Linux administration

Set and View Disk Quotas

Nguyen Hai Chau
Vietnam National University

What are Quotas?

  • Quotas are a way of limiting the amount of disk space that users may take up
  • Some organisations (perhaps those with untrusted external users) absolutely need to ensure that:

    • No user can prevent other users from using a reasonable amount of disk space
    • No user can impede the correct functioning of the system
  • Some organisations don't need to worry about this — their users can be trusted not to abuse the system

Hard and Soft Limits

  • Quotas have hard limits and soft limits
  • A user can exceed the soft limit without retribution
    • But only for a certain period of time — the grace period
    • The user is also warned that the soft limit has been exceeded
  • A hard limit may never be exceeded
  • If a user tries to exceed a hard limit (or an expired soft limit), the attempt fails

    • The program gets the same error message it would if the filesystem itself had run out of disk space
  • Grace periods are set per-filesystem

Per-User and Per-Group Quotas

  • Most quotas are set per-user
    • Each user has his or her own soft limit and hard limit
  • Quotas can also be set per-group
    • A group can be given a soft limit and hard limit
  • Group quotas apply to all users in a group
  • If a group hard limit has been reached, no user in the group may use more space
    • Including users who have not yet reached their individual quota

Block and Inode Limits

  • Quotas can be set for blocks
    • Limits the amount of data space that may be used
  • Quotas can also be set for inodes
    • Limits the number of files that may be created

Displaying Quota Limits: quota

  • The quota command displays quota limits
  • Specifying a username or the name of a group will show information about their quotas:
# quota fred
  • The -v option will show full information about all quotas, even where there are no limits

Options in /etc/fstab

  • The options in /etc/fstab specify which filesystems should have quota enabled
    • Add the option usrquota to enable user quotas
    • Use grpquota to enable group quotas
    • Either or both can be used for each filesystem:
/dev/hda1   /   ext2    defaults
/dev/hdb1   /home   ext2    defaults,usrquota
/dev/hdb2   /work/shared    ext2    defaults,usrquota,grpquota

Other options

  • The filesystems with quota enabled should have files called quota.user and quota.group in their root directories

  • The following commands will create them:

# touch /partition/quota.{user,group}
# chmod 600 /partition/quota.{user,group}

Enabling Quota: quotaon

  • quotaon turns on quota support
    • Can only be done by root
    • Support must be compiled into the kernel, but this is done by default on all modern distributions
  • quotaoff disables quota support
  • For example, to turn on quota on all filesystems:
# quotaon -av
  • Quota can be turned on or off for individual filesystems

Changing Quota Limits: setquota

  • Command line program to alter quota limits for a user or group
  • Specify the name of a user or group with -u username or -g groupname
  • Specify the filesystem to alter after the -u or -g option
  • Finally, the limits to set must be specified in the following order:
    • Soft limit for blocks
    • Hard limit for blocks
    • Soft limit for inodes
    • Hard limit for inodes
  • Setting any limit to 0 will remove that limit

edquota

  • edquota allows quotas to be edited interactively, in a text editor
    • The file in the text editor will be a temporary file
    • edquota will read it back in when the editor terminates
  • Use the -g option to edit group quotas
  • Some versions of Red Hat have a bug where you need to delete an extraneous space before the time unit when doing edquota -t

repquota

  • The repquota command prints information about the quota limits assigned to each user
    • Also shows actual number of blocks and inodes used
  • Use the -a option for information on all filesystems, or specify the filesystem on the command line
  • Use -g to show group quotas
  • Use -v for more complete information