Chapter 5. Quotas

If your system is constantly short of disk space and you cannot increase the amount of available space, you may be forced to implement disk quotas. Quotas allow you to limit the amount of space a user can occupy and the number of files (inodes) each user can own. The XFS filesystem supports disk quotas to automate this process. You can use this system to implement specific disk usage quotas for each user on your system. You can implement  hard or soft limits; hard limits are enforced by the system, soft limits merely remind the user to trim disk usage. Disk usage limits are not enforced for root.

With soft limits, whenever a user logs in with a usage greater than the assigned soft limit, that user is warned (by the login command). When the user exceeds the soft limit, the timer is enabled. Any time the quota drops below the soft limits, the timer is disabled. If the timer is enabled longer than a time period set by the system administrator, the particular limit that has been exceeded is treated as if the hard limit has been reached, and no more disk space is allocated to the user. The only way to reset this condition is to reduce usage below the quota. Only root may set the time limits, and this is done on a per-filesystem basis.

Several options are available on XFS filesystems. You can impose limits on some users and not others, some filesystems and not others, and on total disk usage per user, or total number of files. In addition, on XFS filesystems there is no limit to the number of accounts and there is little performance penalty for large numbers of users.

On XFS filesystems, you can also impose limits according to group IDs as well as user IDs. For information on using disk quotas for user and group IDs, see “Using Disk Quotas on XFS Filesystems”.

Disk quotas on XFS filesystems can be used to do disk usage accounting. Disk usage accounting monitors disk usage, but does not enforce disk usage limits. See “Monitoring Disk Space Usage with Disk Quota Accounting” for more information.

Disk quotas are described in more detail in the quotas(4) reference page. Procedures for imposing and monitoring disk quotas are described in “Using Disk Quotas on XFS Filesystems”.

Using Disk Quotas on XFS Filesystems

This section describes basic commands for administering disk quotas on XFS filesystems. Additional commands are described on the quota(1), edquota(1M), and repquota(1M) reference pages.

You can set disk quotas for individual users and you can set disk quotas for groups according to group ID.

For XFS filesystems, you must first turn on disk quotas on a filesystem, then set quotas on that filesystem for users and projects or groups.

Turning on Disk Quotas for Users on XFS Filesystems

You can turn on quotas for users in these ways:

  • T o turn on disk quotas automatically for users on a non-root filesystem, include the option quota in the /etc/fstab entry, for example:

    /dev/foo / xfs rw,quota 0 0
    

  • To turn on disk quotas manually for users on a non-root filesystem, mount the filesystem with this command:

    # mount -o quota fsname rootdir 
    

    fsname is the device name of the filesystem. rootdir is the directory where the filesystem is mounted.

  • To turn on disk quotas for users on the root filesystem, you must pass the quota mount options into the kernel at boot time through the Linux rootflags boot option. The following example adds the rootflags=quota option to the append line in elilo.conf:

    append="root=/dev/xscsi/pci00.01.0-1/tsrget0/lun0/part3 rootflags=quota
    

Turning on Disk Quotas for Groups on XFS Filesystems

You can turn on quotas for groups in these ways:

  • To turn on disk quotas automatically for groups on a non-root filesystem, include the option gquota in the /etc/fstab entry, for example:

    
    
    /dev/foo / xfs rw,gquota 0 0
    

  • To turn on disk quotas manually for groups on a non-root filesystem, mount the filesystem with this command:

    # mount -o 
    gquota fsname rootdir 
    

    fsname is the device name of the filesystem. rootdir is the directory where the filesystem is mounted.

  • To turn on disk quotas manually for groups on the root filesystem, give these commands:

  • To turn on disk quotas for groups on the root filesystem, you must pass the quota mount options into the kernel at boot time through the Linux rootflags boot option. The following example adds the rootflags=gquota option to the append line in elilo.conf:

    append="root=/dev/xscsi/pci00.01.0-1/tsrget0/lun0/part3 rootflags=gquota
    

Setting Disk Quota Limits for Users on XFS Filesystems

After turning on disk quotas on a filesystem, you can set limits for users on that filesystem using the commands below. You can preview the results of each of these commands by adding a -n option, which is the dry-run option.

  • To specify limits for users interactively, give this command:

    # 
    edquota name ... 
    

    name is a user name or numeric user ID. The screen clears, and you are placed in the editor specified by the EDITOR environment variable (vi if $EDITOR is not set) to edit the disk quotas for the filesystem mounted at rootdir for the first user listed on the command line. You see:

    fs rootdir kbytes (soft = 0, hard = 0) inodes (soft = 0, hard = 0)
    

    The first pair of soft and hard numbers are the soft and hard limits for disk usage in kilobytes in the filesystem at rootdir. The second pair of soft and hard numbers are the soft and hard limits for the number of files that user can own in the filesystem.

    Edit the zeros to set the limits to sizes you choose. A limit of zero is not enforced. After you set the limits, save the file and quit the editor. If you specified more than one user on the command line, another instance of the editor appears with the line above. Edit this line to enter the limits for the second user. Continue until lines have been edited for all users.

  • To specify that users are to have the same limits as another user (proto_name),enter this command:

    # edquota -p proto_name name ...\
    

  • To specify limits for a user non-interactively, enter this command:

    # edquota -f rootdir -l \
    uid=userid,bsoft=kvalue,bhard=kvalue,isoft=value,ihard=value 
    

    userid is a user name or numeric user ID. Each kvalue is a soft or hard limit for disk usage in kilobytes.Each value is a soft or hard limit for the number of files the user can own.

  • To use the file (quotafile) created by command repquota -e as input to the edquota command, enter this command:

    # edquota -i quotafile 
    

Setting Disk Quota Limits for Groups on XFS Filesystems

After turning on disk quotas on a filesystem, you can set limits for groups on that filesystem. You set limits for groups just as you do for users, by using the edquota command as described in “Setting Disk Quota Limits for Users on XFS Filesystems”.

To use the edquota command to set limits for a project, you include the -g option on the command line. When you use the -g option with edquota, any name specified on the command line is considered a group name. For example, to specify limits for groups interactively, give this command:

# 
edquota -g name ... 

name is a group name or numeric group ID. For information on additional options of the edquota command, see the edquota(1M) man page.

Use of disk quota limits for groups and use of disk quota limits for projects are mutually exclusive.

Displaying Disk Quota Information on XFS Filesystems

Some commands that display information about disk quotas are as follows:

  • To display a report that shows whether disk quotas are on or off for each filesystem, give this command as superuser:

    # 
    repquota -sa 
    /dev/root (/):
    --------------
    Status
            user  quota accounting       : on
            user  quota limit enforcement: on
            proj  quota accounting       : off
            proj  quota limit enforcement: off
            group quota accounting       : off
            group quota limit enforcement: off
    Quota Storage
            user  quota inum 103156, blocks 8, extents 7
            proj  quota inum 103157, blocks 5, extents 4
    Default Limits
            blocks time limit: 1.0 week
            files  time limit: 1.0 week
    Cache
            dquots currently cached in memory: 14
    --------------------
    

    The sections of the output are as follows:

    Status  

    Lists the status of disk space accounting (on or off) and enforcement of disk quotas (on or off) for this filesystem.

    Quota Storage  

    Blocks and extents are the number of filesystem blocks and extents used to store disk quota information. The inum value is the inode number at which quota information is stored and is for internal use only.

    Default Limits  

    The blocks and files time limits are the default lengths of time for this filesystem that users have to reduce their disk space usage or number of files below their soft limits. These time limits can be set on a per-user basis by the command edquota -t.

    Cache  

    This section is for internal use only

  • To get information about your disk quotas, enter this command:

    # 
    quota -v 
    Disk quotas for margo (uid 1606):
    Filesystem    usage   quota   limit    timeleft  files   quota   limit   timeleft
    /            138360       0       0              14971       0       0
    /e          4156360   41200       0    1.6 days 222264       0       0
    

    The columns in this output are:

    Filesystem  

    Lists each of the filesystems that have quotas turned on.

    usage 

    Lists the user's disk usage on each filesystem.

    quota 

    The user's soft limit for disk usage or files on each filesystem.

    limit  

    The user's hard limit for disk usage or files on each filesystem.

    timeleft  

    For filesystems where the user's soft limit for disk usage or files is exceeded, gives the number of days until the user is prohibited from using additional disk space or creating more files.

    files  

    The number of files owned by the user on each filesystem.

  • To get information about your group disk quotas, enter this command:

    # quota -g -v 
    Disk quotas for staff (gid 50):
    Filesystem    usage   quota   limit    timeleft  files   quota  limit    timeleft
    /part1            4       0       0                  2       0      0            
    
    

Administering Disk Quotas on XFS Filesystems

If the filesystem being dumped contains quotas, xfsdump will use repquota(1M) to store the quotas in the following files in the root of the filesystem to be dumped:

xfsdump_quotas  

user quotas

xfsdump_quotas_group  

group quotas

These files will then be included in the dump. These files will appear only for those quotas which are enabled on the filesystem being dumped. Upon restoration, edquota(1M) can be used to reactivate the quotas for the filesystem. Note, however, that the xfsdump_quotas file will probably require modification to change the filesystem or UIDs if the filesystem has been restored to a different partition or system.

To create a file that lists the current quota limits of all the filesystems for users, enter this command as superuser:

# 
repquota -a -e quotafile 

To create a file that lists the current quota limits of all the filesystems for groups, enter this command as superuser:

# repquota -g -a -e quotafile 

Monitoring Disk Space Usage with Disk Quota Accounting

The disk quotas system can be used to monitor disk space usage without enforcing disk usage limits. Disk quota accounting can be enabled by user or by group.

On XFS filesystems, use these commands to turn on disk usage accounting without enforcement, stop disk usage accounting, and report disk space usage:

  • To turn on disk usage accounting automatically on a filesystem for user quotas, include the option qnoenforce in the /etc/fstab entry, for example:

    /dev/foo / xfs rw,qnoenforce 0 0
    

    To turn on disk usage accounting automatically on a filesystem for group quotas, include the option gqnoenforce in the /etc/fstab entry, for example:

    /dev/foo / xfs rw,
    
    gqnoenforce 0 0
    

  • To turn on disk usage accounting manually for user quotas on a non-root filesystem, when mounting the filesystem, use this mount command:

    # mount -o 
    qnoenforce fsname rootdir 
    

    fsname is the device name of the filesystem. rootdir is the directory where the filesystem is mounted.

    To turn on disk usage accounting manually on a non-root filesystem for group quotas when mounting the filesystem, use this mount command:

    # mount -o 
    gqnoenforce fsname rootdir 
    

  • To turn on disk usage accounting manually on the root filesystem for user quotas, execute the following commands. The quotaon command turns on disk accounting with enforcement, and the quotaoff -o command turns off the enforcement.

    # 
    
    quotaon -v / 
    # quotaoff -v -o enforce / 
    # reboot 
    

    To turn on disk usage accounting manually on the root filesystem for group quotas, give these commands:

    # quotaon -v -o gquota / 
    # quotaoff -v -o gqenforce / 
    # reboot 
    

  • To stop disk usage accounting on a filesystem for user quotas, give this command:

    # quotaoff fsname 
    

    To stop disk usage accounting on a filesystem for group quotas, give this command:# quotaoff -o gquota fsname 

  • To get information about disk usage, use the commands described in “Checking Disk Space Usage on XFS Filesystems With quota ”.

Checking Disk Space Usage on XFS Filesystems With quota

The quota command reports the amount of disk usage per user, per group, or per project on a filesystem, as well as additional information about the disk quotas. On XFS filesystems, you must turn on quotas to use this feature, even if you are not going to enforce quota limits. For instructions on monitoring disk space usage without enforcing disk usage limits see “Monitoring Disk Space Usage with Disk Quota Accounting”.

For information on the output of the quota command, see “Displaying Disk Quota Information on XFS Filesystems”.