Set Disk Quota2022/09/22 |
Limit amount of disk usage to set Disk Quota.
For example on here, Set Quota on [/home] which is ext4 formatted.
For using Quota on XFS file system, refer to here. |
|
[1] | Install Quota tools. |
root@dlp:~# apt -y install quota quotatool
|
[2] | Enable Quota feature. |
root@dlp:~# df -h /home Filesystem Size Used Avail Use% Mounted on /dev/sdb1 79G 52K 75G 1% /home # set quota feature and re-mount root@dlp:~# umount /home root@dlp:~# tune2fs -O quota /dev/sdb1 tune2fs 1.46.5 (30-Dec-2021)
root@dlp:~#
mount /dev/sdb1 /home
# confirm root@dlp:~# tune2fs -l /dev/sdb1 | grep -i quota Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize quota metadata_csum User quota inode: 3 Group quota inode: 4 |
[3] | Set user Quota. For example, Apply quota to [ubuntu] user. |
# show status root@dlp:~# quotaon -ap group quota on /home (/dev/sdb1) is on user quota on /home (/dev/sdb1) is on project quota on /home (/dev/sdb1) is off # set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)
Disk quotas for user ubuntu (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 28 4096000 5120000 10 0 0
# show status root@dlp:~# repquota -au *** Report for user quotas on device /dev/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20 0 0 2 0 0 ubuntu -- 28 4096000 5120000 10 0 0 |
[4] | If you'd like to apply setting of quota of a user to another user, set like follows. |
# apply setting of [ubuntu] to [debian] root@dlp:~# edquota -p ubuntu debian root@dlp:~# repquota -au *** Report for user quotas on device /dev/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20 0 0 2 0 0 ubuntu -- 28 4096000 5120000 10 0 0 debian -- 16 4096000 5120000 4 0 0 |
[5] | Set group Quota. For example, Apply quota to [ubuntu] group. |
# show status root@dlp:~# quotaon -ap group quota on /home (/dev/sdb1) is on user quota on /home (/dev/sdb1) is on project quota on /home (/dev/sdb1) is off # set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)
Disk quotas for group ubuntu (gid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 28 4096000 5120000 10 0 0
# show status root@dlp:~# repquota -ag *** Report for group quotas on device /dev/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits Group used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 20 0 0 2 0 0 ubuntu -- 28 4096000 5120000 10 0 0 debian -- 16 0 0 4 0 0 |
[6] | It's possible to send warnings to use Warnquota. This setting needs SMTP service on your server. |
root@dlp:~#
vi /etc/quotatab # add device and description which quota is set
/dev/sdb1: Home Directory
root@dlp:~#
vi /etc/warnquota.conf # change mail sender or others if you need MAIL_CMD = "/usr/sbin/sendmail -t" FROM = "root@localhost" # but they don't have to be: SUBJECT = Over quota CC_TO = "root@localhost" SUPPORT = "root@localhost" PHONE = "<enter your phone number here>" # CHARSET = UTF-8 # run warnquota root@dlp:~# warnquota -s
# if a user is over the limit when warnquota runs, following warning is sent Return-Path: <root@dlp.srv.world> X-Original-To: root@localhost Delivered-To: root@localhost Received: by dlp.srv.world (Postfix, from userid 0) id 75279A1521; Thu, 22 Sep 2022 04:33:26 +0000 (UTC) From: root@localhost Reply-To: root@localhost Subject: Over quota To: ubuntu@dlp.srv.world Cc: root@localhost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Message-Id: <20220922043326.75279A1521@dlp.srv.world> Date: Thu, 22 Sep 2022 04:33:26 +0000 (UTC) Hi, We noticed that you are in violation with the quotasystem used on this system. We have found the following violations: Home Directory (/dev/sdb1) Block limits File limits Filesystem used soft hard grace used soft hard grace /dev/sdb1 +- 5000M 4000M 5000M 6days 13 0 0 We hope that you will cleanup before your grace period expires. Basically, this means that the system thinks you are using more disk space on the above partition(s) than you are allowed. If you do not delete files and get below your quota before the grace period expires, the system will prevent you from creating new files. For additional assistance, please contact us at root@localhost or via phone at <enter your phone number here>. |
Sponsored Link |