Introduction
Enforce per-tenant disk limits with the mechanism that matches how your tenants already own files: user quotas when each tenant has a dedicated UID, XFS project quotas when tenants share a UID or span several directory trees. Hard limits block writes with EDQUOT, soft limits start a grace timer, and inode limits stop the tenant who fills the disk with a million 4 KB PHP session files. Everything below assumes the web root lives on its own filesystem (/srv) and that you know which UID writes the files, because a quota is only as good as the ownership model underneath it.
The examples use XFS for the tenant tree and ext4 for /home, which is the split most hosting images ship with. Both filesystems support both mechanisms, but XFS project quotas need no extra tooling, while ext4 project quotas require the project feature and behave slightly differently around inheritance.
Pick the accounting unit first
A quota bucket is keyed to a UID, a GID, or a project ID. Choosing wrong means the limit exists on paper and never fires, or fires against the wrong tenant.
| Mechanism | Bucket key | Setup cost | Use when |
|---|---|---|---|
| User quota | UID | fstab + quota files | Each tenant has its own UID (one PHP-FPM pool per tenant, own SFTP user) |
| Group quota | GID | fstab + quota files | A shared group writes into one tree, e.g. a reseller group |
| Project quota (XFS) | Project ID | /etc/projects + project -s | Tenants share www-data, or one tenant owns several directories |
The ownership question decides it. If ls -ln /srv/www shows every file owned by 33 (www-data) because all pools run under the distro default, user quotas will cap the sum of all tenants as one user. That is a real limit, just not a per-tenant one.
Limits come in pairs. Blocks limit data, inodes limit file count, and each pair has a soft value that starts a grace clock and a hard value that fails immediately. Set the hard limit 10 to 15 percent above the soft one so a tenant hitting the soft limit can still write logs and sessions while the warning email goes out.
User quotas on ext4
Enable the quota feature so tracking is journaled and starts at mount with no quotacheck race. Do it offline; the filesystem must not be mounted.
umount /hometune2fs -O quota -Q usrquota,grpquota /dev/vg_web/lv_homee2fsck -f /dev/vg_web/lv_homee2fsck builds the hidden quota inodes from current usage, which is why existing files show up in repquota afterwards. Then declare the mount options persistently:
/dev/vg_web/lv_home /home ext4 defaults,usrquota,grpquota 0 2Mount and set limits. Blocks are in 1 KB units on ext4 regardless of the filesystem block size, so 40 GiB is 41943040. Newer e2fsprogs accepts suffixes:
mount /homesetquota -u tenant42 40G 45G 400000 450000 /homesetquota -t -u 604800 604800 /homerepquota -s /homeIf your e2fsprogs predates 1.44, drop the suffixes and pass 41943040 47185920 for the block limits.
The legacy path (quotacheck -cugm /home then quotaon -av) still works on filesystems without the quota feature, but it recomputes usage by walking the entire tree and needs to run before users start writing, or the accounting drifts. The feature route avoids both problems.
For ext4 project quotas the sequence is tune2fs -O project -Q prjquota /dev/..., then chattr -p 1000 /srv/www/tenant42 to stamp the ID. It works, but the XFS flow below is less error-prone when you add tenants often.
XFS project quotas
XFS keeps project definitions in two files and stamps a numeric ID onto every inode under a path. The ID, not the path, is what the kernel accounts, so a tenant who renames directories keeps the same bucket.
/dev/vg_web/lv_srv /srv xfs defaults,prjquota 0 2mount /srvecho "42:/srv/www/tenant42" >> /etc/projectsecho "tenant42:42" >> /etc/projidxfs_quota -x -c 'project -s tenant42' /srvxfs_quota -x -c 'limit -p bsoft=40g bhard=45g isoft=400000 ihard=450000 tenant42' /srvxfs_quota -x -c 'timer -p -b 7d -i 7d' /srvproject -s walks the subtree and stamps IDs recursively. On an existing 200 GB tree that takes a while and generates metadata writes, so run it during a window; for new tenants the directory is empty and it returns instantly.
Check the result with xfs_quota -x -c 'report -h' /srv, which prints usage and limits per project. Use quota -p -h tenant42 for a single tenant.
Two ordering rules matter. The directory must exist before project -s. And limits are stored per project ID on that filesystem only, so a tenant with a database on /var/lib/mysql needs the same project ID stamped there and its own limit entry.
project -c sets the ID on a single path without recursion; project -C clears it. Skipping the recursive variant leaves older files unattributed and effectively unquota’d.
Mapping buckets to real tenants
Quota setup fails silently more often at the ownership layer than at the kernel layer. The checks that catch it:
Files written by root are charged to root. A nightly backup script, a wp-cli run over SSH as root, or a cron job that writes into the tenant tree all escape the tenant’s quota. Either run those as the tenant user or accept that the limit covers only traffic-driven writes.
A tenant who can chown can escape a user quota. When a site has shell access and the ability to change file ownership to another existing UID, its usage moves to that UID’s bucket. Project quotas close that hole because the ID lives on the inode and is not writable by the tenant.
All sites under one www-data need project quotas. This is the common case on shared cPanel-style images with mod_php. The alternative, one PHP-FPM pool per tenant with its own UID, is the cleaner long-term fix since it also gives you open_basedir and process isolation, and makes user quotas correct.
Hard links cross project boundaries. A file outside the project hard-linked into the tree is charged to the project that owns the inode, so its size does not count against the tenant. Disable hard links for untrusted tenants with fs.protected_hardlinks=1 (default on modern kernels) and keep realpath-based checks in the panel.
Verification
Prove the limit before you invoice for it. Run as the tenant user so the write is charged correctly:
sudo -u tenant42 dd if=/dev/zero of=/srv/www/tenant42/fill bs=1M count=46000Expect dd: error writing '/srv/www/tenant42/fill': Disk quota exceeded once the hard limit is hit, with the partial file left behind at roughly 45 GB. Delete it immediately.
Inode limits need their own test because block exhaustion masks them. df -i /srv reports inode usage; a tenant with millions of small files can hit ihard while df -h still shows free space.
Monitoring and grace periods
Two numbers decide whether a tenant gets a warning or an outage. Soft limits plus the grace period define the warning window; warnquota reads that state and mails users still over the soft limit.
MESSAGE = Your site has exceeded its disk allowance. Delete files or request an upgrade.\nSUBJECT = Disk quota warning for your hosting accountwarnquota -uwarnquota -pRun it hourly from cron or a systemd timer. Wire the same data into your panel so the client sees usage rather than reading it from an email, and alert yourself at 90 percent of the aggregate filesystem, because per-tenant quotas do not stop the sum of all tenants from filling the volume.
Snapshot the state for trend data:
repquota -as /home > /var/log/quota-home-$(date +%F).txtxfs_quota -x -c 'report -h' /srv > /var/log/quota-srv-$(date +%F).txtContainers on overlay2
Docker’s size storage option requires the data root on XFS mounted with prjquota, and each container’s writable layer becomes a project.
{ "data-root": "/srv/docker", "storage-driver": "overlay2"}docker run --storage-opt size=10G ...This caps the writable layer only. Anything written to a named volume or a bind mount lives on the host filesystem and is not covered, so quota the volume path with an XFS project or a loopback file with its own mount. Also note that the size option is unsupported on ext4 and on overlay2 over anything except XFS with project quota enabled, and Docker reports that as a startup failure rather than a warning.
Troubleshooting
Errors here are mostly configuration errors reported at the wrong layer. The quota syscall returns EDQUOT (errno 122), which applications surface as a generic disk error, so start by confirming the write path and the bucket.
| Error | Cause | Fix |
|---|---|---|
quotaon: Mountpoint (or device) /srv/www not found or has no quota enabled. | Passed a subdirectory, or the mount lacks the quota option | Run quotaon against the mountpoint from findmnt -no TARGET,OPTIONS /srv |
setquota: Cannot open quotafile //aquota.user: No such file or directory | No quota files: filesystem mounted without the option, or legacy setup skipped quotacheck | quotaon -av, or quotacheck -cugm -f /home then quotaon -av |
repquota shows zeros on a filesystem with existing data | Accounting started after the files were written | With the quota feature, unmount and run e2fsck -f; otherwise quotacheck -cugm |
xfs_quota: cannot set limits: No such file or directory | Project name missing from /etc/projid | Add tenant42:42 to /etc/projid before setting limits |
xfs_quota: cannot set limits: Invalid argument | Filesystem not mounted with prjquota | Unmount, add prjquota to fstab, mount again; changing quota options under load fails |
cp: error writing 'x.tar': Disk quota exceeded / PHP Warning: failed to open stream: Disk quota exceeded / MySQL OS error code 122 | Hard limit reached on blocks | xfs_quota -x -c 'quota -p -h tenant42' /srv or repquota -s /home; raise the limit or delete data |
No space left on device while df -h shows free space | Inode hard limit reached | df -i; xfs_quota -x -c 'quota -p -h tenant42' /srv to confirm ihard |
Error response from daemon: --storage-opt is supported only for overlay over xfs with 'pquota' mount option | Docker data root not on XFS with project quota | Move data-root or remount with prjquota |
One recovery case deserves its own note. A tenant already over the hard limit cannot write, but can delete. Raising the hard limit does not clear the state until usage drops below the soft limit and the grace period resets, so a tenant stuck mid-deploy needs space freed, not a bigger number.
What quotas do not do
Quota accounting is cheap on XFS and acceptable on ext4 with journaled quota, but it is not isolation. Memory, CPU, and process count belong to cgroups v2, and a tenant running a fork bomb hits no quota at all.
The limit also does not follow the data. A tenant whose node_modules lives on /srv and whose uploads live on a separate upload volume needs a project ID or user limit on each filesystem, with the panel summing them for display. Same for mail spools and databases.
Finally, quotas are per filesystem and per bucket. Merging two legacy UIDs into one, changing a project ID with chattr, or migrating a tree to a new mount all reset or split accounting. Do the migration, then re-run project -s and re-apply the limits explicitly instead of assuming they carried over.