Disk_quotas
Chapter 15: Disk Quotas and Limits
Section titled “Chapter 15: Disk Quotas and Limits”Overview
Section titled “Overview”Disk quotas allow administrators to limit disk space and file count for users and groups. This chapter covers quota setup, management, monitoring, and best practices for Linux systems in production environments.
15.1 Quota Overview
Section titled “15.1 Quota Overview”Quota Types
Section titled “Quota Types”┌─────────────────────────────────────────────────────────────────────────┐│ DISK QUOTA TYPES │├─────────────────────────────────────────────────────────────────────────┤│ ││ User/Group Quotas: ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ User quotas: Limit disk space/files per user │ ││ │ Group quotas: Limit disk space/files per group │ ││ └─────────────────────────────────────────────────────────────────┘ ││ ││ Block/Inode Limits: ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Block limits: Disk space in KB/MB (actual storage used) │ ││ │ Inode limits: Number of files (prevents tiny file attack) │ ││ └─────────────────────────────────────────────────────────────────┘ ││ ││ Limit Types: ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Soft limit: Warning threshold, can exceed during grace period │ ││ │ Hard limit: Absolute maximum, cannot exceed │ ││ │ Grace period: Time allowed to exceed soft limit │ ││ └─────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────┘15.2 Setting Up Quotas
Section titled “15.2 Setting Up Quotas”Installation
Section titled “Installation”# Install quota tools# Debian/Ubuntusudo apt install quota
# RHEL/CentOSsudo yum install quota
# Arch Linuxsudo pacman -S quota-toolsEnable Quotas in fstab
Section titled “Enable Quotas in fstab”# /etc/fstab - add usrquota,grpquota# /dev/sda1 / ext4 defaults,usrquota,grpquota 0 1
# For XFS filesystem (use uquota,gquota instead)/dev/sda1 / xfs defaults,uquota,gquota 0 0
# Remount filesystemsudo mount -o remount /
# Verifymount | grep quotasInitialize Quota Files
Section titled “Initialize Quota Files”# Create quota filessudo quotacheck -cugm /
# Options:# -c: create new quota files# -u: user quotas# -g: group quotas# -m: don't remount read-only
# Verify created filesls -la /aquota.*# -rw------- 1 root root 7168 /aquota.user# -rw------- 1 root root 6144 /aquota.groupEnable/Disable Quotas
Section titled “Enable/Disable Quotas”# Enable quotassudo quotaon /sudo quotaon -av
# Disable quotassudo quotaoff /
# Enable for specific filesystemsudo quotaon -uv /homesudo quotaon -gv /home15.3 Managing Quotas
Section titled “15.3 Managing Quotas”Setting User Quotas
Section titled “Setting User Quotas”# Edit user quota interactivelysudo edquota -u username
# Example output:# Disk quotas for user john (uid 1000):# Filesystem blocks soft hard inodes soft hard# /dev/sda1 1000 5000 10000 50 100 200
# Set limits in GBsudo edquota -u john# blocks: current usage in KB# soft: 5GB = 5242880 KB# hard: 10GB = 10485760 KB
# Set inode limits# soft: 100 files# hard: 200 filesSetting Group Quotas
Section titled “Setting Group Quotas”# Edit group quotasudo edquota -g developers
# Set limits in GBsudo edquota -g developers# soft: 50GB# hard: 100GBCopy Quota Template
Section titled “Copy Quota Template”# Copy quota settings from one user to anothersudo edquota -p user1 user2 user3
# Useful for setting up multiple users with same limitsQuota Commands
Section titled “Quota Commands”# Check user quotaquota -u usernamequota -u john
# Check group quotaquota -g groupname
# Generate quota reportrepquota -arepquota -aug
# Check quota without being rootsudo -u username quota -u username15.4 Setting Grace Period
Section titled “15.4 Setting Grace Period”# Set grace period for soft limitssudo edquota -t
# Example:# Block grace period: 7 days# Inode grace period: 7 days
# During grace period, users can exceed soft limit# After grace period, soft limit becomes enforced15.5 XFS Quotas
Section titled “15.5 XFS Quotas”# XFS uses different quota commands# Enable in /etc/fstab# /dev/sda1 / xfs defaults,uquota,gquota 0 0
# Report XFS quotasxfs_quota -x -c 'report -h' /
# Set limitsxfs_quota -x -c 'limit bsoft=5g bhard=10g john' /
# Set inode limitsxfs_quota -x -c 'limit isoft=100 ihard=200 john' /
# Real-time monitoringxfs_quota -x -c 'state' /15.6 Monitoring and Troubleshooting
Section titled “15.6 Monitoring and Troubleshooting”# Check quota usagerepquota -a
# Find users approaching limitssudo repquota -a | grep -E "^[+-]"
# Quota violations in logs# Check /var/log/messages for quota warnings
# Common issues:# - "Disk quota exceeded" errors# - Cannot create new files# - Check grace period with: quota -u username -v15.7 Interview Questions
Section titled “15.7 Interview Questions”┌─────────────────────────────────────────────────────────────────────────┐│ DISK QUOTA INTERVIEW QUESTIONS │├─────────────────────────────────────────────────────────────────────────┤ │Q1: What is the difference between soft and hard limits? │ │A1: │- Soft limit: Warning threshold, can be exceeded during grace period │- Hard limit: Absolute maximum, cannot be exceeded │- After grace period expires, soft limit becomes enforced │ │─────────────────────────────────────────────────────────────────────────┤ │Q2: How do you enable disk quotas on Linux? │ │A2: │1. Add usrquota,grpquota to /etc/fstab │2. Remount filesystem: mount -o remount / │3. Create quota files: quotacheck -cugm / │4. Enable quotas: quotaon / │ │─────────────────────────────────────────────────────────────────────────┤ │Q3: What are inode quotas and why are they useful? │ │A3: │- Limit number of files a user/group can create │- Prevents "tiny file attack" (many 0-byte files) │- Useful for preventing directory exhaustion │- Set separately from block (space) quotas │ │─────────────────────────────────────────────────────────────────────────┤ │Q4: How do you set up quotas for multiple users quickly? │ │A4: │- Set quota for one user as template │- Use edquota -p template_user user1 user2 user3 │- Or use script with setquota command │ │─────────────────────────────────────────────────────────────────────────┤ │Q5: What happens when a user exceeds their hard limit? │ │A5: │- Cannot create new files │- Cannot extend existing files │- Gets "Disk quota exceeded" error │- Must delete files or administrator must increase limit │ │─────────────────────────────────────────────────────────────────────────┤ │Q6: How do XFS quotas differ from traditional quotas? │ │A6: │- XFS uses uquota,gquota mount options │- Different commands: xfs_quota │- Can be managed in real-time without quotacheck │- More scalable for large systems │ │─────────────────────────────────────────────────────────────────────────┤ │Q7: How do you check which users are using the most disk space? │ │A7: │repquota -a or repquota -aug │Sort by blocks column │ │─────────────────────────────────────────────────────────────────────────┤ │Q8: What is quota grace period? │ │A8: │- Time allowed to exceed soft limit before enforcement │- Set with edquota -t command │- Applies to both block and inode quotas │- Default is usually 7 days │ │└─────────────────────────────────────────────────────────────────────────┘Quick Reference
Section titled “Quick Reference”# Setupapt install quota# Add usrquota,grpquota to /etc/fstabmount -o remount /quotacheck -cugm /quotaon /
# Managementedquota -u username # Edit user quotaedquota -g groupname # Edit group quotaedquota -p user1 user2 # Copy quotaquota -u username # Check quotarepquota -a # Full reportquotaon /quotaoff / # Enable/disableSummary
Section titled “Summary”- Types: User, Group, Block (space), Inode (files)
- Limits: Soft (warning), Hard (maximum)
- Tools: edquota, quota, repquota, quotacheck, xfs_quota
- Setup: fstab → remount → quotacheck → quotaon
Next Chapter
Section titled “Next Chapter”Chapter 16: Process Management
Last Updated: February 2026