XFS Quota Managament
Like any other file system (EXT3/EXT4), XFS does support quota management. Quotas are used to allocate/restrict disk space usage in a file system. XFS quota supports 3 types i.e., user, group and project level quotas. Technically, there is no directory level quota in XFS, but project type of quota can be used to implement directory level quota.
NOTE1: You need to have a kernel which supports project level quota.
NOTE2: Group and project level quotas are mutually exclusive. Either group or project level quota can be applied a file system.
Before we can start, mount/remount the XFS partition with quota support. Here I am using fstab file for remounting the partition. Add below line to your /etc/fstab file. To understand the format of fstab of file, refer http://en.wikipedia.org/wiki/Fstab#Example
/dev/sdb /xfs_local xfs defaults,uquota 1 1
Mount the partition with below command.
[root@warhammer ~]# mount –a
or you can remount the directory with user quota support like below. I would suggest to update the quota support in “fstab” file rather than remounting it.
[root@warhammer ~]# mount -o remount,uquota /xfs_local
Check all mounted directories to verify
[root@warhammer ~]# mount
/dev/sda3 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
/dev/sda5 on /local type ext3 (rw)
/dev/sda4 on /var type ext3 (rw)
/dev/sdb on /xfs_local type xfs (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
User quota:
Let’s create user quota domain for ‘maddy’ user under /xfs_local file system (partition) with 200m of hard limit.
[root@warhammer ~]# xfs_quota –xc ‘limit bsoft=100m bhard=200m maddy’ /xfs_local
Though native quota commands can also be used to manage quota, XFS has its own set of command to create and manage quota.
Let’s see the command we just used.
xfs_quota => Control command to manage quota domain
xc => Switch to create quotas
limit => Switch to limit the usage
bsoft|bhard => Switch to enforce disk usage limit. bsoft stands for soft limit. bhard stands for hard limit. This switch can enforce limit based on the size i.e., in mega or giga byes.
isoft|ihard => This switch for enforcing limit based on inode usage.
NOTE : Use either size or inode based quota domain
maddy => Username on which the quota is being enforced
/xfs_local => Partition on which quota is enforced for user ‘maddy’
Please note. In above example, we are enforcing quota on /xfs_local partition. That means, quota restriction will ONLY be applied inside /xfs_local partition. User will be able to write more than 200m of data to other partition like /tmp.
We can see all the quota domains applied using below command. It will list all types of quota applied for a file system (partition)
[root@warhammer ~]# xfs_quotas -xc ‘report’ /xfs_local
User quota on /xfs_local (/dev/sdb)
Blocks
User ID Used Soft Hard Warn/Grace
———- ————————————————–
maddy 0 102400 204800 00 [——–]
root 73163404 0 0 00 [——–]
As you can see, user ‘maddy’ applied with 200Mb hard limit and 100M soft limit. Now, let’s create a file to test quota we just applied.
[root@warhammer ~]# su – maddy
warhammer:~> cd /xfs_local/test/
warhammer:/xfs_local/test> cat /dev/zero > test
cat: write error: Disk quota exceeded
warhammer:/xfs_local/test> du -sh *
200M test
There it is. Quota worked as expected.
Group quota:
Group quota can be used to restrict disk space usage for a specific UNIX group. Every user in the group can use allocated space. Let’s see how it works.
First, we need remount the partition with group quota support.
[root@warhammer ~]# mount -o remount,gquota /xfs_local
When you create a UNIX account, there will be an UNIX group also gets created with the same name. Will create a new user and add the user to existing group. Will created a new user ‘maddy2’ and add him to ‘maddy’ group
[root@warhammer ~]# useradd -m maddy2 -g maddy
Make sure he is in ‘maddy’ group
[root@warhammer ~]# id maddy2
uid=60000(maddy2) gid=59999(maddy) groups=59999(maddy)
Let’s create quota domain for a group.
[root@warhammer ~]# xfs_quota -xc ‘limit –g bsoft=50m bhard=100m maddy’ /xfs_local
The syntax is similar to user quota. ‘-g’ switch is used which says it’s a group level quota. Also note, ‘maddy’ represent the group.
Let’s see all quotas domains.
[root@warhammer ~]# xfs_quota -xc ‘report’/xfs_local/
User quota on /xfs_local (/dev/sdb)
Blocks
User ID Used Soft Hard Warn/Grace
———- ————————————————–
maddy 204800 102400 204800 00 [——–]
`
Group quota on /xfs_local (/dev/sdb)
Blocks
Group ID Used Soft Hard Warn/Grace
———- ————————————————–
hardware 204796 0 0 00 [——–]
root 73163404 0 0 00 [——–]
mail 0 0 104857600 00 [——–]
news 0 0 102400 00 [——–]
gopher 204796 0 0 00 [——–]
maddy 0 51200 102400 00 [7 days]
You can see group ‘maddy’ has quota domain applied.
Now, let’s create a folder and set the permission accordingly and create some files within /xfs_local file system (partition) with both users in ‘maddy’ group
[root@warhammer ~]# mkdir /xfs_local/maddy_group/
[root@warhammer ~]# chmod 775 /xfs_local/maddy_group/
[root@warhammer ~]# chown maddy:maddy /xfs_local/maddy_group/
[root@warhammer ~]# su – maddy
warhammer:~> cd /xfs_local/maddy_group/
warhammer:~> dd if=/dev/zero of=50mb.test bs=1M count=50
warhammer:~> ls -lrth 50mb.test
-rw-r–r– 1 maddy maddy 50M Dec 15 10:14 50mb.test
Done. Let’s switch to ‘maddy2’ user and create one more file.
[root@warhammer ~]# su – maddy2
warhammer:~> cd /xfs_local/maddy_group/
warhammer:~> dd if=/dev/zero of=45mb.test bs=1M count=45
warhammer:~> ls -lrth 45mb.test
-rw-r–r– 1 maddy2 maddy2 45M Dec 15 11:14 45mb.test
Now, we have two files 50M and 45M. So, we still have 5M free space. Let’s create one more.
[root@warhammer ~]# su – maddy
warhammer:~> cd /xfs_local/maddy_group/
warhammer:~> dd if=/dev/zero of=50mb.test bs=1M count=50
dd: write error: Disk quota exceeded
Write failed due to the disk quota. Let’s see the report.
[root@warhammer ~]# xfs_quota -xc ‘report’/xfs_local
User quota on /xfs_local (/dev/sdb)
Blocks
User ID Used Soft Hard Warn/Grace
———- ————————————————–
maddy 204800 102400 204800 00 [——–]
`
Group quota on /xfs_local (/dev/sdb)
Blocks
Group ID Used Soft Hard Warn/Grace
———- ————————————————–
hardware 204796 0 0 00 [——–]
root 73163404 0 0 00 [——–]
mail 0 0 104857600 00 [——–]
news 0 0 102400 00 [——–]
gopher 204796 0 0 00 [——–]
maddy 102396 51200 102400 00 [7 days]
Bingo, there is it!!!
Project quota:
As I mentioned earlier, technically there is no directory quota. But, we can use project quota to simulate directory level quota. Directory level quota is useful when you want to restrict the space for a specific directory irrespective which user/group can write to it.
First, remount the partition with project quota support.
[root@warhammer ~]# mount -o remount,pquota /xfs_local
Let’s create a test directory inside /xfs_local file system.
[root@warhammer ~]# mkdir /xfs_local/project_quota_test1
[root@warhammer ~]# mkdir /xfs_local/project_quota_test2
[root@warhammer ~]# chmod 755 /xfs_local/project_quota_test*
[root@warhammer ~]# chown maddy:hardware /xfs_local/project_quota_test*
For project quota, we need to create two files in /etc/folder.
[root@warhammer ~]# touch /etc/projects
[root@warhammer ~]# touch /etc/projid
/etc/project file contains the directory name and /etc/projid contains project ID to directory name mapping. /etc/projid file is optional though.
Let’s update both the files with directory name we created.
[root@warhammer ~]#echo 11:/xfs_local/project_quota_test1 >> /etc/projects
[root@warhammer ~]#echo project_quota_test1:11 >> /etc/projid
NOTE: In project file, you need to provide full path to the directory whereas in projid file, you just have to mention the directory name
Now, let’s create quota domain for the directory. There are two steps in here. First you define the project/ID and then you enable quota for the project.
[root@warhammer ~]# xfs_quota -xc ‘project –s 11’ /xfs_local
Setting up project 11 (path /xfs_local/project_quota_test1)…
Processed 1 /etc/projects paths for project 11
[root@warhammer ~]# xfs_quota -xc ‘limit –p bhard=100G 11’ /xfs_local
Syntax is simple. ‘project’ switch says it’s a project type quota followed by ‘-s’ key. ‘11’ defines, to which project(directory) you are enabling the quota. You need to have ‘projid’ file if you want to use project ID’s during the quota domain creation.
You can also create quota by mentioning the directory name as below
[root@warhammer ~]# xfs_quota -xc ‘project –s project_quota_tes2’ /xfs_local
Setting up project project_quota_tes2 (path /xfs_local/project_quota_test2)…
Processed 1 /etc/projects paths for project project_quota_tes2
[root@warhammer ~]# xfs_quota -xc ‘limit –p bhard=100G project_quota_tes2’ /xfs_local
Let’s see what quota report shows.
[root@warhammer ~]# xfs_quota -xc ‘report’/xfs_local
Project quota on /xfs_local (/dev/sdb)
Blocks
Project ID Used Soft Hard Warn/Grace
———- ————————————————–
project_quota_test1 0 512000 104857600 00 [———]
project_quota_test2 0 512000 104857600 00 [——–]
That’s it. You can check the quota by using ‘df’ command.
[root@warhammer ~]# df -h /xfs_local/project_quota_test2/
Filesystem Size Used Avail Use% Mounted on
/dev/sdb 100G 0 100G 0% /xfs_local
You can see the directory size is set to 100G.
Last point. Sometime when you create quota domain (of any type), you may see error like below.
xfs_quota: cannot set limits: No such process
If you see this error, a simple solution is to reboot your machine and create quotas later.
__maddy
NIce Tutorial.