Configuring Disk Quotas on Ubuntu 22/24
apt-get install quota* -yapt-get -y install quota quotatool -yroot@rnd:~# df -hFilesystem Size Used Avail Use% Mounted ontmpfs 790M 1.7M 788M 1% /run/dev/mapper/ubuntu--vg-lv--0 96G 9.1G 82G 10% /tmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/lock/dev/sda2 2.0G 95M 1.7G 6% /boottmpfs 790M 16K 790M 1% /run/user/0root@rnd:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSloop0 7:0 0 55.4M 1 loop /snap/core18/2846loop1 7:1 0 309.6M 1 loop /snap/nextcloud/45728loop2 7:2 0 44.3M 1 loop /snap/snapd/23258sda 8:0 0 100G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot└─sda3 8:3 0 98G 0 part └─ubuntu--vg-lv--0 252:0 0 98G 0 lvm /root@rnd:~# quota --versionroot@rnd:~# find /lib/modules/`uname -r` -type f -name '*quota_v*.ko*'root@rnd:~# apt-get install linux-image-extra-virtualUpdating Filesystem Mount Optionsroot@rnd:~# vi /etc/fstab ----------BEST------------# / was on /dev/ubuntu-vg/lv-0 during curtin installation#/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bhysMpeYXVD1cAgZY / ext4 defaults 0 1/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bhysMpeYXVD1cAgZY / ext4 defaults,usrquota,grpquota 0 0# /boot was on /dev/sda2 during curtin installation/dev/disk/by-uuid/35a1b76b-563a-4423-b1e3-ada5bdcb3dc8 /boot ext4 defaults 0 1/swap.img none swap sw 0 0 -------------------- OR# / was on /dev/ubuntu-vg/lv-0 during curtin installation#/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bhysMpeYXVD1cAgZY / ext4 defaults 0 1/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bhysMpeYXVD1cAgZY / ext4 defaults,usrquota,grpquota 1 2 or
/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bhysMpeYXVD1cAgZY / ext4 defaults,usrquota,grpquota 0 2# /boot was on /dev/sda2 during curtin installation/dev/disk/by-uuid/35a1b76b-563a-4423-b1e3-ada5bdcb3dc8 /boot ext4 defaults 0 1/swap.img none swap sw 0 0 OR
$ sudo nano /etc/fstabYou should see something like this:-# <file system> <mount point> <type> <options> <dump> <pass># / was on /dev/sda2 during curtin installation/dev/disk/by-uuid/3aa0120a-00f9-40d2-89d0-75c08f69204a / ext4 defaults 0 1/swap.img none swap sw 0 0/dev/sdb1 /mnt/quotadir ext4 defaults 0 2Locate the line corresponding to the filesystem you want to enable quotas for. Add the usrquota and grpquota options to enable user and group quotas, respectively:/dev/sdb1 /mnt/quotadir ext4 defaults,usrqouta,grpquota 0 2 OR/dev/sda / ext4 usrquota,grpquota 0 1 root@rnd:~# mount -o remount /mount: (hint) your fstab has been modified, but systemd still uses the old version; use 'systemctl daemon-reload' to reload.root@rnd:~# systemctl daemon-reloadRemount the filesystem with the new options: root@rnd:~# mount -o remount /root@rnd:~# quotacheck -cugm /Verify that the new options are used to mount the filesystem: root@rnd:~# cat /proc/mounts | grep ' / '/dev/mapper/ubuntu--vg-lv--0 / ext4 rw,relatime,quota,usrquota,grpquota 0 0root@rnd:~# quotacheck -ugm /root@rnd:~# crontab -e# Add the following line@reboot quotacheck -augmTurn on the quota system using: root@rnd:~# quotaon -v / quotaon: Your kernel probably supports ext4 quota feature but you are using external quota files. Please switch your filesystem to use ext4 quota feature as external quota files on ext4 are deprecated.quotaon: using //aquota.group on /dev/sda [/]: Device or resource busyquotaon: using //aquota.user on /dev/sda [/]: Device or resource busy Configure Quotas for a User# edquota -u accesstel -f / # Now edit the default quota configuration file which is shown below: # edquota -u accesstel [set quota 2 GB]
Disk quotas for user accesstel (uid 1000): Filesystem blocks soft hard inodes soft hard /dev/mapper/ubuntu--vg-lv--0 32 0 2048576 11 0 0We can confirm the change by entering the user quota command in terminal:root@rnd:~# quota -u accesstel # quota -vs accesstelDisk quotas for user accesstel (uid 1000): Filesystem blocks quota limit grace files quota limit grace/dev/mapper/ubuntu--vg-lv--0 32 0 2048576 11 0 0 root@rnd:~# repquota -a*** Report for user quotas on device /dev/mapper/ubuntu--vg-lv--0Block grace time: 7days; Inode grace time: 7days Block limits File limitsUser used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 9468004 0 0 176439 0 0 man -- 2264 0 0 168 0 0 www-data -- 4 0 0 1 0 0 _apt -- 24 0 0 6 0 0 systemd-network -- 16 0 0 4 0 0 systemd-timesync -- 4 0 0 2 0 0 messagebus -- 4 0 0 1 0 0 pollinate -- 4 0 0 2 0 0 syslog -- 3448 0 0 5 0 0 uuidd -- 4 0 0 1 0 0 tss -- 4 0 0 1 0 0 landscape -- 12 0 0 5 0 0 fwupd-refresh -- 4 0 0 1 0 0 accesstel -- 32 0 2048576 11 0 To edit quota for the sudo user <example_user> that you added when securing your Linode compute instance, enter the following:# setquota -u <example_user> 100M 110M 0 0 /Check the new quota for the user:# quota -v <example_user>The output is similar to: Disk quotas for user rajie (uid 1000): Filesystem space quota limit grace files quota limit grace /dev/sda 40K 100M 110M 8 0 0You can generate a report for the quota usage of all users on a filesystem:# repquota -s /The output is similar to:*** Report for user quotas on device /dev/sdaBlock grace time: 10days; Inode grace time: 10days Space limits File limitsUser used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 3746M 0K 0K 119k 0 0man -- 1460K 0K 0K 155 0 0systemd-timesync -- 4K 0K 0K 2 0 0syslog -- 23588K 0K 0K 7 0 0_apt -- 36K 0K 0K 6 0 0tss -- 4K 0K 0K 1 0 0pollinate -- 4K 0K 0K 2 0 0landscape -- 8K 0K 0K 3 0 0fwupd-refresh -- 4K 0K 0K 1 0 0example_user -- 24K 200M 220M 8 0 0After
root@rnd:~# vi /etc/fstab# / was on /dev/ubuntu-vg/lv-0 during curtin installation#/dev/disk/by-id/dm-uuid-LVM-UDSJGoHLf7PAn3b3bDteiEyJ6PySc9WaALeNEubRrRRwd4s8hysMpeYXVD1cAgZY / ext4 defaults 0 1/dev/ubuntu-vg/lv-0 / ext4 usrquota,grpquota,defaults 0 2# /boot was on /dev/sda2 during curtin installation/dev/disk/by-uuid/35a1b76b-563a-4423-b1e3-ada5bdcb3dc8 /boot ext4 defaults 0 1/swap.img none swap sw 0 0 --------------------------X------------------------------------
$ sudo nano /etc/fstabYou should see something like this:-# <file system> <mount point> <type> <options> <dump> <pass># / was on /dev/sda2 during curtin installation/dev/disk/by-uuid/3aa0120a-00f9-40d2-89d0-75c08f69204a / ext4 defaults 0 1/swap.img none swap sw 0 0/dev/sdb1 /mnt/quotadir ext4 defaults 0 2Locate the line corresponding to the filesystem you want to enable quotas for. Add the usrquota and grpquota options to enable user and group quotas, respectively:/dev/sdb1 /mnt/quotadir ext4 defaults,usrqouta,grpquota 0 2Disk Quotas on Ubuntu to Manage User Storage
Disk Quotas on Ubuntu to Manage User Storage
Step 1: Installing Quota Management Tools
Ubuntu typically does not come with quota management tools pre-installed. We'll first install these tools with the following command:
sudo apt update
sudo apt install quota
Step 2: Preparing Filesystem for Disk Quotas
Follow this step if you have /home filesystem in your fstab.
We need to enable disk quota support on the filesystem where user data is stored. Typically, this is the /home directory. We'll edit the filesystem options in /etc/fstab:
Open /etc/fstab in a text editor:
sudo nano /etc/fstab
Find the entry for the partition containing /home. Modify it by adding the options usrquota and grpquota. An example line should look like this:
UUID=xxxx-xxxx /home ext4 defaults,usrquota,grpquota 0 2
Save and close the file.
To apply these changes, we need to remount the filesystem:
sudo mount -o remount /home
Follow these steps if you don't have /home filesystem in your fstab
Edit your /etc/fstab:
Find this line:
/dev/disk/by-uuid/af574f85-0c08-4c97-a460-dc899ba87a80 / ext4 defaults 0 1
Add usrquota,grpquota to the options:
Change it to:
/dev/disk/by-uuid/af574f85-0c08-4c97-a460-dc899ba87a80 / ext4 defaults,usrquota,grpquota 0 1
Save and close the file.
Since the quotas are now enabled for /, run:
sudo mount -o remount /
Step 3: Initializing Quota Database Files
Follow for /home filesystem
Next, we'll generate the quota database files required to manage disk usage:
sudo quotacheck -cum /home
sudo quotaon /home
Here:
quotacheck scans the filesystem and creates quota databases.
quotaon activates quotas on the specified filesystem.
Follow for root filesystem
Now, continue the tutorial steps, but use / (not /home) for all quota commands:
sudo quotacheck -cum /
sudo quotaon /
Step 4: Setting Disk Quotas for Users
Now, we can set storage limits for specific users. The disk quota can be set in two ways:
For example, to set quotas for a user named exampleuser, we execute:
sudo edquota -u exampleuser
This command opens a quota file in an editor, similar to:
Disk quotas for user exampleuser (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sda1 2048 0 0 10 0 0
Here, we set the soft and hard limits (in blocks, where each block is typically 1KB). For example, to restrict the user to 1GB soft limit (approximately 1,000,000 blocks) and 1.2GB hard limit (approximately 1,200,000 blocks), the file should appear as:
Disk quotas for user exampleuser (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sda1 2048 1000000 1200000 10 0 0
Save and close the editor after entering the values.
Step 5: Viewing Quota Status and Usage
To monitor quotas and ensure they are working correctly, we use:
sudo repquota -a
This command outputs a detailed list of all users' quotas, current usage, soft and hard limits, and any exceeded quotas.
Example output:
*** Report for user quotas on device /dev/sda1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
exampleuser 2048 1000000 1200000 10 0 0
Step 6: Adjusting Grace Period
If a user surpasses their soft limit, they have a predefined "grace period" during which they can continue to use storage before the soft limit becomes enforced. We can adjust this grace period:
sudo edquota -t
Modify grace periods (typically set as days):
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sda1 7days 7days
Change as desired and save.