CentOS 6
Sponsored Link

Set Disk Quota
2011/07/12
 
Limit amount of disk usage to set Disk Quota.
For example on here, Set Quota on /home which is ext4 formatted.
[1] Install Quota tools.
[root@dlp ~]#
yum -y install quota
[2] Enable Quota to add mount options.
[root@dlp ~]#
umount /home

[root@dlp ~]#
mount -o usrquota,grpquota /dev/sdb1 /home
[root@dlp ~]#
vi /etc/fstab
# add options

/dev/mapper/VolGroup-lv_root /          ext4    defaults        1 1
UUID=cf3f9660-e40d-459d-8763 /boot      ext4    defaults        1 2
/dev/mapper/VolGroup-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/sdb1                    /home      xfs     defaults,usrquota,grpquota 0 0
[3] Set user Quota. For example, Apply quota to "cent" user.
# create quota config

[root@dlp ~]#
quotacheck -um /home
# enable quota

[root@dlp ~]#
quotaon -uv /home

/dev/sdb1 [/home]: user quotas turned on
# show status

[root@dlp ~]#
quotaon -ap

group quota on /home (/dev/sdb1) is off
user quota on /home (/dev/sdb1) is on
# set quota to "cent"

[root@dlp ~]#
edquota -u cent
# set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)

Disk quotas for user cent (uid 500):
  Filesystem   blocks     soft       hard   inodes   soft   hard
  /dev/sdb1    16      4096000    5120000        7      0      0

# show status

[root@dlp ~]#
*** Report for user quotas on device /dev/sdb1
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
cent      --      16 4096000 5120000              4     0     0
[4] If you'd like to apply setting of quota of a user to another user, set like follows.
# apply setting of "cent" to "fedora"

[root@dlp ~]#
edquota -p cent fedora

[root@dlp ~]#
*** Report for user quotas on device /dev/sdb1
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
cent      +- 5120000 4096000 5120000  6days       7     0     0
fedora    --       4 4096000 5120000              4     0     0
[5] Set group Quota. For example, Apply quota to "cent" group.
# create quota config

[root@dlp ~]#
quotacheck -gm /home
# enable quota

[root@dlp ~]#
quotaon -gv /home

/dev/sdb1 [/home]: group quotas turned on
# show status

[root@dlp ~]#
quotaon -ap

group quota on /home (/dev/sdb1) is on
user quota on /home (/dev/sdb1) is on
# set quota to "cent"

[root@dlp ~]#
edquota -g cent
# set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)

Disk quotas for group cent (gid 500):
  Filesystem       blocks       soft       hard     inodes   soft   hard
  /dev/sdb1       5120000    4096000    5120000          7      0      0

# show status

[root@dlp ~]#
*** Report for group quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0
cent      +- 5120000 4096000 5120000  6days       7     0     0
fedora    --      16       0       0              4     0     0
[6] It's possible to send warnings to use Warnquota.
This setting needs SMTP server on your server.
[root@dlp ~]#
vi /etc/quotatab
# add device and description which quota is set

/dev/sdb1: Your Home Director
# change domain name to your own one

[root@dlp ~]#
sed -i -e "s/example\.com/server\.world/g" /etc/warnquota.conf
# run warnquota

[root@dlp ~]#
warnquota -s
# if a user is over the limit when warnquota runs, following warning is sent

From root@dlp.srv.world  Fri Oct 23 09:38:10 2011
Return-Path: <root@dlp.srv.world>
X-Original-To: cent
Delivered-To: cent@dlp.srv.world
From: root@srv.world
Reply-To: root@srv.world
Subject: NOTE: You are exceeding your allocated disk space limits
To: cent@dlp.srv.world
Cc: root@srv.world
Date: Fri, 23 Oct 2011 09:38:10 +0900 (JST)
Status: R

Your disk usage has exceeded the agreed limits on this server
Please delete any unnecessary files on following filesystems:

Your Home Director (/dev/sdb1)

                        Block limits               File limits
Filesystem           used    soft    hard  grace    used  soft  hard  grace
/dev/sdb1      +-   5000M   4000M   5000M  6days       7     0     0

root@srv.world
Matched Content
 
Tweet