Set Disk Quota
2025/01/04 |
Limit amount of disk usage to set Disk Quota.
For example on here, Set Disk Quota on [/home] which is XFS formatted filesystem. |
|
[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
UUID=f81d1f3c-0248-4b2d-a19c-70623e6ad9cf / xfs defaults 0 0
UUID=0a9b4bd1-bdc3-4111-a2b6-7c913683cc40 /boot xfs defaults 0 0
UUID=5fa38690-3750-415e-99a3-155a720bc1bf 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: #131 (1 blocks, 1 extents) Blocks grace time: [7 days] Blocks max warnings: 0 Inodes grace time: [7 days] Inodes max warnings: 0 Realtime Blocks grace time: [7 days] Group quota state on /home (/dev/sdb1) Accounting: ON Enforcement: ON Inode: #132 (1 blocks, 1 extents) Blocks grace time: [7 days] Blocks max warnings: 0 Inodes grace time: [7 days] Inodes max warnings: 0 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 [------] redhat 12K 0 0 00 [------] cent 12K 0 0 00 [------] Group quota on /home (/dev/sdb1) Blocks Group ID Used Soft Hard Warn/Grace ---------- --------------------------------- root 0 0 0 00 [------] redhat 12K 0 0 00 [------] cent 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 [------] redhat 12K 0 0 00 [------] cent 12K 4G 5G 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
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 [------] redhat 12K 4G 5G 00 [------] cent 12K 0 0 00 [------] |
[4] | It's possible to send warnings to use Warnquota. This setting needs SMTP server on your network. |
[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: <20250104025402.42391126051@dlp.srv.world> Date: Sat, 4 Jan 2025 11:54:02 +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 7days 9 0 0 root@localhost |
|