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:
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:
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 thefallocate command:
Step 2: Adjust User Quotas
Use theedquota command to adjust quotas for the user Aaron:
Step 3: Testing Quota Enforcement
Create an additional 60-megabyte file to increase Aaron’s disk usage: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:Adjusting Grace Periods
You can modify the grace periods (the time before soft limits are enforced) using theedquota 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 theedquota command. To verify group quotas, include the group option with the quota command.