19.23 Setting Quotas on an XFS File System

19.23.1 Setting Project Quotas

The following table shows the mount options that you can specify to enable quotas on an XFS file system:

Mount OptionDescription

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 do not enforce usage limits.

uquota

Enable user quotas and enforce usage limits.

To show the block usage limits and the current usage in the myxfs file system for all users, use the xfs_quota command:

# xfs_quota -x -c 'report -h' /myxfs
User quota on /myxfs (/dev/vg0/lv0)
                        Blocks              
User ID      Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
root            0      0      0  00 [------]
guest           0   200M   250M  00 [------]

The following forms of the command display the free and used counts for blocks and inodes respectively in the manner of the df -h command:

# xfs_quota -c 'df -h' /myxfs
Filesystem     Size   Used  Avail Use% Pathname
/dev/vg0/lv0 200.0G  32.2M  20.0G   1% /myxfs

# xfs_quota -c 'df -ih' /myxfs
Filesystem   Inodes   Used   Free Use% Pathname
/dev/vg0/lv0  21.0m      4  21.0m   1% /myxfs

If you specify the -x option to enter expert mode, you can use subcommands such as limit to set soft and hard limits for block and inode usage by an individual user, for example:

# xfs_quota -x -c 'limit bsoft=200m bhard=250m isoft=200 ihard=250 guest' /myxfs 

Of course, this command requires that you mounted the file system with user quotas enabled.

To set limits for a group on an XFS file system that you have mounted with group quotas enabled, specify the -g option to limit, for example:

# xfs_quota -x -c 'limit -g bsoft=5g bhard=6g devgrp' /myxfs

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

19.23.1 Setting Project Quotas

User and group quotas are supported by other file systems, such as ext4. The XFS file system additionally allows you to set quotas on individual directory hierarchies in the file system that are known as managed trees. Each managed tree is uniquely identified by a project ID and an optional project name. Being able to control the disk usage of a directory hierarchy is useful if you do not 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 on it:

  1. Mount the XFS file system with project quotas enabled:

    # mount -o pquota device mountpoint

    For example, to enable project quotas for the /myxfs file system:

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

    # echo project_ID:mountpoint/directory >> /etc/projects

    For example, to set a project ID of 51 for the directory hierarchy /myxfs/testdir:

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

    # echo project_name:project_ID >> /etc/projid

    For example, to map the project name testproj to the project with ID 51:

    # echo testproj:51 >> /etc/projid
  4. Use the project subcommand of xfs_quota to define a managed tree in the XFS file system for the project:

    # xfs_quota -x -c ’project -s project_namemountpoint

    For example, to define a managed tree in the /myxfs file system for the project testproj, which corresponds to the directory hierarchy /myxfs/testdir:

    # xfs_quota -x -c ’project -s testproj’ /myxfs
  5. Use the limit subcommand to set limits on the disk usage of the project:

    # xfs_quota -x -c ’limit -p arguments project_namemountpoint

    For example, to set a hard limit of 10 GB of disk space for the project testproj:

    # xfs_quota -x -c ’limit -p bhard=10g testproj’ /myxfs

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