Implement Disk Quotas in RHEL 6 and CentOS 6
Quotas are used to limit a user's or a group of users' ability to consume disk space. This prevents a small group of users from monopolising disk capacity and potentially interfering with other users or the entire system. This feature of Linux allows the system administrator to allocate a maximum amount of disk space a user or group may use. It can be flexible in its adherence to the rules assigned and is applied per filesystem. The default Linux Kernel which comes with Redhat and Fedora Core comes with quota support compiled in. In order to implement quotas you need to check whether the kernel supports them.
Check whether the quota support is built into the kernel
Terminal
[root@server1~] # grep CONFIG_QUOTA /boot/config-2.6.18-1.2798.fc6 CONFIG_QUOTA=y CONFIG_QUOTACTL=y
Those two values should be 'y'. If its not you may need to install the quota rpm package or you may have to recompile your kernel.
Prerequisites
- You should have a seperate unique partition to implement quotas and mount the partition.
- Make necessary changes in /etc/fstab file and remount the partition and check that quotas are on.
- Create files aquota.user and aquota.group in mounted partition folder. [ Note: this may not be required for RHEL5 ] and make sure the owner of those files in root and he should be able to read and write to those files ( chmod 600 aquota.*).
- Run the command quotacheck to check that quotas are implemented.
Create a seperate partitiion
Using your favorite partitiion tool like ( fdisk, parted, gnuparted or any other tool create a partition). Create a directory and mount that partition to that directory.
Terminal
[root@server1~] # mkdir -p /partmount [root@server1~] # mount /dev/sda7 /partmount
Changes to /etc/fstab
In order to impletment quotas on the partition you need to make changes to /etc/fstab so that when you reboot the system, the quotas are still there on the filesystem. This step is required if you intend to make the quotas permenant. Change the last line as shown in the example.
Terminal
[root@server1~] # vim /etc/fstab LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs defaults 0 0 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 LABEL=SWAP-hdb1 swap swap defaults 0 0 /dev/sda7 /partmount ext3 defaults,usrquota,grpquota 0 0
Now we need to remount the partition for the quotas to be implemented.
Terminal
[root@server1~] # mount -o remount /partmount
Creating quota related files
Terminal
[root@server1~] # cd /partmount [root@server1 partmount] # touch aquota.user; touch aquota.group [root@server1 partmount] # chown root:root aquota.*; chmod 600 aquota.*
Check that quotas are working
Terminal
[root@server1~] # quotacheck -vgum /partmount
Implementing Quotas for users and groups
edquota command
To specify disk quotas you need to run either edquota or setquota commands. In order to specify quota for the user henry you will use the command edquota as follows.
Terminal
[root@server1~] # edquota -u henry
You will be presented with the vi editor specifying the soft limit the hard limit and inodes ( the number of files ) soft limit and hard limit.
Soft Limit: This is the maximum amount of space a user can have on that partition. If you have set a grace period, this will act as an alarm, and you will also be required to set a hard limit.
Hard Limit: Hard limits are only neccessary when you are using grace periods. If grace periods are used this will be the absolute limit a user can use.
Grace periods are set by using the command edquota -t /partition
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
Reporting quotas
Reports on quotas allocated to users and groups could be obtained by using the command repquota
Terminal
[root@server1~] # repquota -u /partmount
To obtain individual quota for users jerry and group payroll the commands would be as follows:
Terminal
[root@server1~] # repquota -uv jerry [root@server1~] # repquota -gv payroll
Quota management
Quotas management can be done with the command quotacheck. This command is useful in the sense we can check that the quotas that are allocated are really in the pipeline for execution.
Terminal
[root@server1~] # quotacheck -vgum /partmount