Disk quota management

You may need to set a maximum disk quota per user, so that one user cannot fill up the whole system with his documents/garbage.

A disk quota is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems.

There are two basic types of disk quotas. The first, known as a usage quota or block quota, limits the amount of disk space that can be used. The second, known as a file quota or inode quota, limits the number of files and directories that can be created.

  1. install package quota
    sudo apt-get install quota
  2. add option usrquota to the /etc/fstab partition you want to restrict
  3. remount that partition to make the changes effective
    sudo mount -o remount /dev/[device]
    Note: ensure nobody is working on that parition, if in doubt run init 1 to switch to runlevel 1
  4. create quota config files in the topmost directory of the filesystem
    sudo touch aquota.user
    sudo touch aquota.group
  5. make linux read the quota config file
    quotacheck -vagum
  6. edit users’s quota information
  7. edquota -u user
    this invokes VI editor, thus you may have to refer to this post on how to use VI
    BLOCKS is the amount of space (in 1k blocks) the user is currently using
    INODES is the number of files the user currently owns
    SOFT LIMIT is the maximum blocks/inodes a quota user may have on the partition when the grace period is set. If set to 0 limits are disabled.
    HARD LIMIT is the maximim blocks/inodes a quota user may have on a partition. If set to 0 limits are disabled.
  8. enforce the quotas. Linux does not constantly monitor the disk quota usage. To make it check it periodically set a CRON JOB to run a script like this

    #! /bin/bash
    quotackeck -vagu

    on a few minutes/hours basis

  9. grace periods. When a user exceeds the soft quota limit its is warned by the system, however he is still able to create new files, until he reaches the HARD LIMIT quota, for a limited amount of time (which is the grace period).
    this can be set this way
    edquota -t
  10. edit grout quota
    edquota -g
  11. getting quota reports
    repquota /dev/[device]