Where to start First steps track · 15 stages
Linux Labs

Disk quotas

4 min Linux · quota

Limiting space and file counts per user/group — enabling, configuring, reports.

Cheat sheet

5 commands Printable version
  • sudo setquota -u user 5G 6G 0 0 /data soft/hard limits on space
  • sudo edquota -u user interactively, in an editor
  • sudo edquota -t configure the grace period
  • quota -u user a user's quota and usage
  • sudo repquota -s /data a report for the filesystem

Overview

Quotas limit how much space (blocks) and how many files (inodes) a user or group can use on a filesystem. Useful on shared servers, so one user can't fill the disk (see disk-usage).

Limits come in two kinds: soft (can be exceeded for a grace period, with a warning) and hard (a firm ceiling — writes get blocked).

Configuration

bash
sudo apt install quota
# add options to the relevant filesystem in /etc/fstab: usrquota,grpquota
#   /dev/sdb1  /data  ext4  defaults,usrquota,grpquota  0  2
sudo mount -o remount /data
sudo quotacheck -cugm /data       # create the accounting files (aquota.user/group)
sudo quotaon -v /data             # turn quotas on
sudo quotaon -p /data             # check whether they're on

Recipes

2

Limits and reports

bash
# set a user's limits (blocks: soft hard, inodes: soft hard):
sudo setquota -u alice 5G 6G 0 0 /data        # soft=5G hard=6G of space, no inode limit
sudo setquota -u alice 0 0 10000 12000 /data  # a limit on the number of files
sudo edquota -u alice             # interactively, in an editor
sudo edquota -t                   # set the grace period (for soft limits)
sudo edquota -p alice -u bob      # copy alice's quotas to bob

# reports:
quota -u alice                    # a user's quota and usage
sudo repquota -a                  # a report for every filesystem with quotas
sudo repquota -s /data            # human-readable (-s)

xfs quotas

xfs works differently — quotas are turned on with a mount option, not quotacheck:

bash
# /etc/fstab:  /data xfs defaults,uquota,gquota 0 0   (or pquota for project quotas)
sudo xfs_quota -x -c 'report -h' /data
sudo xfs_quota -x -c 'limit bsoft=5g bhard=6g alice' /data

Troubleshooting

4

setquota doesn't work / "not found"

The filesystem is mounted without usrquota/grpquota — check mount | grep -i quota. Or quotacheck/quotaon hasn't been run. On xfs this approach doesn't apply at all — there it's xfs_quota and the uquota/gquota/pquota mount options.

A user hit their limit

quota -u user / repquota show the current usage and the ceiling. Raise it with setquota/edquota, or ask them to clean up. A soft limit has a grace period (edquota -t).

Quotas "reset" after a reboot

quotaon doesn't run itself — make sure the options are in /etc/fstab and the quotaon unit is enabled (on ext filesystems). On xfs, quotas activate through the mount options.

quotacheck wants to unmount the filesystem

It's best run on an idle/read-only filesystem. On a live one, use quotacheck -m (force), but accuracy suffers; ideally run it in single-user mode or with a read-only remount.

See also

  • disk-usage — Where the space and inodes went — df, du, finding large files, gotchas.
  • filesystems — Creating filesystems, labels and UUIDs, fsck checks, ext4/xfs.
  • users-groups — Accounts, groups, membership; useradd/usermod, /etc/passwd and /etc/group.
Loading…