Operations 15 min read

Mastering XFS Disk Quota on Linux: Step‑by‑Step Guide for Users and Projects

This comprehensive tutorial explains how to enable and configure Linux Disk Quota on XFS filesystems, covering prerequisites, quota modes, user and directory limits, grace periods, testing scenarios, and essential administration commands for effective storage management.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
Mastering XFS Disk Quota on Linux: Step‑by‑Step Guide for Users and Projects

Introduction

Linux Disk Quota is a technique to limit filesystem resource usage. It can restrict users, groups, or directories to prevent a single entity from exhausting disk space. This article explores applying Disk Quota on XFS.

Prerequisites and Usage Conditions

Linux kernel must support quota; XFS has built‑in quota support.

Quota in usrquota/grpquota mode applies only to regular users; root cannot be limited.

Disable SELinux for testing.

Ext filesystems limit only the whole mount point (cannot limit a single directory).

Avoid applying quota to the root directory "/".

Quota operates on the entire filesystem.

Quota Modes

usrquota : user‑based limits, ineffective for root.

grpquota : group‑based limits.

prjquota : directory‑based limits, cannot be used together with grpquota (supported by xfs_quota).

Typical Quota Workflow

Disable SELinux.

Edit /etc/fstab to add quota activation options for the target filesystem.

Remount the filesystem.

Verify that quota is active.

Use quota commands to set limits for users, groups, or directories.

Validate that the policies are effective.

Check quota usage.

xfs_quota Overview

The xfs_quota command is used extensively; common parameters are summarized below.

Grace Time

Grace time provides a window after a soft limit is exceeded before writes are blocked.

Preparation: Ensure SELinux Is Disabled

<code># sestatus -v
SELinux status:    disabled
# setenforce 0   # temporary disable if enabled
# vi /etc/selinux/config
SELINUX=disabled   # permanent disable</code>

02 User‑Based Quota

Add quota activation option

Append usrquota (or usrquota,grpquota ) to the appropriate line in /etc/fstab :

<code># vi /etc/fstab
/dev/sdb1   /data   xfs defaults,nodiratime,noatime,usrquota 1 2</code>

Remount the filesystem

<code># umount /data
# mount -a</code>

Note: XFS cannot enable quota with mount -o remount ; the above method is required.

Verify activation

<code># mount | grep data
/dev/sdb1 on /data type xfs (rw,noatime,nodiratime,attr2,inode64,logbufs=8,logbsize=32k,usrquota)</code>

Check quota state

<code># xfs_quota -x -c "state"</code>

Set quota for the MySQL user

Soft limit 10 M, hard limit 20 M, grace time 1 minute:

<code># xfs_quota -x -c "limit -u bsoft=10M bhard=20M mysql" /data
# xfs_quota -x -c "timer -u -b 1minutes" /data</code>

Test Scenario 1 – Exceed Hard Limit

<code># su - mysql
$ dd if=/dev/zero of=test.dat bs=1M count=30
dd: error writing ‘test.dat’: Disk quota exceeded</code>

Test Scenario 2 – Exceed Soft Limit and Grace Time

<code># su - mysql
$ dd if=/dev/zero of=test.dat bs=1M count=15
# xfs_quota -x -c "report -ubih" /data</code>

After the 1‑minute grace period, further writes are blocked.

03 Directory‑Based Quota (Project Quota)

Add prjquota to /etc/fstab

<code># vi /etc/fstab
/dev/sdb1   /data   xfs defaults,nodiratime,noatime,prjquota 1 2</code>

Remount and verify

<code># umount /data
# mount -a
# mount | grep data</code>

Create project‑directory mapping

<code># echo "1:/data/mysqldata" >> /etc/projects
# echo "mysqldata:1" >> /etc/projid
# xfs_quota -x -c "project -s mysqldata"</code>

Set directory quota (soft 6 M, hard 10 M)

<code># xfs_quota -x -c "limit -p bsoft=6M bhard=10M mysqldata" /data
# xfs_quota -x -c "report -bih" /data</code>

Test

<code># dd if=/dev/zero of=/data/mysqldata/test.dat bs=1M count=15
dd: error writing ‘/data/mysqldata/test.dat’: No space left on device</code>

04 Common Administration Commands

Temporarily disable quota: xfs_quota -x -c "disable -up" /data

Re‑enable quota: xfs_quota -x -c "enable -p" /data

Completely turn off quota (requires remount): xfs_quota -x -c "off -up" /data

Adjust grace time (user, group, project): xfs_quota -x -c "timer -u -b 14days" /data , xfs_quota -x -c "timer -g -b 14days" /data , xfs_quota -x -c "timer -p -b 14days" /data

05 Summary

This guide provides a practical, step‑by‑step method to deploy block‑based disk quotas on XFS filesystems, covering user, group, and project quotas, as well as common administration commands for effective storage management.

LinuxfilesystemDisk QuotaQuota ManagementXFSAdministration
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.