Disk Quotas: Soft Limits, Hard Limits, and the Grace Period
- Explain what a disk quota caps — per user or group, per filesystem — and why it contains one account's mistake
- Distinguish block (space) limits from inode (file-count) limits and read both
- Explain soft vs hard limits and how an expired grace period turns the soft limit into a hard one
- Enable quotas on ext4 with the mount option, quotacheck and quotaon, and set and read limits with setquota and repquota
- Explain why XFS differs: accounting at mount time, no aquota files, xfs_quota for limits and reports
Why quotas exist: one account, one blast radius
Explain what a quota caps and why a shared filesystem needs one
Picture a shared filesystem —
/homeon a teaching server,/srv/sharefor a team, a volume several services write logs into. Nothing stops one account from filling it. A runaway script, a user who copies a video library into their home directory, a service that logs every request at debug level: when the filesystem hits 100%, every writer on it starts failing, not just the one that caused it. Mail stops delivering, editors can't save, databases refuse transactions. One account's mistake becomes everyone's outage.A disk quota caps consumption per user or per group, per filesystem. It does not make the disk bigger and it does not clean anything up. What it does is shrink the blast radius: the account that goes over its limit is the account whose writes start failing, and everyone else keeps working. That is the whole job, and it is why quotas show up on every Linux certification that touches storage.
Check yourself
A shared /srv/share is at 100% because one user filled it. Without quotas, who is affected?
Two axes: blocks and inodes
Tell space limits from file-count limits and read both
A quota caps two things independently. Blocks are space: how many kilobytes the user's files occupy on that filesystem. Inodes are file count: every file, directory and symlink uses one inode no matter how small it is. A user can be well inside their space limit and still be stopped by their inode limit — a build that writes two million tiny files, a mail spool with one file per message.
This is the same two-axis idea as
df -hversusdf -i: a filesystem can run out of space or out of inodes, and either one stops new files. Quotas apply that split per user.setquotaandrepquotaalways show the two columns side by side, so train your eye to read both before you conclude someone is fine.df -i /Filesystem Inodes IUsed IFree IUse% Mounted on overlay 3907584 71234 3836350 2% /
- -i
- report inodes (file count) instead of blocks (space)
The inode view of a filesystem: IUsed and IFree are file counts, not bytes. The same axis a quota's file limit caps per user. Read it alongside df -hand you have both dimensions a quota enforces.Check yourself
A user has 10 MiB used against a 100 MiB block limit, and 50,000 files against a 50,000 inode limit. Can they create a new empty file?
Soft, hard, and the grace period between them
Explain how a soft limit becomes a hard one when the grace period expires
Each axis has two limits. The hard limit is a wall: a write that would cross it fails immediately with
Disk quota exceeded. The soft limit is lower, and it can be crossed — for a grace period set per filesystem. While the user is over the soft limit and the timer is running, their writes still succeed; they are being warned, not stopped.When the grace period expires, the soft limit is enforced as a hard limit (that is exactly how
edquota(8)puts it). The user now cannot write anything more until they get back under the soft limit, even though they are still below the hard limit. The design gives people room for a burst — a big download they'll clean up tomorrow — without letting a temporary burst become permanent. Set the soft limit where you want people to live, the hard limit where a burst must stop, and the grace period to how long a burst is allowed to last.Check yourself
Soft limit 100 MiB, hard limit 150 MiB, grace 7 days. A user sits at 120 MiB for 8 days, then tries to save a 1 MiB file. What happens?
Turning quotas on (ext4): three steps, not one
Enable quota accounting on ext4 with the mount option, quotacheck and quotaon
On ext4 (and ext3), enabling quotas is three separate steps, and stopping after the first one is the classic mistake. One: add the mount option —
usrquotafor per-user,grpquotafor per-group — to the filesystem's/etc/fstabline and remount. That only declares intent. Two: runquotacheckto scan the filesystem and build the accounting filesaquota.user/aquota.groupat the filesystem's root. Three: runquotaonto start enforcing. Until step three, no limit is enforced no matter what the fstab line says.Example — not runnable on your lab box
sudo mount -o remount,usrquota,grpquota /srv/share- -o remount,usrquota,grpquota
- remount the already-mounted filesystem with user and group quota support
Step one, applied live: remount with the quota options (and put the same options in fstab so they survive a reboot). Nothing is counted or enforced yet — this only allows it. Example — not runnable on your lab box
sudo quotacheck -cugm /srv/share- -c
- create new quota files rather than reading existing ones
- -u
- user quotas
- -g
- group quotas
- -m
- don't try to remount read-only while scanning
Step two: scan every file on the filesystem and write the usage it finds into newly created aquota.user and aquota.group files. quotacheck(8) warns against running it on a busy filesystem with quotas already on; -m skips the read-only remount it would otherwise attempt. Example — not runnable on your lab box
sudo quotaon -v /srv/share/dev/loop0 [/srv/share]: group quotas turned on /dev/loop0 [/srv/share]: user quotas turned on
- -v
- say which quotas were turned on for which device
Step three: turn enforcement on. From this moment limits are checked on every write. quotaoffis the mirror image;quotaon -pprints whether quotas are on without changing anything.Check yourself
An admin adds usrquota to /srv/share's fstab line, remounts, sets a limit with setquota, and the user still writes past it. What was skipped?
Setting and reading limits: setquota, edquota, repquota
Set per-user limits and grace periods, and read the report
setquotasets limits non-interactively, which makes it the tool for scripts and for exams. The argument order is fixed and worth memorising: name, block-soft, block-hard, inode-soft, inode-hard, filesystem. A0means no limit on that value.edquotadoes the same job by opening the limits in your editor — handy by hand, awkward to script.Example — not runnable on your lab box
sudo setquota -u alice 102400 153600 0 0 /srv/share- -u alice
- set a user quota (use -g for a group)
Give alice a 100 MiB soft and 150 MiB hard space limit (1 KiB blocks), with no file-count limit, on /srv/share only. Limits are per filesystem; alice is unlimited everywhere else. Example — not runnable on your lab box
sudo setquota -t 259200 86400 /srv/share- -t
- set grace times: block-grace inode-grace, in seconds
Set the filesystem's grace periods in seconds: 3 days for blocks, 1 day for inodes. Grace periods belong to the filesystem, not to a user — every user on /srv/share gets the same timer. Example — not runnable on your lab box
sudo repquota -s /srv/share*** Report for user quotas on device /dev/loop0 Block grace time: 72:00; Inode grace time: 24:00 Space limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20K 0K 0K 2 0 0 alice +- 118M 100M 150M 2days 41 0 0 bob -- 12M 0K 0K 17 0 0- -s
- human-readable sizes and times instead of raw 1 KiB block counts
The report. One line per user with usage, soft, hard and grace for blocks, then the same for files. The two-character column after the name is the one to scan: +in the first position means over the space soft limit,+in the second means over the file soft limit,-means fine.Check yourself
repquota shows
carol -+ 40M 100M 150M 5000 4000 6000 none. What is carol's situation?XFS is a different animal
Know why the ext4 recipe fails on XFS and what replaces it
Carry the ext4 recipe onto an XFS filesystem and it breaks in two places. First, accounting must be on at mount time.
quotaon(8)states it plainly: XFS requires quota accounting to be turned on when the filesystem is mounted; enforcement can be toggled later, accounting cannot be started after the fact. So the mount option (uquota/usrquota,gquota/grpquota,pquota/prjquota) has to be present when XFS mounts — and for an XFS root filesystem that means the kernel command line, because root is mounted before fstab is read.Second, there are no aquota files. XFS keeps quota information internally, not in user-visible files, so
quotacheckhas no role at all — running it is a sign you're following the wrong recipe. Limits and reports go throughxfs_quota, whose-x(expert) mode carries the commands that change things. XFS also offers project quotas, which cap a directory tree regardless of who owns the files inside it — useful when the thing that fills a disk is an application directory, not a person.Example — not runnable on your lab box
sudo xfs_quota -x -c 'limit bsoft=100m bhard=150m alice' /data- -x
- expert mode — required for commands that change limits
- -c '…'
- run one xfs_quota command non-interactively
The XFS equivalent of setquota: soft and hard space limits for alice on /data, with human units allowed. isoft/ihard set file limits the same way. Example — not runnable on your lab box
sudo xfs_quota -x -c 'report -h' /dataUser quota on /data (/dev/vdb1) Blocks User ID Used Soft Hard Warn/Grace ---------- --------------------------------- root 0 0 0 00 [------] alice 118.0M 100M 150M 00 [2 days]- report -h
- report usage and limits with human-readable units
The XFS report: per-user usage against soft and hard limits, with human-readable sizes. It answers the same question repquota answers on ext4. Check yourself
/data is XFS. An admin adds usrquota to fstab, runs
mount -o remount /data, thenquotacheck -cu /data. Will user quotas work?Now do it — read a box's quota state
Check whether a filesystem is quota-capable and which axis is closer to running out
Before you set a single limit, the first minute of any quota task is reading what's there: which filesystem, which type, which mount options, how close each axis already is. These reads run on any box, including one with no quotas at all — on the lab image they mostly report nothing is configured yet, and recognising that state is the skill. Run each one and say out loud what it tells you.
findmnt -no TARGET,FSTYPE,OPTIONS /- -n
- no header line
- -o TARGET,FSTYPE,OPTIONS
- print only the mount point, filesystem type and mount options
The filesystem type decides the recipe (ext4 three-step, or XFS mount-time + xfs_quota), and the options show whether usrquota/grpquota are active right now. No quota option here means no quota accounting on this mount. grep -E 'usrquota|grpquota|uquota|gquota|prjquota' /etc/fstab || echo 'no quota options in /etc/fstab'- -E
- extended regex, so the | alternatives work
What will be true after the next reboot. A quota option live in findmnt but missing from fstab is a quota that silently disappears on reboot. df -h / && df -i /- -h
- human-readable space
- -i
- inodes (file count)
Both axes at once: space and file count. Whichever percentage is higher is the one a quota on this filesystem would bite first. command -v setquota repquota quotacheck quotaon xfs_quota || echo 'quota tools are not installed on this image'- command -v
- print the path of each command that exists, nothing for those that don't
Which toolset this box actually has. The quota tools ship on the RHEL-family lab image; on an image without them, the answer here is the honest first line of your notes.
- A quota caps one user's or group's consumption on one filesystem, so a runaway account fails its own writes instead of everyone's.
- Blocks (space, in 1 KiB units) and inodes (file count) are separate ceilings — read both columns before deciding which limit bit.
- The soft limit can be crossed for the filesystem's grace period; once grace expires it is enforced as a hard limit. The hard limit is always a wall.
- On ext4, enabling quotas is three steps: mount option, quotacheck (builds aquota.user/group), quotaon. The fstab option alone enforces nothing.
- On XFS, accounting must be on at mount time, there are no aquota files and no quotacheck, and xfs_quota -x handles limits and reports.
