RHCSA: Setting File System Quotas
March 19, 2012 Leave a comment
Setting file system quotas enables a system administrator to govern how much space users and groups consume on certain volumes or partitions. As an example, the admin might set a quota on /home to limit the size of each user’s home directory.
Preparation:
Check that the quota package is installed. If it’s not, install with the command yum install quota.
# rpm -qa | grep quota quota-3.17-10.el6.i686
Quotas are turned on for specific partitions or mounts. This is accomplished by modifying the mount entry in /etc/fstab and adding one or more quota options. Valid quota options are usrquota and grpquota.
/dev/mapper/data /company/data ext4 defaults,usrquota,grpquota 1 2
Remount the partition and verify the change was applied.
# mount -o remount /company/data # mount | grep data /dev/mapper/data on /company/data type ext4 (rw,usrquota,grpquota)
Setting Quotas:
The first step is to run quotacheck. On the volume where quotas are being set quotacheck will create the files aquota.users and aquota.groups. Run it with the -u option to force the creation of aquota.users and -g to force the creation of aquota.groups.
Do not run this command on a volume that is being actively used, as it could cause corruption. For this reason, quotacheck will by default attempt to remount the volume as read only. To avoid problems, user the fuser command to make sure users are not accessing the volume, then run quotacheck with the -m option.
# fuser /company/data # quotacheck -mug /company/data # ls -l /company/data total 24 -rw-------. 1 root root 6144 Mar 18 21:30 aquota.group -rw-------. 1 root root 6144 Mar 18 21:30 aquota.user drwx------. 2 root root 16384 Mar 18 13:57 lost+found
Now run edquota for a user. This will put you in the vi editor with a text file. Modify the file, setting the hard limit and the soft limit. If the user exceeds the soft limit, they will receive a warning and a grace period to bring their usage back down below the soft limit. The hard limit is the absolute maximum number of blocks the user is allowed.
Notice a hard and soft limit can also be set for inodes (file handles). Use edquota with the -g option to set group limits.
# edquota -u user01 Disk quotas for user user01 (uid 500): Filesystem blocks soft hard inodes soft hard /dev/mapper/data 0 8000000 9765625 0 0 0
For the soft limit to work a grace period is required. Use edquota -t to edit the grace period for each partition.
# edquota -t Grace period before enforcing soft limits for users: Time units may be: days, hours, minutes, or seconds Filesystem Block grace period Inode grace period /dev/mapper/data 7days 7days
And finally, turn on quotas using the quotaon command.
# quotaon -v /company/data /dev/mapper/data [/company/data]: group quotas turned on /dev/mapper/data [/company/data]: user quotas turned on
To view quota usage, use the repquota command:
# repquota -u /company/data
*** Report for user quotas on device /dev/mapper/data
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
user01 -- 500000 8000000 9765625 1 0 0