CentOS 7
Sponsored Link

Set Disk Quota2015/10/20

 
Limit amount of disk usage to set Disk Quota.
For example on here, Set Quota on /home which is XFS formatted.
For settings of ext4, refer to here.
[1] Enable Quota to add mount options.
[root@dlp ~]#
umount /home

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

/dev/mapper/centos-root /           xfs   defaults               0 0
UUID=c4df086e-3699-4e02-b7cf  /boot xfs   defaults               0 0
/dev/mapper/centos-swap swap        swap  defaults               0 0
/dev/sdb1               /home       xfs   defaults,uquota,gquota 0 0
[2] Set user Quota. For example, Apply quota to "cent" user.
# run quota tool with expert mode

[root@dlp ~]#
xfs_quota -x /home
# show current status

xfs_quota>
state

User quota state on /home (/dev/sdb1)
  Accounting: ON
  Enforcement: ON
  Inode: #136 (2 blocks, 2 extents)
Group quota state on /home (/dev/sdb1)
  Accounting: ON
  Enforcement: ON
  Inode: #137 (2 blocks, 2 extents)
Project quota state on /home (/dev/sdb1)
  Accounting: OFF
  Enforcement: OFF
  Inode: #137 (2 blocks, 2 extents)
Blocks grace time: [7 days 00:00:30]
Inodes grace time: [7 days 00:00:30]
Realtime Blocks grace time: [7 days 00:00:30]

# show usage reports

xfs_quota>
report -h

User quota on /home (/dev/sdb1)
                        Blocks
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
cent          16K      0      0  00 [------]

Group quota on /home (/dev/sdb1)
                        Blocks
Group ID     Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
cent          16K      0      0  00 [------]

# set Soft Limit 9G, Hard Limit 10G (specify with kilo bytes) to "cent" user

xfs_quota>
limit bsoft=9g bhard=10g cent
# show reports

xfs_quota>
report -h -u

User quota on /home (/dev/sdb1)
                        Blocks
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
cent          16K     9G    10G  00 [------]
[3] If you set group quota, do like follows.
# possible to set on non-interactive mode

[root@dlp ~]#
xfs_quota -x -c 'limit -g bsoft=9g bhard=10g cent' /home
[root@dlp ~]#
xfs_quota -x -c 'report -h -g' /home

Group quota on /home (/dev/sdb1)
                        Blocks
Group ID     Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
cent          16K     9G    10G  00 [------]
[4] It's possible to send warnings to use Warnquota.
This setting needs SMTP server on your server.
# install Warnquota

[root@dlp ~]#
yum -y install quota-warnquota
[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  Thu Oct 20 19:08:08 2015
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
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Date: Thu, 20 Oct 2015 19:08:08 +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 Directory (/dev/sdb1)

                        Block limits               File limits
Filesystem           used    soft    hard  grace    used  soft  hard  grace
/dev/sdb1      +-   4112M   4096M   5120M  6days       6     0     0

root@srv.world
Matched Content