Enable Quota on RHEL/CentOS

Attention: open in a new window. PDFPrintE-mail

 

 

Quota is used for limiting the disk usage for users or groups.

###To verify that the quota is enabled in the kernel###
#grep CONFIG_QUOTA /boot/config-`uname -r`
CONFIG_QUOTA=y
CONFIG_QUOTA_NETLINK_INTERFACE=y
# CONFIG_QUOTA_DEBUG is not set
CONFIG_QUOTA_TREE=y
CONFIG_QUOTACTL=y
[root@rajat rajat]#
yum -y install quota

Create user :
#useradd rajat
#passwd latar


Edit /etc/fstab :
From :
/dev/sda5 /home ext3 defaults 1 2
To :
/dev/sda5 /home ext3 defaults,usrquota,grpquota 1 2


Remount the disk (make sure it’s not in use) :
#mount -o remount /home

Check if usrquota and grpquota are enabled :
#mount | grep /home

Create quota files :
#quotacheck -cvug /home

This creates /home/aquota.user and /home/aquota.group

Check quota :
#quotacheck -avug

Enable quota for user1 :

#edquota user1
Edit soft and hard limits (1000 = 1 MB) or inode values.

Check the quota for user1 :
#quota user1

Enable quota :
#quotaon -avug

In addition :

Through a cron, run everynight when the filesystem is not used :
#quotaoff -avug && quotacheck -avug && quotaon --avug

Get quota stats :
#repquota -a

The edquota command can also be used to copy quota settings for one user as a template to any number of users in your system You will need to use -p switch of the edquota command to copy quota settings.

Terminal
[root@server1~] # edquota -up user1 user2 user3 user4

setquota command

Alternatively you can use the setquota command to set quotas on users and groups.

Terminal
[root@server1~] # setquota -u user1 0 0 0 0 /partmount

To set a quota of 4GB to user henry we would use the following command

Terminal
[root@server1~] # setquota -u henry 4194304 4194304 0 0  /partmount
Its important to remember to calcuate Megabytes in times 1024 X 1MB and Gigabytes as (1024)2 x 1GB

To set 240Msoft, 256M hard for user jerry

Terminal
[root@server1~] # setquota -u jerry 245760 262144 0 0 /partmount

 Commands                         Description
/sbin/quotaon /fs             This command will enable quotas for the filesystem.
/sbin/quotaoff /fs             This command will disable quotas for the filesystem.
/usr/sbin/edquota username    Edit the quotas for a specific user.
/usr/bin/quota                  Users can review the quotas set for them.
/usr/sbin/repquota          Generates a report of disk usage by users.
/sbin/quotacheck            Checks for quota usage

-----------------------------------------------------------------------------------------------------------------