Skip to content

19. Disk Quotas

On a multi-user system, a single user or application could accidentally (or maliciously) fill up the entire hard drive, crashing the server. Disk Quotas allow administrators to restrict how much disk space and how many files a specific user or group can consume on a filesystem.

There are two primary ways to measure quota usage:

  • Block Quotas: Limits the total size of the data (e.g., maximum 5 GB).
  • Inode Quotas: Limits the total number of files a user can create (e.g., maximum 10,000 files), regardless of how small the files are.

For both Blocks and Inodes, you define two thresholds:

  • Soft Limit: A warning threshold. A user can temporarily exceed this limit, but a timer (the Grace Period) begins.
  • Hard Limit: The absolute maximum. A user can never exceed this limit. Any attempt to write data past this limit will result in a “Disk quota exceeded” error.
  • Grace Period: The amount of time a user is allowed to remain above the Soft Limit (usually 7 days). If they don’t clean up their files before the grace period expires, the Soft Limit converts into a Hard Limit, preventing further writes until they delete data.

Quotas must be explicitly enabled at the filesystem level.

To enable user and group quotas, you must add the usrquota and grpquota options to the mount entry in /etc/fstab.

# Example /etc/fstab
UUID=a1b2c3d4... /home ext4 defaults,usrquota,grpquota 0 2

After editing /etc/fstab, remount the filesystem for the options to take effect.

Terminal window
sudo mount -o remount /home

Use the quotacheck command to scan the filesystem and build the initial quota database files (aquota.user and aquota.group).

Terminal window
# -c (create), -u (user), -g (group), -m (don't remount read-only)
sudo quotacheck -cugm /home

Finally, activate the quota system.

Terminal window
sudo quotaon -v /home

To define the soft and hard limits for a specific user, use edquota. It opens the quota configuration in your default text editor.

Terminal window
# Edit quotas for the user 'alice'
sudo edquota -u alice

Editor Output:

Disk quotas for user alice (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 5000000 6000000 0 10000 12000

(In this example, Alice has a 5GB soft block limit and a 6GB hard block limit).

To modify the global grace period (default is 7 days):

Terminal window
sudo edquota -t

If you have configured Alice and want to apply the exact same limits to Bob:

Terminal window
sudo edquota -p alice bob

As an administrator, you need tools to view quota consumption across the system.

  • quota: Shows the quota usage for the currently logged-in user.
    Terminal window
    quota -s
  • repquota: Prints a comprehensive summary report of all user quotas on a specific filesystem. Essential for SysAdmins!
    Terminal window
    sudo repquota -a -s

(The -s flag makes the output human-readable, formatting blocks into Megabytes and Gigabytes).