Disk Quotas - User Disk Space Limits Guide

Disk quotas are essential for managing shared storage resources in multi-user environments. This DevOps-focused guide covers user and group quota management, filesystem-specific tools, and container quota integration for modern infrastructure.

Quota Management Tools Comparison

Quota Type Primary Tools Filesystems DevOps Use Case
User Quotas quota, edquota, setquota ext4, XFS Multi-tenant environments
Group Quotas edquota -g, setquota -g ext4, XFS Team storage limits
Project Quotas xfs_quota, project quota XFS, ext4 Application storage limits
Container Quotas docker run, k8s limits Any Container storage limits
DevOps Quick Reference:
• Check quotas: quota -u username or repquota /mountpoint
• Set user quota: setquota -u username 500M 1G 0 0 /mountpoint
• Edit quota: edquota username
• XFS quotas: xfs_quota -x -c "limit bsoft=1g bhard=2g username" /mountpoint
• Container limits: docker run --storage-opt size=10G
• Kubernetes: Set resources.limits.ephemeral-storage
• Enable quotas: Add usrquota,grpquota to fstab
• Always test quota settings in staging first

Quota Usage Visualization

User: john (Soft: 1GB, Hard: 2GB) 750MB / 1GB (75%)
Group: developers (Soft: 10GB, Hard: 15GB) 8.2GB / 10GB (82%)
Project: webapp (Soft: 5GB, Hard: 7GB) 2.1GB / 5GB (42%)

Essential Quota Commands

Basic Quota Management

Enable and manage user/group quotas on filesystems.

quota, edquota, setquota, repquota
# Install quota tools
sudo apt install quota

# Enable quotas on filesystem
# Add to /etc/fstab:
# /dev/sdb1 /home ext4 defaults,usrquota,grpquota 0 2

# Remount with quotas
sudo mount -o remount /home

# Initialize quota database
sudo quotacheck -cug /home
sudo quotacheck -avug

# Enable quotas
sudo quotaon -av

# Check user quota
quota -u john
quota -g developers

# Set quota for user
sudo setquota -u john 500M 1G 0 0 /home

# Edit quota interactively
sudo edquota john

# Copy quota to multiple users
sudo edquota -p john user1 user2 user3

# Report quota usage
repquota /home
repquota -a

# Disable quotas
sudo quotaoff -a
XFS Quota Management

Advanced quota features for XFS filesystems.

xfs_quota, xfs_quota -x
# Enable quotas on XFS
# Add to /etc/fstab:
# /dev/sdb1 /data xfs defaults,usrquota,grpquota,prjquota 0 2

# Mount with quotas
sudo mount -o remount /data

# Interactive XFS quota management
sudo xfs_quota -x

# Common xfs_quota commands:
# report -h /data          # Human-readable report
# limit bsoft=1g bhard=2g john /data
# limit -g bsoft=10g bhard=15g developers /data
# limit -p bsoft=5g bhard=7g project1 /data

# Set project quota
echo 123:/data/webapp >> /etc/projects
echo webapp:123 >> /etc/projid
sudo xfs_quota -x -c "project -s webapp" /data
sudo xfs_quota -x -c "limit -p bsoft=5g bhard=7g webapp" /data

# Check project usage
sudo xfs_quota -x -c "report -h -p" /data

# Set grace periods
sudo xfs_quota -x -c "timer -g -b 7days" /data
sudo xfs_quota -x -c "timer -u -b 7days" /data

# Export/import quota settings
sudo xfs_quota -x -c "report -p -n" /data > quotas.txt
Quota Monitoring & Reporting

Monitor quota usage and generate reports.

repquota, warnquota, quota reports
# Comprehensive quota report
repquota -aug

# Human-readable report
repquota -augsi

# Report for specific filesystem
repquota -s /home

# Check quota exceeded users
repquota -a | grep +

# Set up automatic quota warnings
sudo warnquota

# Configure warnquota
# Edit /etc/warnquota.conf
#
# MAIL_CMD = /usr/bin/mail
# FROM = quota-manager@company.com
# SUBJECT = Disk Quota Warning
# MESSAGE = Your disk quota has exceeded...

# Test warnquota
sudo warnquota -u john

# Daily quota report script
#!/bin/bash
DATE=$(date +%Y%m%d)
repquota -augsi > /var/log/quotas/quotas_$DATE.log

# Find large quota users
repquota -a | awk '$3 > 1000000 {print $1, $2, $3}' | sort -k3 -nr

# Monitor with watch
watch -n 60 'repquota -s /home'

# Send quota alerts via Slack/Email
# Integrate with monitoring systems

Quota Configuration Guidelines

Environment User Quota Group Quota Grace Period DevOps Recommendation
Development 5-10GB 50GB 7 days Allow experimentation space
Production 1-2GB 20GB 1 day Strict limits for stability
Multi-tenant 500MB-1GB 10GB 3 days Fair resource sharing
Container Host N/A N/A N/A Use container storage limits
Kubernetes N/A N/A N/A Use ResourceQuota and limits

Container & Cloud Quotas

Docker Storage Limits

Manage container storage with Docker quotas.

docker run, storage-opt, devicemapper
# Set container storage limit
docker run -it --storage-opt size=10G ubuntu

# Docker daemon storage options
# /etc/docker/daemon.json
{
  "storage-driver": "devicemapper",
  "storage-opts": [
    "dm.basesize=10G",
    "dm.fs=ext4",
    "dm.thinpooldev=/dev/mapper/docker-thinpool"
  ]
}

# Check container storage usage
docker system df
docker ps -s

# Limit container writable layer
docker run -it --storage-opt size=120G ubuntu

# Compose file with storage limits
# docker-compose.yml
version: '3.8'
services:
  app:
    image: ubuntu
    storage_opt:
      size: 10G

# Clean up unused containers and images
docker system prune -a -f

# Monitor container storage growth
docker stats --format "table {{.Name}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"

# Set overlay2 storage driver limits
# /etc/docker/daemon.json
{
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.size=10G"
  ]
}
Kubernetes Storage Quotas

Implement storage quotas in Kubernetes clusters.

kubectl, ResourceQuota, limits
# Namespace storage quota
apiVersion: v1
kind: ResourceQuota
metadata:
  name: storage-quota
  namespace: production
spec:
  hard:
    requests.storage: "100Gi"
    persistentvolumeclaims: "10"
    requests.ephemeral-storage: "10Gi"
    limits.ephemeral-storage: "20Gi"

# Pod storage limits
apiVersion: v1
kind: Pod
metadata:
  name: storage-demo
spec:
  containers:
  - name: app
    image: nginx
    resources:
      limits:
        ephemeral-storage: "2Gi"
      requests:
        ephemeral-storage: "1Gi"

# Check quota usage
kubectl describe resourcequota storage-quota -n production

# PVC quota example
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-quota
spec:
  resources:
    requests:
      storage: 5Gi

# StorageClass with quota enforcement
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: quota-sc
provisioner: kubernetes.io/no-provisioner
parameters:
  storage: "5Gi"

# Monitor storage usage
kubectl top pods --containers
kubectl describe nodes | grep -A10 "Allocated resources"

# Clean up unused PVCs
kubectl get pvc --all-namespaces | grep Released | awk '{print $2 " -n " $1}' | xargs -n3 kubectl delete pvc
Quota Automation & Monitoring

Automate quota management and monitoring.

Scripts, cron, monitoring tools
# Automated quota setup script
#!/bin/bash
MOUNT_POINT="/home"
QUOTA_DB="/aquota.user"

# Initialize if not exists
if [ ! -f $MOUNT_POINT$QUOTA_DB ]; then
    quotacheck -cug $MOUNT_POINT
    quotaon $MOUNT_POINT
fi

# Set default quotas for new users
#!/bin/bash
DEFAULT_SOFT="500M"
DEFAULT_HARD="1G"

for user in $(ls /home); do
    if [ -d "/home/$user" ]; then
        setquota -u $user $DEFAULT_SOFT $DEFAULT_HARD 0 0 /home
    fi
done

# Quota alert script
#!/bin/bash
THRESHOLD=90
ALERT_EMAIL="admin@company.com"

repquota -a | awk -v threshold=$THRESHOLD '
$1 ~ /^[a-z]/ && $3 > 0 {
    usage = ($2 / $3) * 100
    if (usage > threshold) {
        print "ALERT: User " $1 " quota usage: " usage "%"
    }
}' | mail -s "Quota Alert" $ALERT_EMAIL

# Prometheus quota monitoring
# node_exporter textfile collector
#!/bin/bash
echo "quota_usage{user=\"john\",mount=\"/home\"} 75" > /var/lib/node_exporter/quota.prom
echo "quota_usage{user=\"jane\",mount=\"/home\"} 42" >> /var/lib/node_exporter/quota.prom

# Ansible quota management
- name: Set user quotas
  community.general.quota:
    user: "{{ item.user }}"
    type: user
    mountpoint: /home
    block_soft: "{{ item.soft }}"
    block_hard: "{{ item.hard }}"
  loop:
    - { user: 'john', soft: '500M', hard: '1G' }
    - { user: 'jane', soft: '1G', hard: '2G' }

Practical DevOps Scenarios

Real-World Quota Management Scripts

# 1. Multi-tenant Quota Setup
#!/bin/bash
MOUNT_POINT="/shared"
TENANTS=("tenant1" "tenant2" "tenant3" "tenant4")

echo "Setting up multi-tenant quotas..."
for tenant in "${TENANTS[@]}"; do
    # Create tenant directory
    mkdir -p $MOUNT_POINT/$tenant
    
    # Set project quota (XFS)
    echo "$((RANDOM+1000)):$MOUNT_POINT/$tenant" >> /etc/projects
    echo "$tenant:$((RANDOM+1000))" >> /etc/projid
    xfs_quota -x -c "project -s $tenant" $MOUNT_POINT
    
    # Set quota limits (5GB soft, 7GB hard)
    xfs_quota -x -c "limit -p bsoft=5g bhard=7g $tenant" $MOUNT_POINT
    
    echo "Quota set for tenant: $tenant"
done

# 2. Automated Quota Compliance Check
#!/bin/bash
COMPLIANCE_FILE="/var/log/quota-compliance.log"
NON_COMPLIANT_USERS=()

echo "Quota Compliance Check - $(date)" > $COMPLIANCE_FILE
echo "=================================" >> $COMPLIANCE_FILE

repquota -a | while read line; do
    if [[ $line =~ ^[a-z] ]] && [[ $line =~ \+ ]]; then
        user=$(echo $line | awk '{print $1}')
        usage=$(echo $line | awk '{printf "%.1f", ($2/$3)*100}')
        NON_COMPLIANT_USERS+=("$user ($usage%)")
        echo "NON-COMPLIANT: $user - $usage% usage" >> $COMPLIANCE_FILE
    fi
done

if [ ${#NON_COMPLIANT_USERS[@]} -gt 0 ]; then
    echo "Alert: ${#NON_COMPLIANT_USERS[@]} users over quota"
    # Send to Slack/Teams/Email
fi

# 3. Container Storage Cleanup
#!/bin/bash
THRESHOLD=85
CURRENT_USAGE=$(df /var/lib/docker | awk 'NR==2{print $5}' | sed 's/%//')

if [ $CURRENT_USAGE -gt $THRESHOLD ]; then
    echo "Docker storage usage: ${CURRENT_USAGE}% - cleaning up..."
    
    # Remove unused containers
    docker container prune -f
    
    # Remove unused images
    docker image prune -a -f
    
    # Remove unused volumes
    docker volume prune -f
    
    # Remove build cache
    docker builder prune -a -f
    
    echo "Cleanup completed"
fi

# 4. Kubernetes Storage Quota Enforcer
#!/bin/bash
NAMESPACE=$1
STORAGE_LIMIT="50Gi"

# Create ResourceQuota if not exists
kubectl get resourcequota storage-quota -n $NAMESPACE &>/dev/null || \
kubectl create -f - < /tmp/old_quotas.txt

# Apply quotas to new filesystem
while read user soft hard; do
    setquota -u $user ${soft}K ${hard}K 0 0 $NEW_MOUNT
done < /tmp/old_quotas.txt

echo "Quota migration completed"

# 6. Cloud Instance Quota Setup
#!/bin/bash
# Cloud-init script for auto quota setup
MOUNT_POINT="/shared"

# Install quota tools
apt-get update && apt-get install -y quota

# Enable quotas on filesystem
sed -i 's/defaults/defaults,usrquota,grpquota/' /etc/fstab
mount -o remount $MOUNT_POINT

# Initialize quota system
quotacheck -cug $MOUNT_POINT
quotaon $MOUNT_POINT

# Set default quotas
echo "*/5 * * * * /usr/local/bin/quota-monitor.sh" | crontab -

Troubleshooting Common Quota Issues

Configuration Problems

  • Quotas Not Working: Check fstab options, remount filesystem, run quotacheck
  • Permission Denied: Ensure quota tools have proper permissions, check selinux/apparmor
  • Quota Database Corrupt: Run quotacheck -avug to rebuild

Performance Issues

  • Slow Quota Checks: Use quotacheck -avugm for faster scanning
  • High I/O During quotacheck: Schedule during off-peak hours
  • Container Storage Full: Clean up unused images and containers regularly

Container Quota Issues

  • Docker Storage Full: Use docker system prune, increase base size
  • Kubernetes PVC Issues: Check StorageClass, ResourceQuota, and node disk space
  • Container Restarts: Monitor ephemeral storage usage in pod specs
DevOps Best Practices:
• Set realistic soft limits with reasonable grace periods
• Monitor quota usage proactively with alerts
• Use project quotas for application directories
• Document quota policies and procedures
• Test quota enforcement in staging environments
• Have a process for quota increase requests
• Regular quota audits and cleanup
• Backup quota configurations regularly
Performance Tips:
• Use XFS project quotas for better performance with many users
• Schedule quotacheck during low-usage periods
• Use quotacheck -m to skip mounted filesystem checks
• Monitor inode usage along with block usage
• Consider using dedicated monitoring for quota alerts
• Use container storage drivers with built-in quota support
• Regular filesystem maintenance and defragmentation

Key DevOps Takeaways

Disk quotas are essential for managing shared storage resources in multi-user and multi-tenant environments. By implementing proper quota policies, automating quota management, and integrating with container orchestration platforms, you can ensure fair resource allocation and prevent storage-related outages. Remember that quotas are not just about limiting usage but about enabling predictable and reliable storage management.

Next Step: Explore advanced storage management topics like LVM integration with quotas, cloud storage quota management, and automated storage provisioning with quota enforcement.