Chapter 15. Limiting storage space usage with quotas

You can restrict the amount of disk space available to users or groups by implementing disk quotas. You can also define a warning level at which system administrators are informed before a user consumes too much disk space or a partition becomes full.

15.1. Disk quotas

In most computing environments, disk space is not infinite. The quota subsystem provides a mechanism to control usage of disk space.

You can configure disk quotas for individual users as well as user groups on the local file systems. This makes it possible to manage the space allocated for user-specific files (such as email) separately from the space allocated to the projects that a user works on. The quota subsystem warns users when they exceed their allotted limit, but allows some extra space for current work (hard limit/soft limit).

If quotas are implemented, you need to check if the quotas are exceeded and make sure the quotas are accurate. If users repeatedly exceed their quotas or consistently reach their soft limits, a system administrator can either help the user determine how to use less disk space or increase the user’s disk quota.

You can set quotas to control:

  • The number of consumed disk blocks.
  • The number of inodes, which are data structures that contain information about files in UNIX file systems. Because inodes store file-related information, this allows control over the number of files that can be created.

15.1.1. The xfs_quota tool

You can use the xfs_quota tool to manage quotas on XFS file systems. In addition, you can use XFS file systems with limit enforcement turned off as an effective disk usage accounting system.

The XFS quota system differs from other file systems in a number of ways. Most importantly, XFS considers quota information as file system metadata and uses journaling to provide a higher level guarantee of consistency.

Additional resources
  • The xfs_quota(8) man page.

15.2. Managing XFS disk quotas

You can use the xfs_quota tool to manage quotas in XFS and to configure limits for project-controlled directories.

Generic quota configuration tools (quota, repquota, and edquota for example) may also be used to manipulate XFS quotas. However, these tools cannot be used with XFS project quotas.

Important

Red Hat recommends the use of xfs_quota over all other available tools.

15.2.1. File system quota management in XFS

The XFS quota subsystem manages limits on disk space (blocks) and file (inode) usage. XFS quotas control or report on usage of these items on a user, group, or directory or project level. Group and project quotas are only mutually exclusive on older non-default XFS disk formats.

When managing on a per-directory or per-project basis, XFS manages the disk usage of directory hierarchies associated with a specific project.

15.2.2. Enabling disk quotas for XFS

This procedure enables disk quotas for users, groups, and projects on an XFS file system. Once quotas are enabled, the xfs_quota tool can be used to set limits and report on disk usage.

Procedure

  1. Enable quotas for users:

    # mount -o uquota /dev/xvdb1 /xfs

    Replace uquota with uqnoenforce to allow usage reporting without enforcing any limits.

  2. Enable quotas for groups:

    # mount -o gquota /dev/xvdb1 /xfs

    Replace gquota with gqnoenforce to allow usage reporting without enforcing any limits.

  3. Enable quotas for projects:

    # mount -o pquota /dev/xvdb1 /xfs

    Replace pquota with pqnoenforce to allow usage reporting without enforcing any limits.

  4. Alternatively, include the quota mount options in the /etc/fstab file. The following example shows entries in the /etc/fstab file to enable quotas for users, groups, and projects, respectively, on an XFS file system. These examples also mount the file system with read/write permissions:

    # vim /etc/fstab
    /dev/xvdb1    /xfs    xfs    rw,quota       0  0
    /dev/xvdb1    /xfs    xfs    rw,gquota      0  0
    /dev/xvdb1    /xfs    xfs    rw,prjquota    0  0

    Additional resources

    • The mount(8) man page.
    • The xfs_quota(8) man page.

15.2.3. Reporting XFS usage

You can use the xfs_quota tool to set limits and report on disk usage. By default, xfs_quota is run interactively, and in basic mode. Basic mode subcommands simply report usage, and are available to all users.

Prerequisites
Procedure
  1. Start the xfs_quota shell:

    # xfs_quota
  2. Show usage and limits for the given user:

    # xfs_quota> quota username
  3. Show free and used counts for blocks and inodes:

    # xfs_quota> df
  4. Run the help command to display the basic commands available with xfs_quota.

    # xfs_quota> help
  5. Specify q to exit xfs_quota.

    # xfs_quota> q
Additional resources
  • The xfs_quota(8) man page.

15.2.4. Modifying XFS quota limits

Start the xfs_quota tool with the -x option to enable expert mode and run the administrator commands, which allow modifications to the quota system. The subcommands of this mode allow actual configuration of limits, and are available only to users with elevated privileges.

Prerequisites
Procedure
  1. Start the xfs_quota shell with the -x option to enable expert mode:

    # xfs_quota -x
  2. Report quota information for a specific file system:

    # xfs_quota> report /path

    For example, to display a sample quota report for /home (on /dev/blockdevice), use the command report -h /home. This displays output similar to the following:

    User quota on /home (/dev/blockdevice)
    Blocks
    User ID      Used   Soft   Hard Warn/Grace
    ---------- ---------------------------------
    root            0      0      0  00 [------]
    testuser   103.4G      0      0  00 [------]
  3. Modify quota limits:

    # xfs_quota> limit isoft=500m ihard=700m user /path

    For example, to set a soft and hard inode count limit of 500 and 700 respectively for user john, whose home directory is /home/john, use the following command:

    # xfs_quota -x -c 'limit isoft=500 ihard=700 john' /home/

    In this case, pass mount_point which is the mounted xfs file system.

  4. Run the help command to display the expert commands available with xfs_quota -x:

    # xfs_quota> help
    Additional resources
    • The xfs_quota(8) man page.

15.2.5. Setting project limits for XFS

This procedure configures limits for project-controlled directories.

Procedure
  1. Add the project-controlled directories to /etc/projects. For example, the following adds the /var/log path with a unique ID of 11 to /etc/projects. Your project ID can be any numerical value mapped to your project.

    # echo 11:/var/log >> /etc/projects
  2. Add project names to /etc/projid to map project IDs to project names. For example, the following associates a project called Logs with the project ID of 11 as defined in the previous step.

    # echo Logs:11 >> /etc/projid
  3. Initialize the project directory. For example, the following initializes the project directory /var:

    # xfs_quota -x -c 'project -s logfiles' /var
  4. Configure quotas for projects with initialized directories:

    # xfs_quota -x -c 'limit -p bhard=lg logfiles' /var
    Additional resources
    • The xfs_quota(8) man page.
    • The projid(5) man page.
    • The projects(5) man page.

15.3. Managing ext3 and ext4 disk quotas

You have to enable disk quotas on your system before you can assign them. You can assign disk quotas per user, per group or per project. However, if there is a soft limit set, you can exceed these quotas for a configurable period of time, known as the grace period.

15.3.1. Installing the quota tool

You must install the quota RPM package to implement disk quotas.

Procedure

  • Install the quota package:
# yum install quota

15.3.2. Enabling quota feature on file system creation

This procedure describes how to enable quotas on file system creation.

Procedure

  1. Enable quotas on file system creation:

    # mkfs.ext4 -O quota /dev/sda
    Note

    Only user and group quotas are enabled and initialized by default.

  2. Change the defaults on file system creation:

    # mkfs.ext4 -O quota -E quotatype=usrquota:grpquota:prjquota /dev/sda
  3. Mount the file system:

    # mount /dev/sda

Additional resources

See the man page for ext4 for additional information.

15.3.3. Enabling quota feature on existing file systems

This procedure describes how to enable the quota feature on existing file system using the tune2fs command.

Procedure

  1. Unmount the file system:

    # umount /dev/sda
  2. Enable quotas on existing file system:

    # tune2fs -O quota /dev/sda
    Note

    Only user and group quotas are initialized by default.

  3. Change the defaults:

    # tune2fs -Q usrquota,grpquota,prjquota /dev/sda
  4. Mount the file system:

    # mount /dev/sda

Additional resources

See the man page for ext4 for additional information.

15.3.4. Enabling quota enforcement

The quota accounting is enabled by default after mounting the file system without any additional options, but quota enforcement is not.

Prerequisites

  • Quota feature is enabled and the default quotas are initialized.

Procedure

  • Enable quota enforcement by quotaon for the user quota:

    # mount /dev/sda /mnt
    # quotaon /mnt
    Note

    The quota enforcement can be enabled at mount time using usrquota, grpquota, or prjquota mount options.

    # mount -o usrquota,grpquota,prjquota /dev/sda /mnt
  • Enable user, group, and project quotas for all file systems:

    # quotaon -vaugP
    • If neither of the -u, -g, or -P options are specified, only the user quotas are enabled.
    • If only -g option is specified, only group quotas are enabled.
    • If only -P option is specified, only project quotas are enabled.
  • Enable quotas for a specific file system, such as /home:

    # quotaon -vugP /home

Additional resources

  • See the quotaon(8) man page.

15.3.5. Assigning quotas per user

The disk quotas are assigned to users with the edquota command.

Note

The text editor defined by the EDITOR environment variable is used by edquota. To change the editor, set the EDITOR environment variable in your ~/.bash_profile file to the full path of the editor of your choice.

Prerequisites

  • User must exist prior to setting the user quota.

Procedure

  1. Assign the quota for a user:

    # edquota username

    Replace username with the user to which you want to assign the quotas.

    For example, if you enable a quota for the /dev/sda partition and execute the command edquota testuser, the following is displayed in the default editor configured on the system:

    Disk quotas for user testuser (uid 501):
    Filesystem   blocks   soft   hard   inodes   soft   hard
    /dev/sda      44043      0      0    37418      0      0
  2. Change the desired limits.

    If any of the values are set to 0, limit is not set. Change them in the text editor.

    For example, the following shows the soft and hard block limits for the testuser have been set to 50000 and 55000 respectively.

    Disk quotas for user testuser (uid 501):
    Filesystem   blocks   soft   hard   inodes   soft   hard
    /dev/sda      44043  50000  55000    37418      0      0
    • The first column is the name of the file system that has a quota enabled for it.
    • The second column shows how many blocks the user is currently using.
    • The next two columns are used to set soft and hard block limits for the user on the file system.
    • The inodes column shows how many inodes the user is currently using.
    • The last two columns are used to set the soft and hard inode limits for the user on the file system.

      • The hard block limit is the absolute maximum amount of disk space that a user or group can use. Once this limit is reached, no further disk space can be used.
      • The soft block limit defines the maximum amount of disk space that can be used. However, unlike the hard limit, the soft limit can be exceeded for a certain amount of time. That time is known as the grace period. The grace period can be expressed in seconds, minutes, hours, days, weeks, or months.

Verification steps

  • Verify that the quota for the user has been set:

    # quota -v testuser
    Disk quotas for user testuser:
    Filesystem  blocks  quota  limit  grace  files  quota  limit  grace
    /dev/sda      1000*  1000   1000             0      0      0

15.3.6. Assigning quotas per group

You can assign quotas on a per-group basis.

Prerequisites

  • Group must exist prior to setting the group quota.

Procedure

  1. Set a group quota:

    # edquota -g groupname

    For example, to set a group quota for the devel group:

    # edquota -g devel

    This command displays the existing quota for the group in the text editor:

    Disk quotas for group devel (gid 505):
    Filesystem   blocks  soft  hard  inodes  soft  hard
    /dev/sda     440400     0     0   37418     0     0
  2. Modify the limits and save the file.

Verification steps

  • Verify that the group quota is set:

    # quota -vg groupname

15.3.7. Assigning quotas per project

This procedure assigns quotas per project.

Prerequisites

  • Project quota is enabled on your file system.

Procedure

  1. Add the project-controlled directories to /etc/projects. For example, the following adds the /var/log path with a unique ID of 11 to /etc/projects. Your project ID can be any numerical value mapped to your project.

    # echo 11:/var/log >> /etc/projects
  2. Add project names to /etc/projid to map project IDs to project names. For example, the following associates a project called Logs with the project ID of 11 as defined in the previous step.

    # echo Logs:11 >> /etc/projid
  3. Set the desired limits:

    # edquota -P 11
    Note

    You can choose the project either by its project ID (11 in this case), or by its name (Logs in this case).

  4. Using quotaon, enable quota enforcement:

    See Enabling quota enforcement.

Verification steps

  • Verify that the project quota is set:

    # quota -vP 11
    Note

    You can verify either by the project ID, or by the project name.

Additional resources

  • The edquota(8) man page.
  • The projid(5) man page.
  • The projects(5) man page.

15.3.8. Setting the grace period for soft limits

If a given quota has soft limits, you can edit the grace period, which is the amount of time for which a soft limit can be exceeded. You can set the grace period for users, groups, or projects.

Procedure

  • Edit the grace period:

    # edquota -t
Important

While other edquota commands operate on quotas for a particular user, group, or project, the -t option operates on every file system with quotas enabled.

Additional resources

  • The edquota(8) man page.

15.3.9. Turning file system quotas off

Use quotaoff to turn disk quota enforcement off on the specified file systems. Quota accounting stays enabled after executing this command.

Procedure

  • To turn all user and group quotas off:

    # quotaoff -vaugP
    • If neither of the -u, -g, or -P options are specified, only the user quotas are disabled.
    • If only -g option is specified, only group quotas are disabled.
    • If only -P option is specified, only project quotas are disabled.
    • The -v switch causes verbose status information to display as the command executes.

Additional resources

  • See the quotaoff(8) man page.

15.3.10. Reporting on disk quotas

You can create a disk quota report using the repquota utility.

Procedure

  1. Run the repquota command:

    # repquota

    For example, the command repquota /dev/sda produces this output:

    *** Report for user quotas on device /dev/sda
    Block grace time: 7days; Inode grace time: 7days
    			Block limits			File limits
    User		used	soft	hard	grace	used	soft	hard	grace
    ----------------------------------------------------------------------
    root      --      36       0       0              4     0     0
    kristin   --     540       0       0            125     0     0
    testuser  --  440400  500000  550000          37418     0     0
  2. View the disk usage report for all quota-enabled file systems:

    # repquota -augP

The -- symbol displayed after each user determines whether the block or inode limits have been exceeded. If either soft limit is exceeded, a + character appears in place of the corresponding - character. The first - character represents the block limit, and the second represents the inode limit.

The grace columns are normally blank. If a soft limit has been exceeded, the column contains a time specification equal to the amount of time remaining on the grace period. If the grace period has expired, none appears in its place.

Additional resources

The repquota(8) man page for more information.