Tech Tip: Use disk quotas for space restrictions

Disk quotas are a handy way of enforcing the amount of space a user or group can use on a file system. This is especially valuable in a hosting situation where you want users to use only a certain amount of disk space.

To enable quotas, add the quota option in fstab. For example:

/dev/hde1 /home xfs defaults,quota 1 2

This snippet from /etc/fstab enables quota support on /dev/hde1, which is mounted as the /home directory. To modify the quota for a user, use the edquota tool:

# edquota -u joe

This command edits the quota for user joe on any quota-enabled file system. It fires up vi, or your default editor, and gives you a temporary file to edit that looks like the following:

Disk quotas for user joe (uid 502)
  File system    blocks   soft  hard  inodes  soft  hard
  /dev/hde1           0      0     0       0     0     0

The file shows the default quotas, which are null. Here you determine the soft and hard limits for blocks and inodes. Each block represents 1 KB, so if you set a soft limit of 1500, it represents 1.5 MB. If a user exceeds 1.5 MB of usage on that file system, he or she will be warned.

If you set the hard limit to 3000 (or 3 MB), the user is prevented from writing any more files or directories to that file system unless existing files are first removed to make room. By specifying inodes, you can control the number of files and directories the user is allowed to have on the file system.

To turn quotas on, use the quotaon tool. This activates quota checking for the specified quota-enabled file systems. To disable quotas, use quotaoff. Both commands take the file system name as an argument.

Editor's Picks

Free Newsletters, In your Inbox