HOWTO install DiskQuotas (Linux v2.4.18 and up)

Per-user hard disk space usage limitiation

Linux DiskQuotas do not only serve the purpose of keeping users from swallowing up too much disk space. It is also a fast way of reporting who is using how much disk space, as the kernel keeps track of it everytime you create, modify or delete a file. Thus, you will need no external scripts to walk down the file tree and collect file sizes.

DiskQuotas are enabled by default in the Linux kernel 2.6.x series. Edit /etc/fstab to enable quotas for the filesystem(s). Add the options usrquota and grpquota to the option list, so that an fstab entry could look like this:

/dev/hdc1 /home xfs defaults,auto,usrquota,grpquota,acl 0 0

xfs is a special case and needs slightly different treatment -- see the XFS section below.

Remount (not XFS)

After you have done so, remount the filesystem(s) to finally enable quota for the filesystem.

mount /home -o remount

Make sure you have the latest quota package installed. Check your Linux CDs, the distributor's FTP or any other compatible source. The vanilla source packages can be retrieved from the linuxquota's file section on Sourceforge. (You are encouraged to install the packages that came with your Linux distro, rather than vanilla.)

Initializing quotas (not XFS)

The next step is to run the quota checker which will scan the disk(s) for their current usage. It will create (or update) aquota.user and in each volume's root. These files should be chmod'ed 0600 (i.e. only read-writable for root) afterwards, if they are not already!

quotacheck -augm

-a tells quotacheck to go through all mounted filesystems on which quotas (user, group, or both) have been enabled. By default, quotacheck will refuse to scan mounted partitions, as files may change while you scan. However, for those who need to stay on-line, the -m bypasses the fact that the fs are mounted read-write. You can not be exact to the byte, as quota is activated relatively late during bootup phase. (XFS does not have this problem.)

-u says to collect per-UID usage, -g to collect per-GID usage. -v stands for verbosity and will print a rotating dash to indicate progress while it scans. Right after, issue the quotaon -a (or quotaon /MOUNTPOINT) command to activate quotas and the tracking of file creation, modification and deletion. Use quotaoff -a before attempting to redo a quotacheck.

Do not forget to add quota activation as a boot service! For SUSE this would be insserv /etc/init.d/boot.quota.

For reporting, you can use the repquota utility. To set quotas, you can use setquota or a more friendly version edquota.


XFS considers quotas as meta-data. They can only be activated at mount time, i.e. activating them while the filesystem is not allowed, and hence, the remount operation (see above) will fail. You will have to unmount the volume, and mount it again. On mount, the quotas will be initialized automatically inside the kernel, which is fast, and you do not need to run quotacheck. There will be no aquota.user or file. Also, because quotas are enabled at mount time, they are always accurate.

If you want to use quotas on an xfs root filesystem, special action needs to be done, since /etc/fstab is usually not available by the time the root filesystem is mounted -- by the time one needs to have decided whether or not to activate quotas.

Using initramfs with fstab

Some distributions might copy /etc/fstab into the initramfs image, thus making the initial mount aware of the usrquota,grpquota options we want for an xfs root filesystem.

Using initramfs without fstab

Other distributions (openSUSE among them) might chose not to include fstab, in which case you need to pass the kernel parameter, as seen in the next subsection.

When not using initramfs

When not using an initramfs image, you will need an additional kernel boot parameter:


Be aware of remounts

openSUSE for example, will attempt to remount any volumes listed in the (real) /etc/fstab. Therefore you must not have usrquota,grpquota in your fstab for the root filesystem, because otherwise the remount could fail.

Operation within Linux (added 2004-04-25)

Just a short note to show you what happens when you exceed your quota limits. If you hit the Soft Limit, the Kernel issues a warning to the current tty. That message is not generated by the application and thus does even show up if you redirect all file descriptors. Only your VT (xterm, putty) loggers may keep it. Exceeding the Soft Limit also is no error -- applications will continue to work until the Hard Limit.

$ dd if=/dev/zero of=test bs=10M count=1
ide0(3,1): write failed, user block limit reached.
dd: writing `test': Disk Quota exceeded
1+0 records in
0+0 records out

Trying to exceed the Hard Limit results in the usual kernel error message, and of course a failure return number, which causes applications to come up with an error, as you can see.

Integration into NFS (Linux/Linux) (added 2004-05-03)

Quota limits work without any further adjustments over NFS and thelike. You will get the "Disk Quota exceeded" message as above, however you will not get a warning message when exceeding the soft limit.

To be able to get the exact quota usage and information for an NFS mount using the quota utility or similar tools, you need to run the rquotad daemon (sometimes just quotad) on the server side. (You will not need it if the error message suffices to you.) Activate it with rcquotad start (might need some patches, see below) and put it into the boot sequence using insserv /etc/init.d/quotad (openSUSE).

Quotas must be set on the server!

Integration into SMB (Linux/Windows) (added 2004-04-25)

Samba version 2.2.7a and above, handles quotas just as expected. Suppose I did set a 10MB hard limit on a user and added a random 1.05 MB file to the filesystem, him being the owner, this would show up as follows in Windows(98) Explorer:

When a soft limit is set, Samba reports the soft limit, or the currently used size, whichever is greater, as the maximum disk capacity. However, you can still continue to fill up the filesystem until your hard limit. (Only as long as Windows applications allow you to write to the device despite there is nothing "free".)

When the user tries to store more on the filesystem than his Hard Limit allows, the following error occurrs on DOS (which is weird) and on Windows:

Y:\>copy test test2

Dieses Gerät existiert im Netzwerk nicht. beim Lesen von Laufwerk Y:
Abbrechen, Fehler?

(Says: "The device does not exist within the network. during read of drive Y:, Cancel/Error?" and "Not enough disk space on the drive.") Nobody uses DOS quite anymore so there should not be too much surprises.


Additional keywords: aquota user group edquota setquota repquota showquota