About Disk Quotas

You can set disk quotas to restrict the amount of disk space or blocks that users or groups can use, to limit the number of files or inodes that users or groups can create, and to notify you when usage is reaching a specified limit. A hard limit specifies the maximum number of blocks or inodes that are available to a user or group on the file system. Users or groups can exceed a soft limit for a period, which is known as a grace period.

Oracle Linux 8 doesn't provide support for user and group disk quotas for a Btrfs file system. However, quota support at the subvolume level is available for a Btrfs file system as a technology preview in this release. For more information, see Managing Quotas for Btrfs Subvolumes With Quota Groups.

For information about how to configure quotas for an XFS file system, see Managing Quotas on an XFS File System.

Enabling Disk Quotas on File Systems

Disk quotas are enabled at mount. The following table describes the options that you can specify with the mount command to enable quotas.

Mount Option Description

gqnoenforce

Enable group quotas. Report usage, but do not enforce usage limits.

gquota

Enable group quotas and enforce usage limits.

pqnoenforce

Enable project quotas. Report usage, but do not enforce usage limits.

pquota

Enable project quotas and enforce usage limits.

uqnoenforce

Enable user quotas. Report usage, but don't enforce usage limits.

uquota

Enable user quotas and enforce usage limits.

  1. Install the quota package on the system, if not already installed:

    sudo dnf install quota
  2. Add the usrquota or grpquota options to the file system's /etc/fstab entry:

    /dev/sdb1       /home        ext4    usrquota,grpquota   0 0
  3. Remount the file system:

    sudo mount -o remount /home
  4. Create the quota database files:

    sudo quotacheck -cug /home

    The previous command creates the files aquota.user and aquota.group in the root of the file system, which is /home in this example.

For more information, see the quotacheck(8) manual page.

Assigning Disk Quotas to Users and Groups

  1. For a user, use the following command:

    sudo edquota username

    for a group, use the following command:

    sudo edquota -g group

    Running the previous command opens a text file opens in the default editor that's defined by the EDITOR environment variable. Therefore, you can specify the limits for the user or group, for example:

    Disk quotas for user guest (uid 501)
    Filesystem  blocks  soft  hard  inodes  soft  hard
     /dev/sdb1   10325     0     0    1054     0     0

    The blocks and inodes entries reflect the user's current usage on a file system.

    Tip:

    Setting a limit to 0 disables quota checking and enforcement for the corresponding blocks or inodes category.

  2. Edit the soft and hard block limits for the number of blocks and inodes, then save the changes.

Or, you can use the setquota command to configure quota limits from the command line. The -p option applies quota settings from one user or group to another user or group.

Note that when using XFS file systems, xfs_quota is the preferred tool to manage quota information. See Managing Quotas on an XFS File System for more information.

For more information, see the edquota(8) and setquota(8) manual pages.

Setting Project Quotas

Some file systems enable you to set quotas on individual directory hierarchies, which are known as managed trees. Each managed tree is uniquely identified by a project ID and an optional project name. The ability to control the disk usage of a directory hierarchy is useful if you don't otherwise want to set quota limits for a privileged user, for example, /var/log, or if many users or groups have write access to a directory, for example, /var/tmp.

To define a project and set quota limits for it:

  1. Mount the file system with project quotas enabled.

    sudo mount -o pquota device mountpoint

    For example, to enable project quotas for the /myxfs file system, you would use the following command:

    sudo mount -o pquota /dev/vg0/lv0 /myxfs
  2. Define a unique project ID for the directory hierarchy in the /etc/projects file.

    sudo echo project_ID:mountpoint/directory |sudo tee -a /etc/projects

    For example, you would set a project ID of 51 for the directory hierarchy /myxfs/testdir as follows:

    sudo echo 51:/myxfs/testdir |sudo tee -a /etc/projects
  3. Create an entry in the /etc/projid file that maps a project name to the project ID.

    sudo echo project_name:project_ID |sudo tee -a /etc/projid

    For example, you would map the project name testproj to the project with ID 51 as follows:

    sudo echo testproj:51 |sudo tee -a /etc/projid

For more information, see the projects(5) and projid(5) manual pages.

With the file system mounted to enable project quotas and project IDs set for the directory hierarchy, you can set limits for the project quota using edquota or xfs_quota. Note that when using XFS file systems, xfs_quota is preferred. See Managing Quotas on an XFS File System for more information.

Setting a Grace Period for Soft Limits

  1. Run the following command to set a grace period for soft limits:

    sudo edquota -t

    Running the previous command opens a text file in a default text editor, thus enabling you to specify the grace period, as shown in the following example:

    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/sdb1            7days                  7days 
  2. Specify the grace periods for the soft limits on the number of blocks and inodes, then save the changes.

For more information, see the edquota(8) manual page.

Displaying Disk Quotas

To display a user's disk usage, use the quota command without any options or arguments:

sudo quota username

To display a group's disk usage, add the -g option, use the following command:

sudo quota -g group

To display information about file systems, where usage is over the quota limits, add the -q option, for example:

sudo quota -q

Users can also use the quota command to display disk usage for themselves and their group.

For more information, see the quota(1) manual page.

Enabling and Disabling Disk Quotas

To disable disk quotas for all users, groups on a specific file system, use the following command:

sudo quotaoff -guv filesystem

To disable disk quotas for all users, groups, and file systems, use the following command:

sudo quotaoff -aguv

Reactivate disk quotas for all users, groups, and file systems as follows:

sudo quotaon -aguv

For more information, see the quotaon(1) manual page.

Reporting on Disk Quota Usage

To display the disk quota usage for a file system:

sudo repquota filesystem

To display the disk quota usage for all file systems:

sudo repquota -a

For more information, see the repquota(8) manual page.

Maintaining the Accuracy of Disk Quota Reporting

Uncontrolled system shutdowns can lead to inaccuracies in disk quota reports.

The following steps show how to rebuild the quota database for a file system:

  1. Disable disk quotas for the file system:

    sudo quotaoff -guv filesystem
  2. Unmount the file system:

    sudo umount filesystem
  3. Rebuild the quota databases:

    sudo quotacheck -guv filesystem
  4. Mount the file system:

    sudo mount filesystem
  5. Enable disk quotas for the file system:

    sudo quotaoff -guv filesystem

For more information, see the quotacheck(8) manual page.