Chapter 22. Limiting storage space usage on XFS 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. 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. 22.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. 22.2. 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 xfs_quota(8) man page on your system 22.3. 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. 22.4. Enabling disk quotas for XFS Enable 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 Enable quotas for users: Replace uquota with uqnoenforce to allow usage reporting without enforcing any limits. Enable quotas for groups: Replace gquota with gqnoenforce to allow usage reporting without enforcing any limits. Enable quotas for projects: Replace pquota with pqnoenforce to allow usage reporting without enforcing any limits. 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: Additional resources xfs(5) and xfs_quota(8) man pages on your system 22.5. Reporting XFS usage 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 Quotas have been enabled for the XFS file system. See Enabling disk quotas for XFS . Procedure Start the xfs_quota shell: Show usage and limits for the given user: Show free and used counts for blocks and inodes: Run the help command to display the basic commands available with xfs_quota . Specify q to exit xfs_quota . Additional resources xfs_quota(8) man page on your system 22.6. 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 Quotas have been enabled for the XFS file system. See Enabling disk quotas for XFS . Procedure Start the xfs_quota shell with the -x option to enable expert mode: Report quota information for a specific file system: 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: Modify quota limits: 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: In this case, pass mount_point which is the mounted xfs file system. Display the expert commands available with xfs_quota -x : Verification Verify that the quota limits have been modified: Additional resources xfs_quota(8) man page on your system 22.7. Setting project limits for XFS Configure limits for project-controlled directories. Procedure 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. Add project names to /etc/projid to map project IDs to project names. For example, the following associates a project called logfiles with the project ID of 11 as defined in the step. Initialize the project directory. For example, the following initializes the project directory /var : Configure quotas for projects with initialized directories: Additional resources xfs_quota(8) , projid(5) , and projects(5) man pages on your system

Commands:
mount -o uquota /dev/xvdb1 /xfs
mount -o gquota /dev/xvdb1 /xfs
mount -o pquota /dev/xvdb1 /xfs
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
xfs_quota
xfs_quota> quota username
xfs_quota> df
xfs_quota> help
xfs_quota> q
xfs_quota -x / path
xfs_quota> report / path
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 [------]
xfs_quota> limit isoft= 500m ihard= 700m user
xfs_quota -x -c 'limit isoft=500 ihard=700 john' /home/
xfs_quota> help
xfs_quota> report -i -u User quota on /home (/dev/loop0) Inodes User ID Used Soft Hard Warn/ Grace ---------- -------------------------------------------------- root 3 0 0 00 [------] testuser 2 500 700 00 [------]
echo 11:/var/log >> /etc/projects
echo logfiles:11 >> /etc/projid
xfs_quota -x -c 'project -s logfiles' /var
xfs_quota -x -c 'limit -p bhard=1g logfiles' /var