Set Disk Quota2021/08/26 |
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 [rocky] 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: 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 [------] rocky 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 [------] rocky 16K 0 0 00 [------] redhat 12K 0 0 00 [------] # set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes) to [rocky] user xfs_quota> limit bsoft=4g bhard=5g rocky # 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 [------] rocky 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 rocky' /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 [------] rocky 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. |
[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 Wed Aug 25 19:55:54 2021 Return-Path: <root@dlp.srv.world> X-Original-To: root@localhost Delivered-To: root@localhost From: root@localhost Reply-To: root@localhost Subject: NOTE: You are exceeding your allocated disk space limits To: rocky@dlp.srv.world Cc: root@localhost Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Date: Wed, 25 Aug 2021 19:55:54 +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 +- 4495M 4096M 5120M 6days 8 0 0 root@dlp.srv.world |
Sponsored Link |
|