Implementing a disk quota will prevent users or groups from using too much storage space on a Linux system. This is very useful on systems such as file servers that allow many users to connect and store data, as it ensures that no particular user can utilize an unexpected amount of storage and interrupt storage or processes on the server by making it run out of disk space. Linux administrators should always put a quota on the maximum storage usage for users, as well as other user environment limits like max number of processes and open files.
In this tutorial, we will see the step by step instructions on how to use disk quotas on all major Linux distributions. The instructions will include examples that you can easily copy and paste and then adjust accordingly for use on your own system. The ultimate goal of this implementation is to ensure that disk space will be allocated fairly among the existing users, and that new users will automatically have their own limitations set when their account is created.
In this tutorial you will learn:
- How to install the disk quota package on all major Linux distros
- How to configure disk quota limits for a user or group
- How to set soft limit grace period settings
- Examples for configuring disk quotas and viewing reports
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to Install Disk Quota on Linux
The disk quota software package is usually installed by default on most Linux distributions. In case it is not, you can use the appropriate command below to install disk quota with your system’s package manager.
To install disk quota on Ubuntu, Debian, and Linux Mint:
$ sudo apt install quota
To install disk quota on Fedora, CentOS, AlmaLinux, and Red Hat:
$ sudo dnf install disk quota
To install disk quota on Arch Linux and Manjaro:
$ sudo pacman -S quota-tools
Using Disk Quota on Linux
- Now that the disk quota package is installed, we need to enable it for the desired storage partition by editing the
/etc/fstabfile. Use nano or your preferred text editor to open this file with root privileges:
$ sudo nano /etc/fstab
- We will need to add the
usrquotaoption to the line that corresponds to our storage partition. If you also want to enable disk quotas for groups, you can include the
grpquotaoption as well. For example:
/dev/sda1 /home ext4 defaults,usrquota,grpquota 0 2
When done making your changes, save the file and exit.
- Next, you will need to remount the file system for the changes to take effect. Alternative, rebooting the system will also work.
$ sudo mount -o remount,rw /home
- Next, let’s create a quota index for the mount point. In our case, this would be
/home. We will include options
-cto create a new index,
-mso to avoid mounting the partition as read only, and
-uto specify that we want to create a quota for users. You can also append option
-gif you want to make a group quota.
$ sudo quotacheck -cmu /home
- Turn on the quota:
$ sudo quotaon -v /home
- Then, we will use the
edquotacommand to begin putting quotas for individual users. Specify the name of the user that you would like to edit the quotas for after your command. In this example, we will edit the disk quota for user ‘linuxconfig’:
$ sudo edquota -u linuxconfig
This will open up a configuration file in your system’s default text editor, as seen below.
Here is what each column means:
blocks – the number of blocks (1k each) currently used by the user.
soft – the soft maximum number of 1k blocks the user is allowed to use.
hard – the hard maximum number of 1k blocks the user is allowed to use.
inodes – the current number of inodes used by the user.
soft – the soft maximum number of inodes the user is allowed to use.
hard – the hard maximum number of inodes the user is allowed to use.
When a user hits a soft limit, they will be issued a warning, but the limit is not strictly enforced. When a user hits a hard limit, this is the absolute maximum number of blocks or inodes they are allowed to use, and they will not be permitted to use more.
- With our soft and hard limits set, we can control the grace period of our soft limits with the following command:
$ sudo edquota -t
Set the limits as you see fit, by specifying a number and then units in either days, hours, minutes, or seconds.
After saving your changes to the file, your soft and hard limits will be set for the configured user and start to take effect.
Disk Quota Examples
Here are some examples for setting disk quotas and seeing disk quota information on Linux:
- Set the disk quota for user linuxconfig:
$ sudo edquota -u linuxconfig /home
- Set the disk quota for group developers:
$ sudo edquota -g developers /home
- See the current quota settings for user
linuxconfigon mount point
$ sudo quota -u linuxconfig /home
- Begin enforcing disk quota settings:
$ sudo quotaon -v /home
- Turning off disk quotas:
$ sudo quotaoff -v /home
- To copy disk quota settings from user linuxconfig1 to user linuxconfig2:
$ sudo edquota -p linuxconfig1 linuxconfig2
In this tutorial, we saw how to use disk quotas on a Linux system with examples. Disk quotas are a powerful and useful feature that set limits on the amount of storage space that users or groups can consume, which ensures that excessive use will not interrupt the system for other processes and users that are on it. This involves enabling quotas, setting the hard and soft limits on a user or group basis, and then reguarly checking quota reports to see that it is enforcing them as expected. When properly managed, disk quotas can help system performance and stability for all of the connected users.