quotacheck - Linux


Overview

quotacheck is a Linux utility used to scan one or more filesystems for disk usage, and to build or update quota files which track the disk space and inode usage of each user and group. This command is particularly useful in system administration for enforcing disk usage policies and managing resources efficiently.

Syntax

The basic syntax of the quotacheck command is as follows:

quotacheck [options] -u|-g [-v] filesystem...
  • -u: Check user quotas.
  • -g: Check group quotas.
  • filesystem: Specifies which filesystem to check.

Note: You can specify more than one filesystem at a time.

Options/Flags

  • -c: Create quota files if they do not yet exist.
  • -m: Do not try to remount filesystem read-only.
  • -a: Check all mounted non-NFS filesystems in /etc/mtab.
  • -v: Verbose mode. Display progress and debugging messages during execution.
  • -n: No print. Do not print error messages about quota files.
  • -p: Partial check. Skip filesystems that cannot be stated to be checked without affecting the system state.
  • -R: Root filesystem only. Useful during system boot process.
  • -f: Force checking even if quotas are enabled.
  • -s: Attempt to optimize by using space limits only, ignoring inode limits.

Examples

  1. Basic Check: Check user quotas on /home filesystem.

    quotacheck -u /home
    
  2. Verbose Output: Check both user and group quotas on /dev/sda1 with verbose output.

    quotacheck -ugv /dev/sda1
    
  3. Create Quota Files: Scan all filesystems and create quota files if they don’t exist.

    quotacheck -uga -c 
    

Common Issues

  • Permission Denied: Ensure that quotacheck is run as root or with appropriate sudo privileges.
  • Filesystem Busy: When a filesystem cannot be remounted, use -m to avoid remounting issues.
  • Incorrect Quota Files: Sometimes, quota files could be corrupted. Use -c to recreate them if needed.

Integration

quotacheck can be combined with quotaon and quotaoff for robust quota management:

  1. Enabling Quotas After Check:

    quotacheck -uga /home && quotaon /home
    
  2. Script to Check Quotas and Report Usage:

    #!/bin/bash
    quotacheck -ugav
    repquota -a > /var/log/quota_report.txt
    
  3. Scheduled checks with cron:

    • Add to cron jobs to run daily:
      0 1 * * * /usr/sbin/quotacheck -ugav
      
  • quota: Display disk usage and limits.
  • quotaon, quotaoff: Enable/disable disk quotas.
  • repquota: Summarize quotas for a filesystem.

Additional Resources:

  • Quota management details can be further explored in the official Linux filesystem documentation or utilizing man pages (man quotacheck).

These tools collectively help in maintaining a healthy file system by ensuring that users and groups adhere to specified usage quotas.