centos 7 xfs enable quota. centos 7 quota xfs. how to configure xfs quota in rhel/centos 7 and 8. user quota in linux step by step. change grace period of xfs quota. modify grace period of xfs quota. set quota on folder in rhel/centos 8. xfs quotacheck. mount xfs pquota. rhel xfs quota. xfs project quota. xfs userquota. xfs groupquota. enable xfs quota. disable xfs quota with examples in CentOS 7.
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. In this article I will share the steps to configure xfs user quota, xfs group guota and xfs project quota which you can also refer as xfs disk quota as the quota is applied on directory level. The steps and commands to implement xfs quota is different compared to ext4 filesystem quota.
Lab Environment
I am using Oracle VirtualBox to create a Virtual Machine with CentOS 8 where I will execute all the commands to configure xfs quota. For this purpose I added an additional disk /dev/sdb
and created it as a XFS filesystem.
Enable XFS Quota
Mount the filesystem /dev/sdb1
with the mount option uquota
, gquota
and pquota
to enable xfs user quota, xfs group quota and xfs project quota (xfs disk quota)
/
(root) partition then you must update your /etc/fstab
and reboot the node to enable xfs quota.For example I have enabled xfs quota for /dev/sdb1
# grep quota /etc/fstab
/dev/sdb1 /xquota xfs defaults,uquota,gquota,prjquota 0 0" /etc/fstab
If you have a data partition similar to my setup which you can unmount it without rebooting the node
[root@centos-8 ~]# umount /xquota
Next mount it with xfs quota directives
[root@centos-8 ~]# mount -o uquota,gquota,pquota /dev/sdb1 /xquota
Verify if xfs quota is enabled for /dev/sdb1
:
[root@centos-8 ~]# mount | grep quota /dev/sdb1 on /xquota type xfs (rw,relatime,attr2,inode64,usrquota,prjquota,grpquota)
Configure xfs user quota and xfs group quota in RHEL/CentOS 7/8
The primary purpose of xfs user quota and xfs qroup quota is to track and monitor block and inode usage for filesystem. XFS filesystem does help to manage the storage on the basis of users and group. This enables to have a quota set for a single user or for a group.
Here I will share the steps to enable both xfs user quota and xfs group quota using the same command in CentOS/RHEL 7/8.
Apply xfs user quota limit for blocks
First we will configure and apply xfs user quota on /xquota
device for user 'deepak'. Here I am setting soft limit of 1GB and hard limit of 1.5GB. With xfs quota you cannot use decimal value hence my soft limit is in GB while hard limit is in MB as I cannot use 1.5GB value here.
[root@centos-8 ~]# xfs_quota -x -c 'limit bsoft=1g bhard=1536m deepak' /xquota
- quota block limits (bhard/bsoft)
- inode count limits (ihard/isoft)
- realtime block limits (rtbhard/rtbsoft)
Here,
-x Enable expert mode. All of the administrative commands (see the ADMINISTRATOR COMMANDS section below) which allow modifications to the quota system are available only in expert mode. -c xfs_quota commands may be run interactively (the default) or as arguments on the command line. Multiple -c arguments may be given. The commands are run in the sequence given, then the program exits.
To check the status of xfs quota you can use "report
" with xfs_quota
command:
[root@centos-8 ~]# xfs_quota -x -c report /xquota/ User quota on /xquota (/dev/sdb1) Blocks User ID Used Soft Hard Warn/Grace ---------- -------------------------------------------------- root 0 0 0 00 [--------] deepak 0 1048576 1572864 00 [--------]
Currently as we see none of the blocks are used by user deepak, along with the soft and hard limit for xfs user quota.
Verify xfs user quota for user deepak
I will give full permission for other users for /xquota
so I can allow user deepak to write inside this path.
[root@centos-8 ~]# chmod o+rwx /xquota/
We will use fallocate
to create a dummy file with 1.2GB size. As our xfs user quota hard limit is 1.5GB so this should succeed.
[deepak@centos-8 ~]$ fallocate -l 1.2G /xquota/test_file_1.2G
Verify the xfs user quota status for /xquota
again
[root@centos-8 ~]# xfs_quota -x -c report /xquota/ User quota on /xquota (/dev/sdb1) Blocks User ID Used Soft Hard Warn/Grace ---------- -------------------------------------------------- root 0 0 0 00 [--------] deepak 1253376 1048576 1572864 00 [7 days]
Next we will try to create another 1GB file but we know that we only have 300MB left as per our xfs user quota hard limit, this should fail
[deepak@centos-8 ~]$ fallocate -l 1G /xquota/test_file_1.2G
fallocate: fallocate failed: Disk quota exceeded
As expected we get "disk quota exceeded
" error once we reach xfs user quota limit
Modify xfs user quota limit
If any point you feel you need to modify the xfs user quota limit then you can re-run the same command as used to set the xfs quota, BUT with the new limit value. For example I have added a soft limit of 1G and hard limit of 1.5G, which I wish to change to 900M as soft block limit and 1G as hard block limit
[root@centos-8 ~]# xfs_quota -x -c 'limit bsoft=900M bhard=1000M deepak' /xquota
Verify the new xfs quota limit
[root@centos-8 ~]# xfs_quota -x -c "report -h" /xquota/
User quota on /xquota (/dev/sdb1)
Blocks
User ID Used Soft Hard Warn/Grace
---------- ---------------------------------
root 300M 0 0 00 [------]
deepak 0 900M 1000M 00 [------]
Apply xfs user quota limit for inodes
Similar to block limit, you can also add xfs quota limit for inode using isoft
and ihard
as shown below. Here I have added a soft inode limit for user deepak as 500 and hard limit of 700
[root@centos-8 ~]# xfs_quota -x -c 'limit isoft=500 ihard=700 deepak' /xquota
Check the xfs quota limit for user deepak
[root@centos-8 ~]# xfs_quota -x -c "report -bih" /xquota/ User quota on /xquota (/dev/sdb1) Blocks Inodes User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- root 300M 0 0 00 [------] 5 0 0 00 [------] deepak 0 900M 1000M 00 [------] 0 500 700 00 [------]
xfs_quota -x -c 'limit -g bsoft=500M bhard=700M quotagroup' /quotacheck
to configure xfs group quota limit. Here quotagroup is the group for which I am implementing xfs group quota with soft block limit of 500M and hard limit of 700M.
Configure xfs user quota and group quota in the same command
Use -u
to define xfs quota for user and use -g
to define xfs quota for group. Use the below syntax to configure xfs quota for user and group in a single command.
# xfs_quota -x -c 'limit -u bsoft= bhard= user '-c' limit -g bsoft= bhard= group'
For example, here I have added a soft block limit of 500M and hard limit of 800M for user deepak, and in the same command I have added soft block limit of 600M and hard limit of 900M for group admin
[root@centos-8 ~]# xfs_quota -x -c 'limit -u bsoft=500M bhard=800M deepak' -c 'limit -g bsoft=600M bhard=900M admin' /xquota/
Print and check the xfs quota report for user and group on /xquota directory
[root@centos-8 ~]# xfs_quota -x -c "report -bih" /xquota/ User quota on /xquota (/dev/sdb1) Blocks Inodes User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- root 300M 0 0 00 [------] 5 0 0 00 [------] deepak 0 500M 800M 00 [------] 0 500 700 00 [------] Group quota on /xquota (/dev/sdb1) Blocks Inodes Group ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- root 300M 0 0 00 [------] 5 0 0 00 [------] admin 0 600M 900M 00 [------] 0 0 0 00 [------]
Configure xfs project quota (or xfs disk quota) in RHEL/CentOS 7/8
Project quota's primary purpose is to track and monitor disk usage for directories.When managing on a per-directory or per-project basis, XFS manages the disk usage of directory hierarchies associated with a specific project. In doing so, XFS recognises cross-organizational "group" boundaries between projects. This provides a level of control that is broader than what is available when managing quotas for users or groups.
In order to enable xfs disk quotas for a single directory instead of user or xfs group quotas, we have to add the xfs project quota directive called pquota to the volume containing the directory. xfs project quota is used to add and configure xfs quota for directory. xfs disk quota is basically xfs project quota.
At the beginning of this article I had shared the steps to enable xfs project quota, so I will skip that part here
Create xfs project quota related files
Before configuring limits for project-controlled directories, add them first to /etc/projects
. We need to add a project name and an associated new, unique ID /etc/projectid
to map project IDs to project names in the format "project name:project ID
"
[root@centos-8 ~]# echo testquota:11 >> /etc/projid
Here "testquota" is my project name while 11 is the project ID which can be any numerical value mapped to your project.
Next add the directories project-controlled to /etc/projects
in the format "project ID : projected-controlled directory
"
[root@centos-8 ~]# echo 11:/xquota >> /etc/projects
Initialize project directory
Once a project is added to /etc/projects
, initialize its project directory using the following syntax:
# xfs_quota -x -c 'project -s projectname' project_path
To initialize our testquota
project directory
[root@centos-8 ~]# xfs_quota -x -c 'project -s testquota' Setting up project testquota (path /xquota)... Processed 1 (/etc/projects and cmdline) paths for project testquota with recursion depth infinite (-1).
We can use the below command to check the project we set:
[root@centos-8 ~]# xfs_quota -x -c "print" /xquota/ Filesystem Pathname /xquota /dev/sdb1 (pquota) /xquota /dev/sdb1 (project 11, testquota)
Print out our xfs quota rules for this device, currently since xfs project quota is not set we see null values for soft and hard limit.
[root@centos-8 ~]# xfs_quota -x -c "report -pbih" /xquota/
Project quota on /xquota (/dev/sdb1)
Blocks Inodes
Project ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace
---------- --------------------------------- ---------------------------------
#0 0 0 0 00 [------] 2 0 0 00 [------]
testquota 0 0 0 00 [------] 1 0 0 00 [------]
Here,
-p project quota -b blocks used -i inodes used -h report in human-readable format
Apply xfs project quota limit
XFS Quotas for projects with initialized directories can then be configured, with:
[root@centos-8 ~]# xfs_quota -x -c 'limit -p bsoft=200m bhard=300m testquota' /xquota/
Print the xfs disk quota report (pquota
). Now as you see we have a defined soft and hard block limit for xfs quota
[root@centos-8 ~]# xfs_quota -x -c 'report -pbih' /xquota/ Project quota on /xquota (/dev/sdb1) Blocks Inodes Project ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- #0 0 0 0 00 [------] 2 0 0 00 [------] testquota 0 200M 300M 00 [------] 1 0 0 00 [------]
Verify xfs project quota
Now since our configuration to set up xfs disk quota is all done, it is time to verify the xfs quota limit. Our soft limit is 200MB and hard limit is 400MB here for /xquota directory. We try to create a dummy file using dd command:
[root@centos-8 ~]# dd if=/dev/urandom of=/xquota/test_file
dd: writing to '/xquota/test_file': No space left on device
614401+0 records in
614400+0 records out
314572800 bytes (315 MB, 300 MiB) copied, 7.74771 s, 40.6 MB/s
As you see after creating a file of 300MB, the command fails with "dd: writing to '/xquota/test_file': No space left on device
". So our xfs disk quota is working as expected.
How xfs quota grace period works?
In XFS Quota, the grace period is referred as timer. When a 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 pops, the particular limit that has been exceeded is treated as if the hard limit has been reached, and no more resources are allocated to the user. The only way to reset this condition, short of turning off limit enforcement or increasing the limit, is to reduce usage below quota.
Update or modify xfs quota grace period (timer)
To check the current xfs quota grace period use "state"
[root@centos-8 ~]# xfs_quota -x -c "state" /xquota/ User quota state on /xquota (/dev/sdb1) Accounting: ON Enforcement: ON Inode: #131 (2 blocks, 2 extents) Group quota state on /xquota (/dev/sdb1) Accounting: ON Enforcement: ON Inode: #135 (2 blocks, 2 extents) Project quota state on /xquota (/dev/sdb1) Accounting: ON Enforcement: ON Inode: #132 (1 blocks, 1 extents) Blocks grace time: [7 days] Inodes grace time: [7 days] Realtime Blocks grace time: [7 days]
By default the xfs quota grace period is 7 days for all block, inodes and realtime blocks. To change the grace period of blocks use (-b
), for inodes (-i
) and for realtime blocks (-r
) as shown below. Here i have increased grace period of block limit to 10 days
[root@centos-8 ~]# xfs_quota -x -c 'timer -p -b 10days' /xquota
Timer allows the quota enforcement timeout (i.e. the amount of time allowed to pass before the soft limits are enforced as the hard limits) to be modified. Verify the new block limit:
[root@centos-8 ~]# xfs_quota -x -c "state -p" /xquota Project quota state on /xquota (/dev/sdb1) Accounting: ON Enforcement: ON Inode: #132 (1 blocks, 1 extents) Blocks grace time: [10 days] Inodes grace time: [7 days] Realtime Blocks grace time: [7 days]
Disable xfs quota temporarily
To disable xfs quota temporarily for xfs user quota use
[root@centos-8 ~]# xfs_quota -x -c "disable -uv" /xquota/ User quota state on /xquota (/dev/sdb1) Accounting: ON Enforcement: OFF Inode: #131 (2 blocks, 2 extents) Blocks grace time: [7 days] Inodes grace time: [7 days] Realtime Blocks grace time: [7 days]
Here as you see Accounting is still ON which means you can still set quota but those limits will not be enforced any more. Now I can create a file with any size under /xquota using user deepak
[deepak@centos-8 ~]$ fallocate -l 2G /xquota/test_file12
As you see user deepak was able to create a file with 2Gb size even when the hard block limit for user deepak was 1G
Similarly to disable quota for group and projects use -g
and -p
respectively.
~]# xfs_quota -x -c "enable -ugpv" /xquota/
where u is for xfs user quota, g for xfs group quota and p for xfs project data
To completely turn OFF xfs quota for user "deepak" on /xquota
[root@centos-8 ~]# xfs_quota -x -c "off -uv" /xquota/ User quota state on /xquota (/dev/sdb1) Accounting: OFF Enforcement: OFF Inode: #131 (2 blocks, 2 extents) Blocks grace time: [7 days] Inodes grace time: [7 days] Realtime Blocks grace time: [7 days]
Next as you see I can only see xfs group quota values for /xquota
[root@centos-8 ~]# xfs_quota -x -c "report -bih" /xquota/
Group quota on /xquota (/dev/sdb1)
Blocks Inodes
Group ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace
---------- --------------------------------- ---------------------------------
root 0 0 0 00 [------] 3 0 0 00 [------]
admin 0 600M 900M 00 [------] 0 0 0 00 [------]
Verify the same under mounts. So for us only group quota is enabled now.
[root@centos-8 ~]# mount | grep quota
/dev/sdb1 on /xquota type xfs (rw,relatime,attr2,inode64,grpquota)
Disable xfs quota permanently
To disable xfs quota permanently remove xfs quota mount options from /etc/fstab
. Remove any xfs quota directives from the filesystem devices under /etc/fstab
. It is better if you add "noquota
" with defaults option to make sure xfs quota is properly disabled
# grep quota /etc/fstab /dev/sdb1 /xquota xfs defaults,noquota 0 0
Next you must reboot your node to activate the changes to disable xfs quota. If you wish to disable xfs quota for the current session as well (without going for reboot) then you can use below command:
[root@centos-8 ~]# xfs_quota -x -c "off -ugpv" /xquota/
This will disable xfs uquota, gquota and pquota for the current session as well.
Lastly I hope the steps from the article to enable xfs quota, configure xfs quota, xfs user quota, xfs group quota, xfs project quota or disk quota and disable xfs quota in CentOS/RHEL 7/8 Linux with examples was helpful. So, let me know your suggestions and feedback using the comment section.
References:
XFS Quota Management
xfs_quota man page
very nice article and well explained in detail. Thank you Admin.