Managing Disk Quotas in Linux
Introduction
Disk quotas are used to limit the amount of disk space and the number of files a user or group can use on a filesystem. This tutorial covers how to set up and manage disk quotas in a Linux environment.
Step 1: Install Quota Packages
First, ensure that the necessary quota management packages are installed on your system. You can install them using your package manager. For example, on a Debian-based system, you can use:
On a Red Hat-based system, use:
Step 2: Enable Quotas on the Filesystem
To enable quotas, you need to modify the filesystem table file /etc/fstab
. Open the file with your preferred text editor:
Find the entry for the filesystem you want to enable quotas on, and add usrquota
and grpquota
options. For example:
Save the changes and remount the filesystem:
Step 3: Create Quota Files
Next, create the quota database files on the filesystem root:
This command checks the filesystem and creates the necessary quota files.
Step 4: Enable Quota Enforcement
Enable quota enforcement using the following command:
This command turns on quota enforcement on the specified filesystem.
Step 5: Set Quotas for Users
Now you can set disk quotas for users using the edquota
command:
This will open a file where you can set soft and hard limits for blocks and inodes. For example:
Disk quotas for user username (uid 1001): Filesystem blocks soft hard inodes soft hard /dev/sda1 10000 5000 6000 500 300 400
Save and close the file. The soft limit is the quota limit that can be temporarily exceeded, while the hard limit is the absolute limit that cannot be exceeded.
Step 6: Check Quota Usage
You can check the quota usage for a user with the quota
command:
The output will show the current disk usage and limits for the user:
Disk quotas for user username (uid 1001): Filesystem blocks quota limit grace files quota limit grace /dev/sda1 2000 5000 6000 100 300 400
Step 7: Report Quota Status
The repquota
command can be used to report the quota status for all users on a filesystem:
The output will list the quota usage for each user:
*** Report for user quotas on device /dev/sda1 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- username -- 2000* 5000 6000 2days 100 300 400
Conclusion
By following these steps, you can effectively manage disk quotas on your Linux system. This ensures that users do not exceed their allocated disk space, helping to maintain the overall health and performance of the system.