Setting Filesystem Quotas on Ubuntu 22.04

Install the Quota Tools

  1. Install the quota command line tools using apt package manager:

    sudo apt update
    sudo apt install quota
  2. Update the mount options for the filesystem by updating the corresponding entry in /etc/fstab configuration file, using an editor of your choice to:

    # <file system> <mount point>   <type>  <options>                  <dump>  <pass>
    /dev/sda /home ext4 defaults,usrquota,grpquota 0 1

The options usrquota and grpquota enables quotas on the filesystem for both users and groups. Ensure that you add the new options separated by a comma and no spaces.

  1. Remount the filesystem to apply the new options:

    sudo mount -o remount /home
  2. Verify that the new options are used to mount the filesystem:

    cat /proc/mounts | grep ' /home '
  3. Create the aquota.user, and aquota.group files that contain information about the limits and the usage of the filesystem:

    sudo quotacheck -ugm /home

    The option -u creates the aquota.user file for users, the -g option creates the aquota.group file groups, and the -m option disables remounting the filesystem as read-only. You can view the quota files that are created using the ls /home command.

  4. Turn on the quota system using:

    sudo quotaon -v /home

Configure Quotas for a User

To edit quota for user , enter the following:

sudo setquota -u <example_user> 100M 110M 0 0 /home

Check the new quota for the user:

sudo quota -v <example_user>

If you want your users to be able to check their quotas, even if they do not have sudo access, then you need to give them permission to read the quota files you created. Create a users group, make those files readable by the users group, and then make sure all your users are added in the group.

Also, users can check their quota usage using the quota command:

quota -s --hide-device --show-mntpoint