Using Disk Quotas

If you want to limit the amount of disk storage any user can consume. Most sites have a few disk hogs around, who just love to fill the disk with their MP3 collections and downloaded sitcoms, use the Linux Disk Quota package. This contains several components, including quota, edquota, quotacheck, and repquota.

First, edit /etc/fstab and select the partitions to enable quotas. Your choices are usrquota, for individual users, or grpquota, for putting quotas on groups. It’s okay to have both:

/dev/hda6 / ext3 defaults 0 1
/dev/hda7 /home ext3 defaults,usrquota,grpquota 0 2

Now remount the filesystem:

# mount -o remount /home

Quota’s init script will run quotacheck, which will examine the installation, create a database of disk usage, and create quota files.

Next, assign a quota to a user. This opens a configuration file in your default editor:

# edquota -u vhenson
Disk quotas for user vhenson (uid 1550):
Filesystem blocks soft hard inodes soft hard
/dev/hda7 550466 0 0 47466 0 0

Soft limits allow a grace period, with warnings to the user. Hard limits cut them off immediately. To set limits, simply edit the file:

# edquota -u vhenson
Disk quotas for user vhenson (uid 1550):
Filesystem blocks soft hard inodes soft hard
/dev/hda7 550466 650000 700000 47466 0 0

Blocks are always 1024 bytes, so 650,000 blocks is about 665 megabytes.

Save and close the file, and verify that the quota is in effect:

# quota vhenson
Disk quotas for user vhenson (uid 1550): 650000 700000

To assign a quota to a group use:

# edquota -g engineers

Note that if a single greedy user in a group uses up the group quota, it’s too bad for the rest of the group—it’s all gone.

This invokes the default editor, for setting the grace period for soft limits on the entire filesystem:

# edquota -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/hda3 7days 7days

You can use one “prototype” user as the model for new users:

# edquota -p vhenson dnorth

or for a whole bale of users:

# edquota -p vhenson `awk -F: ‘$3 > 999 {print $1}’ /etc/passwd`

Or you can list several at once:

# edquota -p vhenson dnorth jvesperman sanvin

You’ll doubtless want to keep an eye on things. This repquota command gives a system-wide snapshot of current usage:

# repquota -a

For a specific filesystem, use:

# repquota /home