Archive for May, 2012

Left to their own devices, users will gobble up as much disk space as they need to use. Linux allows you to enforce disk quotas for your users so that your disks have enough space for everyone. I’m going to be using Fedora Linux for this, but the process is almost exactly the same for all distributions.

First, you need to make sure you have the quota package installed. It’s probably installed by default, but if not you can install it with: -

yum install quota

Under Debian-based systems this would be: -

sudo apt-get install quota

Next you need to decide which partitions you want to enable quota support on. Most people will naturally want to use “/home” as this is where user directories are but the beauty of quotas are that you can apply then to any partition, not just home. This works especially well if you have very little space on your home partition and some user’s home directories are actually on a different partition with their user accounts symbolically linked to appear under “/home”. But since the process is the same, I’ll assume you’ve got your “/home” directory mounted on a separate disk called “/dev/sdb1″.

Open up “/etc/fstab” which holds all the partitions to be mounted upon boot and append the string “usrquota,grpquota” where indicated. Obviously change your device to be mounted to whichever suits your needs.


/dev/sdb1 /home ext4 defaults 1 2

…should become…


/dev/sdb1 /home ext4 defaults,usrquota,grpquota 1 2

You’ll now have to remount the file-system for this change to take effect. If your home directory is on the same partition as your root (“/”) directory, this will probably necessitate a reboot. If not, you can remount the partition using: -

mount -o remount /home

Now that the selected partition has support for user quotas and has been remounted, you need to create the quota database files. This can be done with: -

quotacheck -cug /home

If you now do “ls -la /home”, you should see two new files, “aquota.user” and “aquota.group”. These are the quota files for that partiton for users and groups respectively and will be created at the root of the mounted partition directory (in this case, under “/home”).

Make sure quotas are turned on with: -

quotaon -av /home

This should give you output similar to this: -


group quota on /home (/dev/sdb1) is on
user quota on /home (/dev/sdb1) is on

Now that you’ve configured quota support for your partition, you need to add policies for users and groups. For this, I’m going to create a new user called “quotauser”.

useradd quotauser

…and set a password for the account.

passwd quotauser

Once the user is created, it’s time to impose a quota limit. So you’ll need to edit the quota policy for the user you’ve just created.

edquota -u quotauser

This will give you output similar to this.

Disk quotas for user quotauser (uid 502):
Filesystem	                blocks	soft	hard	inodes	soft	hard
/dev/sdb1	                32	0	0	8	0	0

This output deserves a little explanation. The “Filesystem” column is obvious, this is the file system on which quotas have been activated for users. The second column “blocks” is how many blocks the user is current using in their home directory. The next two columns are used to set soft and hard block limits for the user on the file system.
The “inodes” column shows how many inodes the user is currently using based on the number of files and directories in the user’s home directory. The last two columns are used to set the soft and hard inode limits for the user on the file system.

We’ll only need to concern ourselves with the first two soft and hard columns as we’re going to base our quota limits on disk space size and not the number of inodes used, although you can if you want to. The hard limit is the absolute maximum amount of disk space that a user or group can use. Once this limit is reached, no further disk space can be used. The soft limit defines the maximum amount of disk space that can be used. However, unlike the hard limit the soft limit can be exceeded for a certain amount of time. That time is known as the grace period and can be expressed in seconds, minutes, hours, days, weeks, or months. If any of the values for any of the columns are set to 0, that limit is not set. We’ll get to setting the grace period for the soft limits in a moment but for now let’s set the limits for our new user.

For example purposes, we’ll set the quota to a warning limit of 500MB (500MB x 1024K = 512000) and a panic limit of 512MB (512MB x 1024K = 524288) on the “/home” file system.

Disk quotas for user quotauser (uid 502):
Filesystem	                blocks	soft	hard	inodes	soft	hard
/dev/sdb1	                32	512000	524288	8	0	0

Save this file using whichever default editor you’re using and verify the new limits with: -

quota quotauser

which should give the new output as something like: -

Disk quotas for user quotauser (uid 502):
Filesystem	                blocks	soft	hard	inodes	soft	hard    grace
/dev/sdb1	                32	512000	524288	8	0	0

Next, we’ll set the grace period for the soft limit.

edquota -t

The “-t” switch will act on all file systems with quotas enabled, unlike the other switches to the edquota command which only affect particular users or groups. If the idea of setting quota limits for each user doesn’t appeal to you, you can set quotas for groups that a large number of users are a member of and they will still be enforced.

edquota -g some_group

A few other useful commands…

To show your own user quota, use “quota”
To show a particular user’s quota, use “quota -u user”
To show all users quota usage, use “repquota -a”

Search The Node
XBox LIVE Gamertag
The Node Downloads
Mini Tweets

Switch to our mobile site