6.2. Managing Disk Quotas

If quotas are implemented, they need some maintenance — mostly in the form of watching to see if the quotas are exceeded and making sure the quotas are accurate. Of course, if users repeatedly exceeds their quotas or consistently reaches their soft limits, a system administrator has a few choices to make depending on what type of users they are and how much disk space impacts their work. The administrator can either help the user determine how to use less disk space or increase the user's disk quota if needed.

6.2.1. Reporting on Disk Quotas

Creating a disk usage report entails running the repquota utility. For example, the command repquota /home produces this output:

*** Report for user quotas on device /dev/hda3
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      36       0       0              4     0     0
tfox      --     540       0       0            125     0     0
testuser  --  440400  500000  550000          37418     0     0

To view the disk usage report for all quota-enabled file systems, use the command:

repquota -a

While the report is easy to read, a few points should be explained. The -- displayed after each user is a quick way to determine whether the block or inode limits have been exceeded. If either soft limit is exceeded, a + appears in place of the corresponding -; the first - represents the block limit, and the second represents the inode limit.

The grace columns are normally blank. If a soft limit has been exceeded, the column contains a time specification equal to the amount of time remaining on the grace period. If the grace period has expired, none appears in its place.

6.2.2. Keeping Quotas Accurate

Whenever a file system is not unmounted cleanly (due to a system crash, for example), it is necessary to run quotacheck. However, quotacheck can be run on a regular basis, even if the system has not crashed. Running the following command periodically keeps the quotas more accurate (the options used have been described in Section 6.1.1 Enabling Quotas):

quotacheck -avug

The easiest way to run it periodically is to use cron. As root, either use the crontab -e command to schedule a periodic quotacheck or place a script that runs quotacheck in any one of the following directories (using whichever interval best matches your needs):

The most accurate quota statistics can be obtained when the file system(s) analyzed are not in active use. Thus, the cron task should be schedule during a time where the file system(s) are used the least. If this time is various for different file systems with quotas, run quotacheck for each file system at different times with multiple cron tasks.

Refer to Chapter 37 Automated Tasks for more information about configuring cron.

6.2.3. Enabling and Disabling

It is possible to disable quotas without setting them to be 0. To turn all user and group quotas off, use the following command:

quotaoff -vaug

If neither the -u or -g options are specified, only the user quotas are disabled. If only -g is specified, only group quotas are disabled.

To enable quotas again, use the quotaon command with the same options.

For example, to enable user and group quotas for all file systems:

quotaon -vaug

To enable quotas for a specific file system, such as /home:

quotaon -vug /home

If neither the -u or -g options are specified, only the user quotas are enabled. If only -g is specified, only group quotas are enabled.