How to use disk quota on Linux with examples

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
How to use disk quota on Linux with examples
How to use disk quota on Linux with examples
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software quota
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – 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



  1. Now that the disk quota package is installed, we need to enable it for the desired storage partition by editing the /etc/fstab file. Use nano or your preferred text editor to open this file with root privileges:
    $ sudo nano /etc/fstab
    
  2. We will need to add the usrquota option to the line that corresponds to our storage partition. If you also want to enable disk quotas for groups, you can include the grpquota option as well. For example:
    /dev/sda1       /home   ext4 defaults,usrquota,grpquota 0 2
    
    We have added the usrquota and grpquota settings to the /etc/fstab file
    We have added the usrquota and grpquota settings to the /etc/fstab file

    When done making your changes, save the file and exit.

  3. 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
    
  4. Next, let’s create a quota index for the mount point. In our case, this would be /home. We will include options -c to create a new index, -m so to avoid mounting the partition as read only, and -u to specify that we want to create a quota for users. You can also append option -g if you want to make a group quota.
    $ sudo quotacheck -cmu /home
    
  5. Turn on the quota:
    $ sudo quotaon -v /home
    
  6. Then, we will use the edquota command 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.

    Disk quota configuration file for user
    Disk quota configuration file for user

    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.

    NOTE
    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.
  7. 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.

    Seting the grace period for soft limits
    Seting the grace period for soft limits

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:

  1. Set the disk quota for user linuxconfig:
    $ sudo edquota -u linuxconfig /home
    
  2. Set the disk quota for group developers:
    $ sudo edquota -g developers /home
    
  3. See the current quota settings for user linuxconfig on mount point /home:
    $ sudo quota -u linuxconfig /home
    
  4. Begin enforcing disk quota settings:
    $ sudo quotaon -v /home
    
  5. Turning off disk quotas:
    $ sudo quotaoff -v /home
    
  6. To copy disk quota settings from user linuxconfig1 to user linuxconfig2:
    $ sudo edquota -p linuxconfig1 linuxconfig2
    


Closing Thoughts

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.



Comments and Discussions
Linux Forum