Table of Content

Weight: 1

Description: Candidates should be able to manage disk quotas for users.

Key Knowledge Areas:

  • Set up a disk quota for a filesystem
  • Edit, check and generate user quota reports

Terms and Utilities:

quota
edquota
repquota
quotaon

quota

root@dclab-u1504s:/home/oldhorse# which quota
/usr/bin/quota
root@dclab-u1504s:/home/oldhorse# which quotaon
/sbin/quotaon

root@dclab-u1504s:/home/oldhorse# cat /etc/fstab 
/dev/sdb        /myspace        ext3    defaults        1       3 

change to 

/dev/sdb        /myspace        ext3    defaults,usrquota,grpquota      1       3 

root@dclab-u1504s:/home/oldhorse# umount /myspace 
root@dclab-u1504s:/home/oldhorse# mount -a
root@dclab-u1504s:/home/oldhorse# mount|grep quota
/dev/sdb on /myspace type ext3 (rw,relatime,quota,usrquota,grpquota,data=ordered)

convert sdb from ext3 to ext4

umount /myspace 
fsck.ext3 -pf /dev/sdb
tune2fs -O extents,uninit_bg,dir_index /dev/sdb
fsck.ext4 -yfD /dev/sdb

quotaon ext4

quotacheck -augvc
quotacheck: Scanning /dev/sdb [/myspace] done
quotacheck: Checked 2 directories and 2 files

quotaon -p /myspace/
group quota on /myspace (/dev/sdb) is off
user quota on /myspace (/dev/sdb) is off

quotaon -uagv
/dev/sdb [/myspace]: group quotas turned on
/dev/sdb [/myspace]: user quotas turned on

quotaon -p /myspace/
group quota on /myspace (/dev/sdb) is on
user quota on /myspace (/dev/sdb) is on

edquota

edquota -u oldhorse

default editor nano, ctrl-x to exit 

check quota

/myspace$ dd if=/dev/zero of=/myspace/testfile1 bs=1024 count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00322465 s, 325 MB/s

/myspace$ ls -lh
total 1.1M
-rw------- 1 root     root     7.0K Oct 17 09:18 aquota.group
-rw------- 1 root     root     7.0K Oct 17 09:18 aquota.user
drwx------ 2 oldhorse oldhorse  16K Oct  4 03:56 lost+found
-rw-rw-r-- 1 oldhorse oldhorse 1.0M Oct 17 09:43 testfile1

quota
Disk quotas for user oldhorse (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
       /dev/sdb    1044   10240   11264               3      50      50 

dd if=/dev/zero of=/myspace/testfile2 bs=1024 count=9500
9500+0 records in
9500+0 records out
9728000 bytes (9.7 MB) copied, 0.0469966 s, 207 MB/s

quota
Disk quotas for user oldhorse (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
       /dev/sdb   10544*  10240   11264   7days       4      50      50  

oldhorse@dclab-u1504s:/myspace$ ls -lh
total 11M
-rw------- 1 root     root     7.0K Oct 17 09:18 aquota.group
-rw------- 1 root     root     7.0K Oct 17 09:18 aquota.user
drwx------ 2 oldhorse oldhorse  16K Oct  4 03:56 lost+found
-rw-rw-r-- 1 oldhorse oldhorse 1.0M Oct 17 09:43 testfile1
-rw-rw-r-- 1 oldhorse oldhorse 9.3M Oct 17 09:43 testfile2

sudo repquota -ug /myspace/
[sudo] password for oldhorse: 
*** Report for user quotas on device /dev/sdb
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
oldhorse  +-   10544   10240   11264  6days       4    50    50       

*** Report for group quotas on device /dev/sdb
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
oldhorse  --   10544       0       0              4     0     0 

warn email for over quota

cat /etc/quotagrpadmins 
cat /etc/warnquota.conf 
cat /etc/quotatab 

sudo warnquota 
/bin/sh: 1: /usr/sbin/sendmail: not found
warnquota: Warning: Mailer exitted abnormally.

Quiz questions

1. Name 2 Linux filesystems that support quotas, and name one filesystem that does not.
2. What happens when the soft limit is reached?
3. What happens when the hard limit is reached?
4. Who can adjust filesystem quotas?
5. If changes are made to the filesystem while quotas are not enabled, which command must be used for quotas to work correctly?
Answers to quiz questions
1. reiserfs does not support quotas in some kernel versions. Ext2, ext3 and others do support quotas. Readonly
file systems do not support quotas.
2. Nothing happens. quota -q
begins to display a warning message.
3. The filesystem behaves as if it is full.
4. Only root.
5. quotacheck -avug
(or specify the specific filesystem)