How to Configure Disk Quotas on a VPS? Print

  • 0

Disk quotas limit the amount of disk space and inodes (file count) users or groups can consume on a Virtual Private Server (VPS). This is crucial for multi-user environments, preventing any single user from exhausting storage and impacting services like web hosting or databases. On a VPS, where resources are often constrained, quotas help maintain performance and fairness. This guide provides concise steps to configure disk quotas on a Linux VPS (e.g., Ubuntu or CentOS), as Windows Server does not natively support similar quota systems without third-party tools.

Why Use Disk Quotas?

  • Resource Management: Prevent users from consuming excessive disk space.
  • System Stability: Avoid service disruptions due to storage exhaustion.
  • Fair Usage: Ensure equitable resource allocation in shared environments.
  • Security: Limit potential abuse from compromised user accounts.

Prerequisites

  • Root Access: Full administrative access via SSH or console.
  • Linux OS: Ubuntu, CentOS, or another distribution with quota support.
  • File System: Quotas require ext4 or similar file systems (not all VPS providers use compatible file systems).
  • Sufficient Storage: Adequate disk space to allocate quotas (check with df -h).
  • Backup: Save critical data before modifying file system settings.

Steps to Configure Disk Quotas on a Linux VPS

This guide focuses on Ubuntu 20.04, with notes for CentOS where applicable.

Step 1: Access the VPS

  • Connect via SSH:
    ssh user@your-vps-ip
    
  • If SSH is unavailable, use the provider’s console. For example, VPS.DO’s SolusVM control panel offers VNC console access for direct management.

Step 2: Enable Quota Support

  • Check if the file system supports quotas:
    df -h /
    
    Ensure the root file system is ext4 (common on KVM-based VPS).
  • Install quota tools:
    sudo apt update && sudo apt install quota quotatool  # Ubuntu
    sudo yum install quota  # CentOS
    
  • Enable quotas on the file system by editing /etc/fstab:
    sudo nano /etc/fstab
    
  • Find the root partition (e.g., /dev/sda1 / ext4 defaults 0 1) and add usrquota,grpquota:
    /dev/sda1 / ext4 defaults,usrquota,grpquota 0 1
    
  • Remount the file system:
    sudo mount -o remount /
    
  • Verify quota support:
    mount | grep 'usrquota'
    

Step 3: Initialize Quota Files

  • Create quota files for users and groups:
    sudo quotacheck -cugm /
    
    This generates aquota.user and aquota.group in the root directory.
  • Enable quotas:
    sudo quotaon -av
    

Step 4: Set Quotas for Users

  • Assign quotas to a user (e.g., testuser):
    sudo edquota -u testuser
    
  • In the editor, set soft and hard limits for blocks (space) and inodes (files). Example:
    Disk quotas for user testuser (uid 1001):
      Filesystem  blocks  soft  hard  inodes  soft  hard
      /dev/sda1   0       50000 60000 0       1000  1200
    
    • blocks: Disk space in KB (e.g., 50000 KB = 50 MB soft limit, 60000 KB = 60 MB hard limit).
    • inodes: Number of files.
  • Save and exit.

Step 5: Set Quotas for Groups

  • Assign quotas to a group (e.g., testgroup):
    sudo edquota -g testgroup
    
  • Set similar soft/hard limits for blocks and inodes.

Step 6: Test and Verify Quotas

  • Check a user’s quota:
    sudo quota -u testuser
    
  • Test by creating files as the user:
    su - testuser
    dd if=/dev/zero of=testfile bs=1M count=70  # Attempt to exceed quota
    
  • Verify quota enforcement (should fail if exceeding hard limit).
  • Monitor disk usage in the VPS control panel, such as VPS.DO’s SolusVM dashboard, to ensure quotas align with available storage.

Step 7: Automate Quota Checks

  • Enable periodic quota checks via cron:
    sudo crontab -e
    
  • Add:
    0 0 * * * /sbin/quotacheck -avugm
    
  • Ensure quota service starts on boot:
    sudo systemctl enable quota
    

Troubleshooting

  • Quota Not Enforced: Verify usrquota,grpquota in /etc/fstab and run quotaon -av.
  • File System Incompatible: Confirm the file system is ext4 (use lsblk -f). Some VPS providers may use unsupported file systems; contact support if needed.
  • Permission Errors: Ensure root privileges (sudo) for all commands.
  • Disk Full: Check total disk usage (df -h). If storage is low, consider upgrading the VPS plan.

Best Practices

  • Set Reasonable Limits: Balance user needs with available disk space.
  • Monitor Usage: Regularly check quota reports (repquota -a) to adjust limits.
  • Backup Configurations: Save /etc/fstab and quota files before changes.
  • Secure Quota Files: Restrict access to aquota.user and aquota.group:
    sudo chmod 600 /aquota.*
    
  • Test Quotas: Verify limits with test users before applying to production.

When to Seek Help

If quotas fail to apply or you suspect provider-side storage issues, contact your VPS provider with details (e.g., fstab config, error messages). Providers like VPS.DO offer 24/7 ticket-based support for assistance.

Configuring disk quotas ensures efficient resource management, maintaining stability and fairness on your VPS for all users and services.


Was this answer helpful?

« Back