XFS quotas.
per-user and per-group limits on /srv/db.
The DB team keeps dumping huge query results to /srv/db and there have been two close calls with disk fill. dbadmin1 needs per-user and per-group quotas enforced, with a usage report.
The ticket: people on the DB team have been dumping massive query results to /srv/db, and there have already been two close calls with the disk filling. dbadmin1 wants quotas. dbadmin1 gets 500MB soft and 600MB hard, dbreader gets 100MB soft and 150MB hard, and the dbadmins group gets 1GB soft and 1.2GB hard across all members. Finish with a report of everyone’s usage.
The real problem: XFS quotas cannot just be switched on. They need mount options in fstab and a remount before any limit will take effect. Miss that and every limit command silently does nothing.
What we are doing: enabling XFS quotas, setting per-user and per-group limits, and reporting usage.
The ticket
mount | grep /srv/db # confirm /srv/db is mounted XFS df -hT /srv/db id dbadmin1 dbreader getent group dbadmins
Concept review. Soft, hard, and grace.
man xfs_quota mount
A soft limit is a warning threshold. The user can go over it, but only for a grace period, seven days by default. A hard limit is an absolute ceiling, and a write that would cross it fails on the spot. Quotas can be counted in blocks, which is disk space, or in inodes, which is number of files. This ticket is all block quotas.
XFS quotas are turned on by mount options: usrquota for user quotas and grpquota for group quotas. The command to set and read them follows one pattern.
xfs_quota -x -c 'COMMAND' /mountpoint # -x expert mode, needed to set limits, timers, and state # -c the command to run
Enable quotas in fstab and remount
Add the two options to the /srv/db line, then remount. XFS quotas can only be activated by a remount, not on the fly.
grep '/srv/db' /etc/fstab sudo cp /etc/fstab /etc/fstab.bak.$(date +%Y%m%d_%H%M) # add usrquota,grpquota to the /srv/db line's options sudo sed -i '\|/srv/db| s|defaults|defaults,usrquota,grpquota|' /etc/fstab grep '/srv/db' /etc/fstab # remount to activate (unmount then mount, not remount) sudo umount /srv/db sudo mount /srv/db mount | grep /srv/db # should now include usrquota,grpquota
Set the user quotas
sudo xfs_quota -x -c 'limit bsoft=500m bhard=600m dbadmin1' /srv/db sudo xfs_quota -x -c 'limit bsoft=100m bhard=150m dbreader' /srv/db sudo xfs_quota -x -c 'quota -u dbadmin1' /srv/db sudo xfs_quota -x -c 'quota -u dbreader' /srv/db
Set the group quota
The -g flag makes the limit apply to the group across all its members.
sudo xfs_quota -x -c 'limit -g bsoft=1g bhard=1200m dbadmins' /srv/db sudo xfs_quota -x -c 'report -gh' /srv/db
Generate the report
report -uh and report -gh give human-readable usage for users and groups. Save both for dbadmin1.
sudo mkdir -p /srv/audit_reports sudo xfs_quota -x -c 'report -uh' /srv/db | sudo tee /srv/audit_reports/quota_users_$(date +%Y%m%d).txt sudo xfs_quota -x -c 'report -gh' /srv/db | sudo tee /srv/audit_reports/quota_groups_$(date +%Y%m%d).txt
Prove the hard limit works
A quota you have not tested is a quota you do not trust. Write under the limit, then try to blow past it and watch the write stop.
sudo mkdir -p /srv/db/dbadmin1_workspace sudo chown dbadmin1:dbadmins /srv/db/dbadmin1_workspace # under the soft limit, succeeds sudo -u dbadmin1 dd if=/dev/zero of=/srv/db/dbadmin1_workspace/test_400mb bs=1M count=400 sudo xfs_quota -x -c 'quota -u dbadmin1' /srv/db # past the hard limit, stops with 'Disk quota exceeded' sudo -u dbadmin1 dd if=/dev/zero of=/srv/db/dbadmin1_workspace/test_250mb bs=1M count=250 sudo xfs_quota -x -c 'quota -u dbadmin1' /srv/db sudo rm /srv/db/dbadmin1_workspace/test_*
Exam questions
Write the command first.
Q1. Set a 200MB soft and 250MB hard quota for user bob on the XFS filesystem at /srv/db.
Q2. Display a human-readable report of all user quota usage on /srv/db.
Q3. Set a 1GB soft, 1.2GB hard group quota for developers on /srv/db and verify it.
Answers.
# A1 sudo xfs_quota -x -c 'limit bsoft=200m bhard=250m bob' /srv/db # A2 sudo xfs_quota -x -c 'report -uh' /srv/db # A3 sudo xfs_quota -x -c 'limit -g bsoft=1g bhard=1200m developers' /srv/db sudo xfs_quota -x -c 'report -gh' /srv/db
Final checklist: confirm everything works
If every check passes, the ticket is done.
# 1. fstab has usrquota,grpquota and /srv/db is remounted with them grep /srv/db /etc/fstab; mount | grep /srv/db # 2. user and group limits set sudo xfs_quota -x -c 'report -uh' /srv/db # 3. hard limit enforcement verified by an over-limit write # 4. reports saved to /srv/audit_reports/ # 5. all three exam commands written from scratch # 6. tracker entry checked off
Reply to dbadmin1: quotas are active on /srv/db. Per-user limits for dbadmin1 (500m/600m) and dbreader (100m/150m), group limit for dbadmins (1g/1.2g). Reports in /srv/audit_reports/.