User Group Quota

 

This turotial is about turning journaled quota in redhat or centOs linux

To turn on quota

root@nfsserver ~]# yum list quota

If it says avaliable instead of installed then

 

[root@nfsserver ~]# yum install quota

After installation you can edit fstab file

 

 

[root@nfsserver ~]# vi /etc/fstab

/dev/mapper/sysvg-homelv /home ext4 defaults,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 1 2

 

 

 

[root@nfsserver ~]# mount -o remount /home

or

[root@nfsserver ~]# reboot

 

 

[root@nfsserver ~]# cat /etc/mtab
/dev/mapper/sysvg-homelv /home ext4   rw,usrjquoota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 0

 

 

 

[root@nfsserver ~]# cd /home
[root@nfsserver home]# ls -l
total 28
drwx------. 4 kallu    kallu     4096 Dec 22 15:26 kallu
drwx------. 2 root     root     16384 Oct 11 16:37 lost+found
drwx------. 4 mama     mama      4096 Dec 22 14:45 mama
drwx------. 5 velocity velocity  4096 Dec 19 19:40 velocity

 

 

create database

c=create

u=user

g=group

quotacheck= scan a filesystem for disk usage, create , check and repair quota files.

[root@nfsserver home]# quotacheck -cug /home


[root@nfsserver home]# ls -l
total 44

-rw-------. 1 root     root      7168 Dec 22 15:38 aquota.group
-rw-------. 1 root     root      7168 Dec 22 15:38 aquota.user
drwx------. 4 kallu    kallu     4096 Dec 22 15:26 kallu
drwx------. 2 root     root      16384 Oct 11 16:37 lost+found
drwx------. 4 mama     mama      4096 Dec 22 14:45 mama
drwx------. 5 velocity velocity  4096 Dec 19 19:40 velocity

 

quotaon=turn filesystem quotas on

[root@nfsserver home]# quotaon -av

 

here i added 200  kb  soft limit and 400 kb hard limit

if the user crosses 200 kb then it should give warning

and user would not be able to write more than 400 kb

  • Blocks: The amount of space in 1K blocks the user is currently using.
  • Inodes: The number of files the user is currently using.
  • Soft Limit: The maximum blocks/inodes a quota user may have on a partition. The role of a soft limit changes if grace periods are used. When this occurs, the user is only warned that their soft limit has been exceeded. When the grace period expires, the user is barred from using additional disk space or files. When set to zero, limits are disabled.
  • Hard Limit: The maximum blocks/inodes a quota user may have on a partition when a grace period is set. Users may exceed a soft limit, but they can never exceed their hard limit.

 

 

[root@nfsserver home]# edquota -u kallu
Disk quotas for user kallu (uid 501):
  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/mapp/sysvg-homelv        40           200       400      12          0         0
[root@nfsserver home]# quota kallu
Disk quotas for user kallu (uid 501):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/mapper/sysvg-homelv
                    40    200     400   6days      12       0       0

 

[root@nfsserver home]# repquota -a
*** Report for user quotas on device /dev/mapper/sysvg-homelv
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
velocity -- 44 0 0 11 0 0
kallu +- 40 200 400 6days 12 0 0
mama -- 32 0 0 8 0 0

 

now to check if it works or not

 

[root@nfsserver home]# su - kallu

[kallu@nfsserver ~]$ whoami
kallu

[kallu@nfsserver ~]$ pwd
/home/kallu
[kallu@nfsserver ~]$ ls -l

 

our soft limit is 100kb,

40k is already been used with hidden files ,

so we have 160 kb  left for soft limit and 260 kb for hard limit

[root@nfsserver kallu]# du -ch --max-depth 1 /home/kallu
12K     /home/kallu/.mozilla
4.0K    /home/kallu/.gnome2
40K     /home/kallu
40K     total

system wont warn you until you dont reach soft limit , but if you cross soft limit it will warn you

 

lets create a file called test of size 161  and see if it warns us

[kallu@nfsserver ~]$ dd if=/dev/zero of=/home/kallu/test bs=1024 count=161
dm-0: warning, user block quota exceeded.
161+0 records in
161+0 records out
164864 bytes (165 kB) copied, 0.00110889 s, 149 MB/s

 

 

now exit as kallu and login as root

when using quota kallu you see * in used blocks that means exceeded soft limit

[kallu@nfsserver ~]$ exit
logout
[root@nfsserver kallu]# quota kallu
Disk quotas for user kallu (uid 501):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/mapper/sysvg-homelv
                    204*    200     400    none      11       0       0

 

now lets login as kallu and try to create a file that exceeds hard limit

right now 204 kb is being used, so lets create a file of size 197 to cross limit of 400kb

 

[root@nfsserver kallu]# su - kallu
[kallu@nfsserver ~]$ ls -lh
total 164K
-rw-rw-r--. 1 kallu kallu 161K Dec 22 18:17 test

[kallu@nfsserver ~]$ dd if=/dev/zero of=/home/kallu/test1 bs=1024 count=197

dm-0: write failed, user block limit reached.
dd: writing /home/kallu/test1': Disk quota exceeded
197+0 records in
196+0 records out
200704 bytes (201 kB) copied, 0.000439156 s, 457 MB/s


[kallu@nfsserver ~]$ ls -lh
total 360K
-rw-rw-r--. 1 kallu kallu 161K Dec 22 18:40 test
-rw-rw-r--. 1 kallu kallu 196K Dec 22 18:41 test1                      


                  [created a file but 196 kb instead of 197 kb]




 

 

change to root and check quota

it shows u have exceeded the  limit

[root@nfsserver kallu]# quota kallu
Disk quotas for user kallu (uid 501):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/mapper/sysvg-homelv
                    400*    200     400   47:55      13       0       0

 

now if you try to create  then it wont let you create a file, and if you copy a file it will create a empty file

 

 

[kallu@nfsserver ~]$ dd if=/dev/zero of=/home/kallu/test3 bs=1024 count=20
dd: writing /home/kallu/test3': Disk quota exceeded
1+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000277985 s, 0.0 kB/s
[kallu@nfsserver ~]$ ls -lh
total 360K
-rw-rw-r--. 1 kallu kallu 161K Dec 22 18:40 test
-rw-rw-r--. 1 kallu kallu 196K Dec 22 18:41 test1
-rw-rw-r--. 1 kallu kallu    0 Dec 22 18:43 test3

 

system didnt let you create anything because it exceeded  the limit.

 

 

To turn off quota

 

quotaoff=turn filesystem quota off

quotaoff /home

 

remove aquota.user and aquota.group file

 rm -rf aquota.user

 

 

 rm -rf aquota.group

 

delete from fstab

/dev/mapper/sysvg-homelv /home ext4 defaults,usrjquota=aquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 1 2

to

 

/dev/mapper/sysvg-homelv /home ext4 defaults  1 2

 

and remount the filesystem

[kallu@nfsserver ~]$ mount - o remount /home

 

you should see this

[root@nfsserver ~]# cat /etc/mtab
/dev/mapper/sysvg-homelv /home ext4 rw 0 0

 

 

 

Leave a Reply