Skip to main content
In this guide, you’ll learn how to set up user and group disk quotas for file systems in Linux. Disk quotas prevent any user or group from monopolizing storage resources, ensuring fair distribution among all system users. For instance, on a 100-terabyte server, instead of one user consuming 80 terabytes and leaving only 20 terabytes for 99 users, you can enforce quotas—such as allowing each user 1 terabyte of storage.
Enforcing disk quotas helps maintain balanced resource usage on shared storage systems, preventing individual users or groups from overwhelming the system capacity.

Prerequisites

Before proceeding, ensure the necessary quota management tools are available. On many distributions like CentOS, these tools come preinstalled. If not, install them using DNF:

Enabling Disk Quotas on a Filesystem

Updating /etc/fstab

To begin, decide which file system will have quotas enabled. For example, to enforce quotas on the backup partition, open the /etc/fstab file with your preferred text editor (e.g., Vim) and modify the corresponding line to include user and group quota options. If the original entry is:
Update it to:
Here, usrquota activates user quotas and grqquota activates group quotas.
Before modifying /etc/fstab, ensure you have a backup of the file. A misconfiguration could render your system unbootable.

Applying Changes

After editing /etc/fstab, save the file and reboot the machine to apply the changes:

Configuring Quotas on Different Filesystems

XFS Filesystem

On an XFS filesystem, quota monitoring is managed internally. Once the quota options are enabled in /etc/fstab, the system will automatically track usage and enforce limits without additional configuration.

ext4 Filesystem

For ext4 filesystems, quotas are not tracked internally. To set up quota tracking on a partition (e.g., /dev/vdb2 mounted at /mnt), create the necessary quota files (aquota.user and aquota.group) by running:
Note: Run the quotacheck command only once per filesystem to avoid redundancy.

Creating a Test Environment on an XFS Filesystem

To demonstrate quota management, we will use the XFS filesystem mounted at /mybackups.

Step 1: Set Up a User Directory

Create a directory for a user named Aaron, change its ownership, and generate a 100-megabyte file using the fallocate command:

Step 2: Adjust User Quotas

Use the edquota command to adjust quotas for the user Aaron:
When the editor launches, you will see current block usage (where one block is typically one kilobyte). For example, 102,400 blocks correspond to 100 megabytes. You can easily set soft and hard limits using the suffixes “M” (megabytes), “G” (gigabytes), or “T” (terabytes). In this scenario, you might set a soft limit of 150M and a hard limit of 200M:

Step 3: Testing Quota Enforcement

Create an additional 60-megabyte file to increase Aaron’s disk usage:
At this point, Aaron’s total disk usage is 160 megabytes—exceeding the soft limit of 150M but still below the hard limit of 200M. The system marks the soft limit breach with an asterisk and initiates a grace period (typically six days), during which Aaron can reduce disk usage below the soft limit:
If storage usage is not reduced during the grace period, the system will enforce the soft limit strictly.

Step 4: Exceeding the Hard Limit

Attempting to create a file that pushes usage beyond the hard limit will result in an error. For example, creating a 40-megabyte file would exceed the 200-megabyte hard limit:

Managing Inode Quotas

Disk quotas can also limit the number of files and directories via inode quotas. Each file or directory consumes one inode. For example, the quota editor might display:
Aaron is using 4 inodes with a hard limit of 5. Creating another file or directory would exceed the inode limit, blocking further file creations.

Adjusting Grace Periods

You can modify the grace periods (the time before soft limits are enforced) using the edquota command with the corresponding edit period option. This allows you to set separate grace periods for blocks (storage) and inodes (file count).

Managing Group Quotas

Managing group quotas follows a process nearly identical to that for user quotas. The primary difference is using the group flag (e.g., -g) with the edquota command. To verify group quotas, include the group option with the quota command.

Conclusion

By following these steps, you can efficiently set up and manage disk quotas for both users and groups on Linux systems. This ensures balanced resource utilization and prevents excessive disk usage by any single user or group. Now, it’s time to get some hands-on lab practice and deepen your understanding of disk quota management!

Watch Video

Practice Lab