How to Use Ubuntu xfs_quota to Enforce Strict File System Capacity Limits

The Shared Hosting Nightmare

When provisioning an Ubuntu server as a shared environment—perhaps a university shell server where 500 computer science students share a single 10-Terabyte hard drive—administrators face a massive resource allocation problem. The standard Linux filesystem does not care who writes to the disk. If a single student writes a flawed Python script that enters an infinite loop, generating a 10-Terabyte log file, that single student will consume 100% of the physical hard drive. The other 499 students will be completely unable to save their work, and the operating system itself may crash as it runs out of space for critical system logs.

To mathematically prevent this scenario, UNIX engineers deploy File System Quotas. While legacy filesystems like ext4 require complex quota daemons and separate index files (aquota.user), the modern, high-performance XFS filesystem integrates quota management directly into its core architecture. By leveraging the xfs_quota utility, administrators can enforce strict, unbreakable mathematical ceilings on exactly how many Megabytes of data (Block Quotas) or how many individual files (Inode Quotas) a specific user or group is allowed to possess, isolating the blast radius of rogue scripts.

Step 1: Enabling Quotas at the Mount Level

By default, even if you format a drive as XFS, the quota enforcement engine is turned off to save CPU cycles. You must explicitly instruct the Linux kernel to track XFS usage at boot time.

To do this, you must edit the master filesystem table (/etc/fstab).

sudo nano /etc/fstab

Locate the entry for your massive shared drive (e.g., /dev/sdb1 mounted at /mnt/student_data). You must append the quota mount options to the fourth column.

  • uquota (User Quota): Tracks usage per individual user ID.
  • gquota (Group Quota): Tracks usage for an entire group (e.g., the “Robotics_Club” group).
  • pquota (Project Quota): Tracks usage for a specific directory, regardless of who writes to it (highly advanced).

Modify the line to look like this:

/dev/sdb1  /mnt/student_data  xfs  defaults,uquota,gquota  0  0

Save the file. Because these are kernel-level accounting flags, you cannot simply run mount -a. You must either reboot the server or completely unmount and remount the massive drive:

sudo umount /mnt/student_data
sudo mount /mnt/student_data

Step 2: Defining Soft and Hard Limits

The XFS engine is now silently tracking every single byte written to the disk. You must now define the mathematical boundaries. Quotas utilize two distinct limits:

  1. Soft Limit: A warning threshold. If a user crosses this line, they can still write to the disk, but a grace period timer starts ticking (usually 7 days). If they do not delete files before the timer expires, the Soft Limit becomes a Hard Limit, and they are locked out.
  2. Hard Limit: The absolute physical ceiling. If a user attempts to write a single byte past this limit, the kernel violently intercepts the write() system call and throws a Disk quota exceeded error to their terminal.

Step 3: Enforcing Limits via xfs_quota

Unlike ext4, you do not use the standard edquota command for XFS. You must use the dedicated XFS utility in “Expert” mode (-x).

Suppose you want to restrict the user jdoe to a Soft Limit of 40 Gigabytes and a Hard Limit of 50 Gigabytes on the /mnt/student_data drive.

sudo xfs_quota -x -c 'limit bsoft=40G bhard=50G jdoe' /mnt/student_data

Decoding the Logic:

  • -x: Expert mode (required to execute modification commands).
  • -c: Pass the command string inline.
  • bsoft / bhard: The “b” stands for Blocks (the actual physical size of the files on the disk).

The moment you press Enter, the limit is live. If jdoe runs an infinite loop script, it will consume exactly 50GB and then instantly crash with an I/O error, leaving the remaining 9.95 Terabytes of the shared drive perfectly safe.

Step 4: Enforcing Inode Quotas (The Hidden Threat)

Block quotas only solve half the problem. What if a malicious student writes a script that generates 10 million tiny, 1-byte text files?

10 million 1-byte files only consume 10 Megabytes of physical disk space. They will never trigger the 50GB block quota. However, every single file consumes one Inode (the metadata structure that tracks the file). A hard drive has a mathematically limited number of Inodes. If a user exhausts all the Inodes, no one on the system can create a new file, even if the drive has 5 Terabytes of free space.

You must enforce an Inode quota to prevent this specific denial-of-service attack.

sudo xfs_quota -x -c 'limit isoft=80000 ihard=100000 jdoe' /mnt/student_data

This explicitly limits jdoe to creating a maximum of 100,000 individual files, mathematically neutralizing the Inode exhaustion attack.

Step 5: Auditing Global Utilization

To view the current status of the entire filesystem and see exactly who is violating their quotas, use the report verb.

sudo xfs_quota -x -c 'report -h' /mnt/student_data

(The -h flag formats the output in Human-Readable Megabytes/Gigabytes).

The output generates a pristine table showing every user, their current Used space, their Soft and Hard limits, and their Grace period countdown. This allows administrators to instantly identify storage abusers and enforce data lifecycle policies.

Conclusion

Treating a shared Linux filesystem as an ungoverned pool of storage guarantees catastrophic resource exhaustion and multi-tenant denial-of-service scenarios. By deploying the XFS filesystem and mastering the xfs_quota utility, Ubuntu engineers enforce strict mathematical boundaries at the kernel level. The ability to dictate absolute Block ceilings and defensively cap Inode consumption transforms a chaotic shared drive into a highly predictable, mathematically isolated storage environment.

RELATED POSTS

  • How to Join an Ubuntu Linux Machine to a Windows Active Directory Domain using SSSD
  • How to Configure a Chroot Jail for SFTP Users on Ubuntu 22.04
  • How to Install and Configure the Proxmox Backup Server (PBS) Client on Debian
  • How to Configure Network Teaming (Bonding) in Ubuntu Server
  • How to Clear Systemd Journal Logs in Linux using journalctl
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.