CentOS 8
Sponsored Link

Set Disk Quota2020/01/09

 
Limit amount of disk usage to set Disk Quota.
For example on here, Set Disk Quota on [/home] which is XFS formatted filesystem.
For quota settings on ext4, refer to here (Ubuntu 18.04).
[1] Enable Quota to add mount options.
# add quota options to the target mount point

[root@dlp ~]#
umount /home

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

/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=b7886c5b-b915-4b00-aaa0-2cc856645e3d /boot ext4    defaults        1 2
/dev/mapper/cl-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: #131 (2 blocks, 2 extents)
Group quota state on /home (/dev/sdb1)
  Accounting: ON
  Enforcement: ON
  Inode: #132 (2 blocks, 2 extents)
Project quota state on /home (/dev/sdb1)
  Accounting: OFF
  Enforcement: OFF
  Inode: N/A
Blocks grace time: [7 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]

# 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 [------]
redhat        12K      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 [------]
redhat        12K      0      0  00 [------]

# set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes) to [cent] user
xfs_quota> limit bsoft=4g bhard=5g 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     4G     5G  00 [------]
redhat        12K      0      0  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=4g bhard=5g 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     4G     5G  00 [------]
redhat        12K      0      0  00 [------]
[4] It's possible to send warnings to use Warnquota.
This setting needs SMTP server on your network.
# install Warnquota

[root@dlp ~]#
dnf -y install quota-warnquota
[root@dlp ~]#
vi /etc/quotatab
# add device and description which quota is set

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

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

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

From root@dlp.srv.world  Thu Jan  8 19:32:10 2020
Return-Path: <root@dlp.srv.world>
X-Original-To: root@dlp.srv.world
Delivered-To: root@dlp.srv.world
From: root@dlp.srv.world
Reply-To: root@dlp.srv.world
Subject: NOTE: You are exceeding your allocated disk space limits
To: cent@dlp.srv.world
Cc: root@dlp.srv.world
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Date: Thu,  8 Jan 2020 19:32: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 Directory (/dev/sdb1)

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

root@dlp.srv.world
Matched Content