CentOS Stream 9
Sponsored Link

Set Disk Quota2022/06/30

 
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 22.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/cs-root     /                       xfs     defaults        0 0
UUID=d12ef6a4-72bf-4d44-af00-51fcb8d48f59 /boot xfs     defaults        0 0
/dev/mapper/cs-swap     none                    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: #135 (2 blocks, 2 extents)
Blocks grace time: [7 days]
Blocks max warnings: 5
Inodes grace time: [7 days]
Inodes max warnings: 5
Realtime Blocks grace time: [7 days]
Group quota state on /home (/dev/sdb1)
  Accounting: ON
  Enforcement: ON
  Inode: #136 (2 blocks, 2 extents)
Blocks grace time: [7 days]
Blocks max warnings: 5
Inodes grace time: [7 days]
Inodes max warnings: 5
Realtime Blocks grace time: [7 days]
Project quota state on /home (/dev/sdb1)
  Accounting: OFF
  Enforcement: OFF
  Inode: N/A
Blocks grace time: [--------]
Blocks max warnings: 0
Inodes grace time: [--------]
Inodes max warnings: 0
Realtime Blocks grace time: [--------]

# 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          12K      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          12K      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          12K     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 redhat' /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          12K      0      0  00 [------]
redhat        12K     4G     5G  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/localhost/g" /etc/warnquota.conf

[root@dlp ~]#
sed -i -e "s/^FAIL/#FAIL/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@localhost
Reply-To: root@localhost
Subject: You are exceeding your allocated disk space limits
To: cent@dlp.srv.world
Cc: root@localhost
Message-Id: <20220630060536.BA2873008F8E@dlp.srv.world>
Date: Thu, 30 Jun 2022 15:05:36 +0900 (JST)

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      +-   5120M   4096M   5120M  6days       7     0     0

root@localhost
Matched Content