File system quota

If you want to make sure your users do not get too greedy with the filesystem space, you may want to set up a disk quota for the users. This will allow the kernel to enforce a maximum disk usage for each user. There exists both a soft and a hard limit on the quota. When the soft limit is exceeded, the user wil start getting daily mails concerning their disk usage (if the system is configured for this behavior). When trying to exceed the hard limit, the filesystem will return a disk-full error, and further writing will be impossible. There is also a grace period during which the user is still allowed to go over his soft-limit.

Kernel configuration

The first thing to check is that your kernel is compiled with quota support. This is under File systemsQuota support. The option is called CONFIG_QUOTA if you need to grep for it in the kernel configuration. Aparently quota is currently supported for ext2, ext3 annnnd reiserfs filesystems. I run reiserfs, so I should be good to go.

I also select the Quota format v2 support (QFMT_V2), although I don't think other parts of the system uses 32-bit UIDs.

Quota tools

Now, install the needed tools to maintain and check the filesystem quotas. On Debian systems the packages are quota and quotatool, so let us install these:

[root@server root]# apt-get install quota{,tool}

These packages should install appropriate init-scripts to check the disk quotas on system boot. During the configuration, the system will also ask whether daily emails should be sent to users that are over their quota.

Modify /etc/fstab

In order to enable the quotas, an additional parameter should be added to /etc/fstab for each filesystem where quota is desired. For user quotas the option is usrquota, whereas group quotas are enabled with grpquota. Both can be enabled, if desired.

I want to run user quota on the root filesystem (which is running reiserfs), so I add the usrquota-option:

/dev/ida/c0d0p1 /   reiserfs     defaults,usrquota  0  1

Note that the filesystem (device) looks a bit strange. This machine has a hardware raid controller with a somewhat strange device name (/dev/ida/c0d0p1). If you see something like /dev/hdaX or /dev/sdaX this is perfectly normal.

Initial quotacheck

In order to use the quota system, the filesystem quotas must be checked and saved in a file in the root of the filesystem for which quota should be enabled. Since I do not want to reboot the machine now, and the root filesystem cannot easily be remounted read-only, I run the quotacheck with the -m option. The safe way to do this would be to reboot the machine, which should then run the quotachek on startup.

[root@server /]# quotacheck -vm /
quotacheck: Scanning /dev/ida/c0d0p1 [/] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Old group file not found. Usage will not be substracted.
quotacheck: Checked 8728 directories and 122851 files
quotacheck: Old file not found.

When quotacheck has finished running, it will have created the needed quota file in the root of the filesystem. For user quotas (in version 2 format) the file will be called aquota.user.

We can now turn the quota system on for the first time:

[root@server /]# quotaon /

Setting users filesystem quotas

In order to set the quotas for a particular user on the system, you can use the edquota-program. For this example I will be setting the quota for the user spiff:

[root@server /]# edquota -u spiff

This opens up the default editor (set in the $EDITOR environment variable, or defaulting to vi), and displays the current quotas for the user. In this example we get the following:

Disk quotas for user spiff (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/ida/c0d0p1              721129          0          0        831        0        0

We see that the user spiff currently uses 721129 blocks of 1kB (in other words 704MB) and 831 inodes (files/directories). The soft and hard quotas for both blocks and inodes are set to 0, which means unlimited.

We now set the block quotas to 2097152 (soft) and 10485760 (hard). This gives spiff a soft quota of 2GB and a hard quota of 10GB (remember the values are 1kB blocks). We do not set the quotas for the inode count. The new quotas look like this:

Disk quotas for user spiff (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/ida/c0d0p1              721129    2097152   10485760        831        0        0

Save the file and exit the editor, and the new quotas are set.

If you are using group quotas, these are edited with edquota -g group.

Quota overview with repquota

To get a quick report of the quota stats, repquota can be used:

[root@server /]# repquota -ast
*** Report for user quotas on device /dev/ida/c0d0p1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
root      --   2311M       0       0           127k     0     0
daemon    --       1       0       0              1     0     0
bin       --       1       0       0              9     0     0
man       --    1661       0       0             25     0     0
mail      --      25       0       0             10     0     0
spiff     --    705M   2048M  10240M            831     0     0

The above report shows the current quota usage (some lines have been deleted to avoid cluttering). We can see that the user spiff has a soft quota of 2GB and a hard quota fo 10GB. There are no quotas on the inode count (number of files/directories). The user spiff currently uses 705MB and has 831 files/directories on the filesystem.

Note that the information printed by repquota is read from the quota system, which means it is very fast to get this information (compared to scanning the entire filesystem with something like du. Even if no quotas are set or enforced, setting up quota on a filesystem can help give an easy overview of which users are cluttering up the filesystem (and it works if their files are in other places than their home-dir as well, such as in /tmp.

Last updated: 2007.01.21