User and Group Disk Quota on UNIX / Linux
Disk space usages can restricted by Disk Quota. which can be implemented on user or group level. This would inform before a user or group completely consume Disk or partition. As we could manage it on individual user level, we could able to restrict user specific number of files or their total size.
In addition to file size, we can also maintain file count as well with Quota. This would help us to maintain inode number in specific disk or partitions, this help because sometime disk is not writeable because all inodes get consumed.
So Quota can help us to maintain Filesystem space usages and inodes consumption through user or group.
So in this post, we will try to learn, How can we enable and configure Quota.To implement disk quotas, use the following steps:
1. installation Quota
2. Enable quotas.
3. Assign quota policies.
1. Installation of Quota
In Ubuntu machines Quota packages can be install through apt-get utlilty.
#apt-get install quota Reading package lists… Done Building dependency tree Reading state information… Done Suggested packages: libnet-ldap-perl rpcbind portmap default-mta mail-transport-agent The following NEW packages will be installed: quota 0 upgraded, 1 newly installed, 0 to remove and 64 not upgraded. Need to get 542 kB of archives. After this operation, 1,438 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/main quota amd64 4.01-3 [542 kB] Fetched 542 kB in 5s (103 kB/s) Preconfiguring packages … Selecting previously unselected package quota. (Reading database … 200842 files and directories currently installed.) Preparing to unpack …/quota_4.01-3_amd64.deb … Unpacking quota (4.01-3) … Processing triggers for ureadahead (0.100.0-16) … ureadahead will be reprofiled on next reboot Processing triggers for man-db (2.6.7.1-1ubuntu1) … Setting up quota (4.01-3) … Processing triggers for ureadahead (0.100.0-16) …#dpkg -l quota Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-====================================-=======================-=======================- ii quota 4.01-3 amd64 disk quota management tools |
In Redhat and centOS, Quota can be iinstall through yum utility
[root@srv103 ~]# yum install quota -t
[root@srv103 ~]# rpm -q quota quota-3.17-20.el6.x86_64 |
2. Enable Quota
For enbaling Quota in Linux, first you have to edit /etc/fstab file with the help of editor and edit entries for that that mount point. Below is example of same. Add usrquota and/or grpquota options on file-system require quota.
/dev/mapper/vg_srv103-lv_root / ext4 defaults 1 1
UUID=27f14130-a0b1-495f-96b8-46f575d3bcad /boot ext4 defaults 1 2 /dev/mapper/vg_srv103-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/vghome/lvhome /home ext3 defaults,usrjquota,grpjquota 0 0 |
In above example, we are working on separate /home partition. you can make it during or after installation. This would provide you easy Quota management on /home for Users and group.
After adding usrquota and grpquota entries for quita required file-system we have to remount that filesystem. for this we have use mount command with their respective options describe below.
[root@srv103 ~]# mount -o remount /home |
Now it is quota enable file-system, we have to build a table for current disk usage per file system This table is also to update operating system’s copy of disk usage,file system’s disk quota files are updated, this will create the quota files (aquota.user and aquota.group) on the file system create .For creating quota enabled run below commands described format.
[root@srv103 ~]# ls -l /home/ #This is no quota file present in /home total 20 drwx—— 2 root root 16384 Dec 22 05:28 lost+found drwx—— 2 u1 u1 4096 Dec 22 06:48 u1 [root@srv103 ~]# quotacheck -cug /home #Command used for creating quota files (aquota.user and aquota.group) on the file system [root@srv103 ~]# ls -l /home total 36 -rw——- 1 root root 7168 Dec 22 06:59 aquota.group -rw——- 1 root root 7168 Dec 22 06:59 aquota.user drwx—— 2 root root 16384 Dec 22 05:28 lost+found drwx—— 2 u1 u1 4096 Dec 22 06:48 u1 [root@srv103 ~]# quotacheck -vug /home #command to generate the table of current disk usage per file system with quotas enabled: quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown. quotacheck: Scanning /dev/mapper/vghome-lvhome [/home] done quotacheck: Checked 4 directories and 7 files |
in above command, various options used. below are described explaination for them.
-u, –user Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked. This is the default action. -g, –group Only group quotas listed in /etc/mtab or on the filesystems specified are to be checked. -c, –create-files Don’t read existing quota files. Just perform a new scan and save it to disk. quotacheck also skips scanning of old quota files when they are not found. -v, –verbose quotacheck reports its operation as it progresses. Normally it operates silently. If the option is specified twice, also the current directory is printed (note that printing can slow down the scan measurably). |
In above commands we can see there is one warning for journaled quota, we can enable journal in our quota with adding below mention options in /etc/fstab file.
[root@srv103 ~]# awk END'{print}’ /etc/fstab /dev/vghome/lvhome /home ext3 defaults,usrjquota=aquota.user,grpjquota=aquota.grp,jqfmt=vfsv0 0 0 |
Now, if we run ” quotacheck -vug /home ” command will not show any error.
[root@srv103 ~]# quotacheck -vug /home quotacheck: Scanning /dev/mapper/vghome-lvhome [/home] done quotacheck: Checked 4 directories and 8 files |
Now we are ready to use quota on users or group. Use ” edquota \<user-name\> “ command to set Quota. Below screen will ope, were you can used to set Quota.
Disk quotas for user u1 (uid 500): Filesystem blocks soft hard inodes soft hard /dev/mapper/vghome-lvhome 16 0 0 4 0 0 |
Let’s see what all columns is name of quota enabled file-system.
Second block shows user currently used blocks. Next two columns used to set user’s soft and hard blocks limit. Inodes columns show currently used inodes by user. Last two columns used to define soft and hard limit of inode for user on that file-system.
Block usage and limits are reported and interpereted as multiples of kibibyte (1024 bytes) blocks by default. Symbols K, M, G, and T can be appended to numeric value to express kibibytes, mebibytes, gibibytes, and tebibytes.
Inode usage and limits are interpreted literally. Symbols k, m, g, and t can be appended to numeric value to express multiples of 10^3, 10^6, 10^9, and 10^12 inodes.
Hard block limit is to defines maximum amount of disk space that user or group can use. If that limit reached, further disk space cannot be used.
Soft limit is same as hard limit as defines maximum amount of disk space that user or group can use. But unlike hard limit Soft limit can be exceeded for a certain amount of time (grace period). Grace periods can define in seconds, minutes, hours, weeks or months.
Quota set for user u1 in through ” edquota \<user-name\> “ command in below format
Disk quotas for user u1 (uid 500): Filesystem blocks soft hard inodes soft hard /dev/mapper/vghome-lvhome 16 100M 200M 4 0 0 |
In Redhat or centOS by default it opens in vi editor, when you save it and check with ” quota \<user-name\> “. it will change M , Megibyte into blocks and show in below format.
Quota grace period can be defined through ” edquota -t “. This will show screen mentioned below.
Leave a Reply