Learn Linux, 101

Manage disk quotas

Sharing your disk space


Content series:

This content is part # of # in the series: Learn Linux, 101

Stay tuned for additional content in this series.

This content is part of the series:Learn Linux, 101

Stay tuned for additional content in this series.


In this tutorial, learn to manage disk quotas for users. Learn to:

  • Set up a disk quota for a filesystem
  • Set quota limits
  • Check quotas
  • Generate quota reports

This tutorial helps you prepare for Objective 104.4 in Topic 104 of the Linux Server Professional (LPIC-1) exam 101. The objective has a weight of 1.

Sharing your disk space

Quotas allow you to control disk usage by user or by group. Quotas prevent individual users and groups from using a larger portion of a filesystem than they are permitted, or from filling it up altogether. XFS filesystems also support project quotas, which limit the amount of space used by a project, regardless of which users create files in the project's directory tree.

Quotas must be enabled and managed by the root user or by a user with root authority. They are often used on multiuser systems, but less often on single-user workstations.

This tutorial covers version 2 quota on non-XFS filesystems and xfs quota on XFS filesystems. Note that the LPI 101 exam focuses on version 2 quotas.


To get the most from the tutorials in this series, you should have a basic knowledge of Linux and a working Linux system to practice the commands covered in this tutorial. Unless otherwise noted, the examples in this tutorial use CentOS 6 with a 2.6.32-504 kernel. Sometimes different versions of a program will format output differently, so your results may not always look exactly like the listings and figures shown here.

You should also be familiar with the material in our tutorial "Learn Linux 101: Create partitions and filesystems."

Our test setup

So that you can better understand some of the examples, we will first describe the test partition setup we are using for this tutorial. If you already understand file ownership and permissions, and you have the quota package already installed, you may skip to the Enabling quotas section. Refer to our developerWorks roadmap for LPIC-1 for links to other tutorials in this series that provide more detail about these commands than the brief explanations provided here.

Test partitions and users

We use a 110GB ext4 partition (/dev/sdc6) and a 40GB XFS partition (/dev/sdc3) for demonstration purposes. These are mounted at /quotatest/ext4 and /quotatest/xfs, respectively.

Listing 1. Setting up the partitions
[root@attic4-cent ~]# mkfs -t ext4 /dev/sdc6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=0 blocks
7045120 inodes, 28160000 blocks
1408000 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
860 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@attic4-cent ~]# mkfs -t xfs -i size=512 /dev/sdc3
mkfs.xfs: /dev/sdc3 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@attic4-cent ~]# mkfs -t xfs -f -i size=512 /dev/sdc3
meta-data=/dev/sdc3              isize=512    agcount=16, agsize=655360 blks
         =                       sectsz=4096  attr=2, projid32bit=0
data     =                       bsize=4096   blocks=10485760, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@attic4-cent ~]# mkdir -p /quotatest/ext4
[root@attic4-cent ~]# mkdir -p /quotatest/xfs
[root@attic4-cent ~]# mount /dev/sdc6 /quotatest/ext4
[root@attic4-cent ~]# mount /dev/sdc3 /quotatest/xfs

For this example, we want regular users to be able to create files in the new filesystems. As created, the filesystems are owned by root, and normal users cannot create files or directories on them. We will change the ownership so that the new filesystems are owned by user development who has a private group also called development. We will also change the permissions so that users in the development group can create files and directories. Listing 2 shows how we set up the ownership and permissions.

Listing 2. Changing ownership and permissions for our test partitions
[root@attic4-cent ~]# # Show default ownership and permissions
[root@attic4-cent ~]# ls -l /quotatest/
total 4
drwxr-xr-x. 3 root root 4096 Aug  7 15:51 ext4
drwxr-xr-x. 2 root root    6 Aug  7 15:56 xfs
[root@attic4-cent ~]# # Change user and group ownership to development
[root@attic4-cent ~]# chown development:development /quotatest/*
[root@attic4-cent ~]# # Allow group members to create files and directories
[root@attic4-cent ~]# chmod g+w /quotatest/*
[root@attic4-cent ~]# ls -l /quotatest/
total 4
drwxrwxr-x. 3 development development 4096 Aug  7 15:51 ext4
drwxrwxr-x. 2 development development    6 Aug  7 15:56 xfs
[root@attic4-cent ~]# # Set default group of new files and directories
[root@attic4-cent ~]# # to development
[root@attic4-cent ~]# chmod g+s /quotatest/ext4/
[root@attic4-cent ~]# ls -l /quotatest/
total 4
drwxrwsr-x. 3 development development 4096 Aug  7 15:51 ext4
drwxrwxr-x. 2 development development    6 Aug  7 15:56 xfs

Finally, if you are using SELinux (Security Enhanced Linux) in enforcing mode, the security contexts may need updating. Run fixfiles check to see if you need to update the contexts and run fixfiles relabel to relabel the /quotatest tree as shown in Listing 3. See the man pages for other ways to relabel, including relabeling your entire filesystem at the next boot.

Listing 3. Check and fix SELinux contexts
[root@attic4-cent ~]# # Check whether SELinux contexts need updating
[root@attic4-cent ~]# fixfiles check /quotatest
/sbin/restorecon reset /quotatest context unconfined_u:object_r:default_t:s0->
/sbin/restorecon reset /quotatest/ext4 context system_u:object_r:file_t:s0->
/sbin/restorecon reset /quotatest/ext4/lost+found context system_u:object_r:file_t:s0->
/sbin/restorecon reset /quotatest/xfs context system_u:object_r:file_t:s0->
[root@attic4-cent ~]# # Update SELinux contexts
[root@attic4-cent ~]# fixfiles relabel /quotatest

    Files in the /tmp directory may be labeled incorrectly, this command 
    can remove all files in /tmp.  If you choose to remove files from /tmp, 
    a reboot will be required after completion.
    Do you wish to clean out the /tmp directory [N]? n

We also make use of three users—ian, mary, and jenni—each having a private group with the same name as the user name. Each of these users is also a member of the development group.

Checking for the quota package

If you are using a desktop system, you may not have the quota package installed since quotas are not part of the usual default desktop install. Use dpkg or rpm to check that you have the package installed as shown in Listing 4.

Listing 4. Checking for quota packages
ian@ubuntu:~$ # Ubuntu 15.04
ian@ubuntu:~$ dpkg -l quota
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
un  quota          <none>       <none>       (no description available)

[root@attic4-cent ~]# # CentOS 6
[root@attic4-cent ~]# rpm -q quota
[root@attic4-cent ~]# yum list installed quota
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
Installed Packages
quota.x86_64      1:3.17-21.el6_5       @anaconda-CentOS-201410241409.x86_64/6.6

Our Ubuntu 15.04 example does not have the quota package installed, while the CentOS 6 system does.

If you do not have the quota package installed already see our tutorials, "Learn Linux 101: Use Debian package management." and Learn Linux 101: Use RPM and YUM package management for help on installing packages.

Enabling quotas

There are three different types of quota support:

  1. Version 1 quota format used up to kernel 2.2
  2. Version 2 quota format used on 2.4 and later kernels.
  3. xfs, the quota on XFS filesystems

Quotas require kernel support that was introduced in later 2.4 kernels. 2.6 kernels have the support you need.

XFS quotas are always journaled. Journaled version 2 quotas are supported on kernel 2.6.11 and above.

Version 1 quota support is sometimes referred to as vfsold, while Version 2 quota support is sometimes referred to as vfsv0 (32-bit UIDs / GIDs, 64-bit space usage, 32-bit inode usage and limits) or vfsv1 (64-bit quota limits and usage).

Adding quota support to /etc/fstab

The next step to enable quotas is to add the appropriate options to the filesystem definitions in /etc/fstab, according to whether you want to implement user quotas, group quotas, or both. XFS filesystems also support project quotas.

At the time of writing, the options for enabling quotas are not centrally documented in an obvious man page. Table 1 shows the options that are available and the type of quota system they are used for.

Table 1. Quota options in /etc/fstab
OptionApplies toUse
usrquotaAll typesEnable user quotas
usrjquota=filenamevfsv0, vfsv1 (Version 2)Enable journaled user quotas; requires a quota database file name (usually aquota.user) and specification of jqfmt option
uquotaxfsEquivalent to usrquota
grpquotaAll typesEnable group quotas
grpjquota=filenamevfsv0, vfsv1 (Version 2)Enable journaled group quotas; requires a quota database file name (usually and specification of jqfmt option
gquotaxfsEquivalent to grpquota
prjquotaxfsEnable project quotas
pquotaxfsEquivalent to prjquota
jqfmt=formatvfsv0, vfsv1 (Version 2)Format of quota used when either usrjquota or grpjquota is specified; currently vfsv0, vfsv1 (Version 2) is the only supported format
quotavfsold (Version 1), vfsv0, vfsv1 (Version 2)Equivalent to usrquota
noquotavfsold (Version 1), vfsv0, vfsv1 (Version 2)Do not enable quotas
uqnoenforcexfsEnable user quota accounting, but disable enforcement
gqnoenforcexfsEnable group quota accounting, but disable enforcement
pqnoenforcexfsEnable project quota accounting, but disable enforcement

We use an ext4 partition and an XFS partition for demonstration purposes. We'll add user and group quota to these filesystems so you can see how quotas work on two different filesystems. Our /etc/fstab entries are shown in Listing 5.

Listing 5. Enabling quota support in /etc/fstab
/dev/sdc6  /quotatest/ext4  ext4    defaults,usrquota,grpquota          1 2
/dev/sdc3  /quotatest/xfs   xfs     defaults,usrquota,grpquota          1 2

Remount the filesystem

After you edit /etc/fstab and add quotas, you need to remount the filesystems. For XFS filesystems, quota data is considered part of the filesystem metadata. For other filesystems, user quota information is stored in the aquota.user file in the root of the filesystem, and group quota is similarly stored in Version 1 quotas used quota.user and For these filesystems, after you remount the filesystem, you must create the quota files and enable quota checking. The quotacheck command checks the quotas on all filesystems and creates the required aquota.user and files if they do not exist. It can also repair damaged quota files. See the man pages for more information.

The following are some of the common options used with the quotacheck command:

-a or --all
Check all mounted filesystems in /etc/mtab (except NFS filesystems)
-c or --create-files
Ignore existing quota files. Run a new scan and write the results to disk
-u or --user
Check user quotas (this is the default)
-g or --group
Check group quotas
-v or --verbose
Verbose output

Listing 6 shows the result of unmounting the filesystems and then remounting them using the definitions from /etc/fstab, then running the quotacheck command on our freshly remounted filesystems. If you do not use the -a option, you must specify the filesystem that you want to check.

Listing 6. Creating quota database files for vfsold (Version 1) and vfsv0 or vfsv1 (Version 2)
[root@attic4-cent ~]# umount /quotatest/*
[root@attic4-cent ~]# mount /quotatest/ext4
[root@attic4-cent ~]# mount /quotatest/xfs
[root@attic4-cent ~]# quotacheck -augvc
quotacheck: Your kernel probably supports journaled quota but you are not using it. 
Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdc6 [/quotatest/ext4] done
quotacheck: Cannot stat old group quota file /quotatest/ext4/ No such file 
or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /quotatest/ext4/ No such file 
or directory. Usage will not be subtracted.
quotacheck: Checked 2 directories and 1 files
quotacheck: Old file not found.
quotacheck: Skipping /dev/sdc3 [/quotatest/xfs]
[root@attic4-cent ~]# # find the created quota ext4 files
[root@attic4-cent ~]# find /quotatest

If your output includes messages like:

quotacheck: Cannot create new quotafile /quotatest/ext4/ Permission denied

then you probably did not update your SELinux contexts. Go back and check Listing 3.

Notice the warning from the quotacheck command suggesting that we switch to using journaled quotas. Do this by changing the options in /etc/fstab for the ext4 filesystem on /dev/sdc6 from

After you update /etc/fstab, you will need to remount your filesystems again.

Notice also that the XFS filesystem was skipped by the quotacheck command because the XFS quota structures are contained in the meta-data and journaled.

Start or stop quota checking

To enforce vfsold and vfsv0 quota checking, you must turn it on using the quotaon command. The common options -a, -g, -u, and -v have the same meaning as for the quotacheck command. Similarly, if you do not specify the -a option, you must specify a filesystem. Use the -p option if you just want to display whether quotas are on or off. Use the quotaoff command to turn off quota checking. Listing 7 shows examples of both these commands.

Listing 7. Turning on quota checking for vfsold and vfsv0 quotas
[root@attic4-cent ~]# quotaon -p /quotatest/ext4/
group quota on /quotatest/ext4 (/dev/sdc6) is off
user quota on /quotatest/ext4 (/dev/sdc6) is off
[root@attic4-cent ~]# quotaon -uagv
/dev/sdc6 [/quotatest/ext4]: group quotas turned on
/dev/sdc6 [/quotatest/ext4]: user quotas turned on
[root@attic4-cent ~]# quotaoff -ugv /quotatest/ext4/
/dev/sdc6 [/quotatest/ext4]: group quotas turned off
/dev/sdc6 [/quotatest/ext4]: user quotas turned off
[root@attic4-cent ~]# quotaon -ugv /quotatest/ext4/
/dev/sdc6 [/quotatest/ext4]: group quotas turned on
/dev/sdc6 [/quotatest/ext4]: user quotas turned on

For XFS filesystems, quota checking is turned on by default, unless the file is mounted with the uqnoenforce, gqnoenforce, or pqnoenforce options. Use the xfs_quota command with the -x (for expert) option to manipulate xfs quotas. Without the -x option you are limited to displaying quota information. The command has several subcommands, including help to display a list of available subcommands, state to display overall state, enable to enable quota checking, and disable to disable it. The options -u, -g, and -p limit the action to users, groups, or projects, respectively. Use -v for verbose output. You can also run the command in command-line mode where the individual subcommand is specified with the -c option. You may specify this option multiple times for multiple subcommands. If you are specifying options for your subcommand, you will probably need to quote your command. Some examples are shown in Listing 8.

Listing 8. Turning on quota checking for xfs quotas
[root@attic4-cent ~]# xfs_quota -x
xfs_quota> state
User quota state on /quotatest/xfs (/dev/sdc3)
  Accounting: ON
  Enforcement: ON
  Inode: #99 (2 blocks, 2 extents)
Group quota state on /quotatest/xfs (/dev/sdc3)
  Accounting: ON
  Enforcement: ON
  Inode: #100 (2 blocks, 2 extents)
Project quota state on /quotatest/xfs (/dev/sdc3)
  Accounting: OFF
  Enforcement: OFF
  Inode: #100 (2 blocks, 2 extents)
Blocks grace time: [7 days 00:00:30]
Inodes grace time: [7 days 00:00:30]
Realtime Blocks grace time: [7 days 00:00:30]
xfs_quota> disable
xfs_quota> quit
[root@attic4-cent ~]# xfs_quota -x  -c "enable -gu -v"  /quotatest/xfs
User quota state on /quotatest/xfs (/dev/sdc3)
  Accounting: ON
  Enforcement: ON
  Inode: #99 (2 blocks, 2 extents)
Group quota state on /quotatest/xfs (/dev/sdc3)
  Accounting: ON
  Enforcement: ON
  Inode: #100 (2 blocks, 2 extents)
Blocks grace time: [7 days 00:00:30]
Inodes grace time: [7 days 00:00:30]
Realtime Blocks grace time: [7 days 00:00:30]

Checking version 1 and 2 quotas at boot time

Although beyond the scope of this tutorial, the quotacheck and quotaon commands are usually included in initialization scripts so that quotas are enabled whenever you reboot the system. The Quota Mini HOWTO has additional information. If you are using journaled quotas, you should not need to run quotacheck at boot time.

Setting quota limits

As you have seen, quotas are controlled either through binary files in the root of the filesystem or through filesystem metadata. To set a quota for a particular user, use the edquota command. This command extracts the quota information for the user from the various filesystems with quotas enabled, creates a temporary file, and opens an editor for you to adjust the quotas. By default, edquota uses the vi editor. Set the EDITOR or the VISUAL environment variables if you want to use a different editor. To edit user quotas, use the -u option (default) with one or more user names. To edit group quotas, use the -g with one or more group names.

You must be root to edit quotas. Using vi as the editor, the information displayed will look something like Listing 9.

Listing 9. Running edquota -u ian
Disk quotas for user ian (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdc6                         0          0          0          0        0        0
  /dev/sdc3                         0          0          0          0        0        0

As you can see in Listing 9, edquota displays my current usage of both 1K blocks and inodes on each of the filesystems that have quota turned on. There are also soft and hard limits for both block and inode usage. In this example, these are 0, meaning no quota limit is enforced.

The soft limit is the value at which a user will receive email warnings about being over quota. The hard limit is the value that a user may not exceed. You can think of block limits as an approximate limit on the amount of data that a user may store, and inode limits as a limit on the number of files and directories.

Changing quota limits

You change the quota limits by changing the values in the temporary file and then saving the file. If you do not want to make changes, quit the file without saving. We will use some very small limits in our examples, so you can easily see the effects. Suppose you want to set my quota to 10MB of data and 50 files on each of our test filesystems. Allowing 10% additional for hard limits, you would set values as shown in Listing 10.

Listing 10. Setting limits
Disk quotas for user ian (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdc6                         0      11264          0          0       50       55
  /dev/sdc3                         0      11264          0          0       50       55

Save the file, and the new quotas will take effect. Note that any changes you make to the used blocks or inodes values will be ignored.

Copying quotas

Now suppose you are creating IDs for additional developers. Assume you have users mary and jenni, and you'd like them both to have the same quota as ian. You do this using the -p option of edquota, which uses the quota values of ian as a prototype for those of the other users as shown in Listing 11.

Listing 11. Setting quotas from a prototype
[root@attic4-cent ~]# edquota -p ian mary jenni

Group limits

You can also use edquota to restrict the allocation of disk space based on the group ownership of files. For example, the three developers above are members of the development group. To limit the total amounts used by the all members of the group to 250MB and 100 files, use the command edquota -g development and set the values as shown in Listing 12.

Listing 12. Setting quotas for a group
Disk quotas for group development (gid 1002):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdc6                         4      25600      28160          1      100      110
  /dev/sdc3                         0      25600      28160          1      100      110

You may wonder why there are already some blocks and inodes used on /dev/sdc6, our ext4 filesystem. Remember back in Listing 2 we used chown and chmod to set the default group for all new files to be the development group? That also applies to the two quota database files. You can change these back to being in root's group as shown in Listing 13. Be sure to turn off quota checking to make the change and then turn it back on again.

Listing 13. Resetting group owner for quota database files
[root@attic4-cent ~]# quotaoff /quotatest/ext4/
[root@attic4-cent ~]# chown :root /quotatest/ext4/aquota.*
[root@attic4-cent ~]# quotaon /quotatest/ext4

The grace period

Users or groups may exceed their soft limit for a grace period, which defaults to seven days. After the grace period, the soft limit is enforced as a hard limit. Once the hard limit is reached, some files must be deleted before new files can be created. Set grace periods using edquota -t. Again, you will be placed in an editor with data similar to that of Listing 14. As before, save changes to update the values. Be sure to leave your users enough time to receive their warning email and delete some files accordingly.

Listing 14. Setting grace periods
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/sdc6                     7days                  7days
  /dev/sdc3                     7days                  7days

Checking quotas

The quota command with no options displays the quotas for the invoking user on any filesystems for which the user has quotas set if the user has files on that system. The -v option displays the information for all filesystems that have quota enabled. The root user may also add a user name to the command to view quotas for a particular user. In Listing 15, we create a 1MB file on our ext4 filesystem and show the use of the quota command with and without the -v option.

Listing 15. Displaying quotas
[ian@attic4-cent ~]$ dd if=/dev/zero of=/quotatest/ext4/ianfile1 bs=1024 count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00736743 s, 142 MB/s
[ian@attic4-cent ~]$ quota
Disk quotas for user ian (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdc6    1024   11264       0               1      50      55        
[ian@attic4-cent ~]$ quota -v
Disk quotas for user ian (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdc6    1024   11264       0               1      50      55        
      /dev/sdc3       0   11264       0               0      50      55

Along with the statistics on current usage, you see the soft and hard quota limits displayed. If you run the quota command immediately after creating the file, you may see a slightly larger block count displayed for a short time.

Listing 16 shows what happens if you exceed the soft limit and then what happens if you attempt to exceed the hard limit. In this example, we add a 9.5MB file to the 1MB we already created, which is sufficient to exceed the soft limit. Notice how the soft limit has an asterisk beside it indicating that the user is over quota. Note also that the grace period columns now indicate how long the user has to correct the problem. Finally, when we try to make a copy of the 1MB file, the operation fails because this would exceed the hard limit for user ian.

Listing 16. Exceeding block quotas
[ian@attic4-cent ~]$ dd if=/dev/zero of=/quotatest/ext4/ianfile2 bs=1024 count=9500
9500+0 records in
9500+0 records out
9728000 bytes (9.7 MB) copied, 0.0503342 s, 193 MB/s
[ian@attic4-cent ~]$ quota
Disk quotas for user ian (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdc6   10524   11264       0               2      50      55        
[ian@attic4-cent ~]$ cp /quotatest/ext4/ianfile1 /quotatest/ext4/ianfile3
sdc6: warning, user block quota exceeded.
[ian@attic4-cent ~]$ quota
Disk quotas for user ian (uid 1000): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdc6   11548*  11264       0   6days       3      50      55

To illustrate what happens if you exceed the inode (file) quote, we'll switch to user jenni, and create 52 empty files in /quotatest/ext4. Listing 17 shows the results.

Listing 17. Exceeding Jenni's file quota
[jenni@attic4-cent ~]$ for n in $(seq 1 52); do touch /quotatest/ext4/jenni$n;done
sdc6: warning, user file quota exceeded.
[jenni@attic4-cent ~]$ quota
Disk quotas for user jenni (uid 1004): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdc6       0   11264       0              52*     50      55   7days

Quota reports

Checking user quotas one user at a time is not very useful, so you will want to use the repquota command to generate quota reports. Listing 18 shows how to see the quotas for all users and groups on /quotatest/ext4/.

Listing 18. Generating quota reports
[root@attic4-cent ~]# repquota -ug /quotatest/ext4
*** Report for user quotas on device /dev/sdc6
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
root      --      16       0       0              1     0     0       
ian       +-   11548   11264       0  6days      22    50    55       
development --       4       0       0              1     0     0       
jenni     -+       0   11264       0             52    50    55  6days
mary      --    1024   11264       0             35    50    55       

*** Report for group quotas on device /dev/sdc6
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
root      --      16       0       0              1     0     0       
development -+   12576   25600   28160            110   100   110  7days

Note the plus sign in Listing 18 for users ian and jenni and for group development indicating that each is now over quota. User ian has too much data. User jenni has too many files. And group development also has too many files.

As with other quota commands, the -a option produces a report for all mounted filesystems that have quota enabled. The -v option produces more verbose output. And the -n option produces the listing by numeric user number rather than resolving the user number to a name. This may provide a performance boost for large reports, but is generally less useful to human readers.

Project quotas on XFS filesystems

The xfs quota system also supports project quotas, which are an alternative to group quotas. You cannot use both group and project quotas on one XFS filesystem. Project quotas must be enabled by adding the prjquota (or pquota) to /etc/fstab.

Project quotas use the notion of a numeric id and a more descriptive project name. The file /etc/projects is used to map the numeric project identifiers to directory trees, while the file /etc/projid maps the numeric project identifiers to project names. It is possible, but less convenient, to operate without these two files in /etc. See the man pages for details.

To set project quotas, you must use the xfs_quota command in expert mode (-x option). First you must use the project subcommand with the -s option to set up the project quotas by marking all the affected inodes as part of the project. You then use the limit subcommand to set hard or soft limits. Listing 19 shows how to set up a project tree under /quotatest/xfs/proj-dir1, with a 15MB project hard limit. We will also set up a parallel /quotatest/xfs/proj-dir2 with no limits for illustration.

Listing 19. Setting up an xfs project quota.
[root@attic4-cent ~]# mkdir -m ag+w /quotatest/xfs/proj-dir{1,2}
[root@attic4-cent ~]# chown development:development /quotatest/xfs/proj-dir*
[root@attic4-cent ~]# echo "50:/quotatest/xfs/proj-dir1" >> /etc/projects
[root@attic4-cent ~]# echo "dev-projects:50" >> /etc/projid
[root@attic4-cent ~]# xfs_quota -x
xfs_quota> path
      Filesystem          Pathname
 000  /quotatest/xfs      /dev/sdc3 (uquota, gquota)
[001] /quotatest/xfs/proj-dir1 /dev/sdc3 (project 50, dev-projects)
xfs_quota> project -s dev-projects
Setting up project dev-projects (path /quotatest/xfs/proj-dir1)...
Processed 1 (/etc/projects and cmdline) paths for project dev-projects with 
recursion depth infinite (-1).
xfs_quota> limit -p bhard=15m dev-projects
xfs_quota> q

We'll illustrate the project quota in action by having user chris create some files. User chris is not a member of the development group and does not have any quotas set for either his id or group. Listing 20 shows that chris cannot create more than 15MB of data in /quotatest/xfs/proj-dir1, but is not limited in /quotatest/xfs/proj-dir2.

Listing 20. Project quotas in action
[chris@attic4-cent ~]$ id chris
uid=1006(chris) gid=1006(chris) groups=1006(chris)
[chris@attic4-cent ~]$ cd /quotatest/xfs/
[chris@attic4-cent xfs]$ dir
proj-dir1  proj-dir2
[chris@attic4-cent xfs]$ dd if=/dev/zero of=proj-dir1/chris1 bs=1024 count=10000
10000+0 records in
10000+0 records out
10240000 bytes (10 MB) copied, 0.0386164 s, 265 MB/s
[chris@attic4-cent xfs]$ cp proj-dir1/chris1 proj-dir1/chris2
cp: writing `proj-dir1/chris2': No space left on device
[chris@attic4-cent xfs]$ ls -l proj-dir1
total 15356
-rw-rw-r--. 1 chris chris 10240000 Aug  8 18:01 chris1
-rw-rw-r--. 1 chris chris  5484544 Aug  8 18:01 chris2
[chris@attic4-cent xfs]$ # Note: second copy was truncated at hard limit
[chris@attic4-cent xfs]$ cp proj-dir1/chris1 proj-dir2/chris1
[chris@attic4-cent xfs]$ cp proj-dir1/chris1 proj-dir2/chris2
[chris@attic4-cent xfs]$ cp proj-dir1/chris1 proj-dir2/chris3
[chris@attic4-cent xfs]$ du -sh *
15M	proj-dir1
30M	proj-dir2
[chris@attic4-cent xfs]$ du -sh $(find /quotatest/xfs/proj-dir1 -user chris)
9.8M	/quotatest/xfs/proj-dir1/chris1
5.3M	/quotatest/xfs/proj-dir1/chris2
[chris@attic4-cent xfs]$ du -sh $(find /quotatest/xfs/proj-dir2 -user chris)
9.8M	/quotatest/xfs/proj-dir2/chris1
9.8M	/quotatest/xfs/proj-dir2/chris2
9.8M	/quotatest/xfs/proj-dir2/chris3

Warning users

The warnquota command is used to send email warnings to users who are over quota. When a group is over quota, the email is sent to the user specified in /etc/quotagrpadmins for the group. The format of the email is controlled by the file /etc/warnquota.conf. The file /etc/quotatab is used to map names such as /dev/sdc6 to more user-friendly descriptions such as "Shared EXT3 filesystem." Normally warnquota is run periodically as a cron job. See the man pages for cron and warnquota for more information.

This completes your introduction to quotas on Linux.

Downloadable resources

Related topics


Sign in or register to add and subscribe to comments.

ArticleTitle=Learn Linux, 101: Manage disk quotas