Quota: Disk Usage Management

Contents

1. Overview
1.1. Prerequisites
2. Installing Quota Tools
3. Configuring Quotas
3.1. Preparing the Mount Point
3.2. Preparing User Groups
3.3. Setting the Quota
3.3.1. Setting the User Quota
3.3.2. Setting the Group Quota
3.3.3. The 'setquota' Command
4. Quota Reports
4.1. repquota
4.2. warnquota
5. quotactl - C API

1. Overview

In certain situations the ability to limit the amount of disk space a user or group of users may use is invaluable. This can be achieved in Fedora using the quota tools. This tutorial will walk you through the installation and configuration of a quota system on the /home mount point. You can replace /home with any other mount point you want to enable quotas on.

1.1. Prerequisites

This tutorial assumes that /home is mounted from it's own partition and is not part of the root filesystem. It also assumes that this partition is already formatted and ready to use.

2. Installing Quota Tools

In order to enable disk quotas you need the quota tools installed. To check, run the command:

[root@wrkstn ~]$ rpm -q quota
quota-3.13-1.2.1

If the above command returns 'package quota is not installed' then you need to install the quota tools as root with the command:

[root@wrkstn ~]$ yum install quota

This will install the quota tools and any required packages. Once it is complete you are ready to setup the quotas.

3. Configuring Quotas

3.1. Preparing the Mount Point

Before you can set quota limits on a mount point, you need to mount it with the usrquota and grpquota options.

Open /etc/fstab in a text editor and find the line that references the /home mount point. In the options part of the line add 'usrquota,grpquota'.

/dev/hda2 /home ext3 defaults,usrquota,grpquota 0 0

Save the file and re-mount /home to activate the quota options.

[root@wrkstn ~]$ umount /home
[root@wrkstn ~]$ mount /home

3.2. Preparing User Groups

This section will guide you through creating a group of users which can be used for a group quota. If your users are already in a group you want to use, or you want to manage quotas on a per-user level you can skip this step.

Group Quotas

Group quotas set the maximum usage for the entire group. It does not set the limit for each individual user within the group.

First, create a new group:

[root@wrkstn ~]$ groupadd quotausers

Add users to the group with the command:

[root@wrkstn ~]$ usermod -G quotausers username

Note: If the users are logged in, the users will not become part of the new group until they next log off and back in.

3.3. Setting the Quota

Before you can set a quota on a mount, you need to create the necessary database files, as root run the following command:

[root@wrkstn ~]$ quotacheck -cug /quota

The "-c" option is used to create the database files, this only needs to be done once, upon future use of this command you can ommit this option.

Running the ls command should now show two new files: 'aquota.group' and 'aquota.user'.

[root@wrkstn ~]$ ls -1 /home
aquota.group aquota.user cjsavage lost+found

3.3.1. Setting the User Quota

To set the quota for a user, use the edquota command. The command below will set the quota for user 'cjsavage'.

[root@wrkstn ~]$ edquota -f /home cjsavage

The edquota command will open a text file in your default text editor:

Disk quotas for user cjsavage (uid 500):
  Filesystem      blocks     soft     hard    inodes     soft     hard
  /dev/hda2       672592        0        0     11290        0        0

The 'blocks' and 'inodes' entries show how many blocks (Kb) and inodes (files/directories) are currently being used by the user/group. They should not be changed and are shown as a reference only.

The 'soft' option specifies how much space to let the user/group consume before issuing a quota warning. The 'hard' option is the maximum amount space that can be consumed.

To change the user's warning to 5Mb, quota to 10Mb, and allow the user to create 100 files with a warning at 75 files, change the file to:

Disk quotas for user cjsavage (uid 500):
  Filesystem      blocks     soft     hard    inodes     soft     hard
  /dev/hda2       672592     5000    10000     11290       75      100

3.3.2. Setting the Group Quota

The process for creating group quotas is the same as for users except you pass edquota the "-g" option.

[root@wrkstn ~]$ edquota -g quotausers

The edquota command will open a text file in your default text editor:

Disk quotas for group quotausers (uid 519):
  Filesystem      blocks     soft     hard    inodes     soft     hard
  /dev/hda2       672592        0        0     11290        0        0

Make the following changes to apply the same quota limit as for the individual users shown above.

Disk quotas for group quotausers (uid 519):
  Filesystem      blocks     soft     hard    inodes     soft     hard
  /dev/hda2       672592     5000    10000     11290       75      100

3.3.3. The 'setquota' Command

You can also set quotas using the setquota command line utility. This is more appropriate if you want to change quotas from a script.

The commands below will set the quota warning to 5Mb, the quota limit to 10Mb, and will allow the user/group to create 100 files with a warning at 75.

For the user 'cjsavage', use the command:

[root@wrkstn ~]$ setquota -u cjsavage 5000 10000 75 100 /home

For the group 'quotausers', use the command:

[root@wrkstn ~]$ setquota -g quotausers 5000 10000 75 100 /home

4. Quota Reports

The quota tools include two commands for reporting information about quota usage.

4.1. repquota

The repquota command prints a list of users and their usage on the specified mount. The command should be run as root.

[root@wrkstn ~]# repquota /home
*** Report for user quotas on device /dev/md2
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --    9832       0       0             25     0     0
cjsavage  --    2248    5000   10000              9    75   100

To get a report for a specific group, provide the "-g" option:

[root@wrkstn ~]# repquota -g /home
*** Report for group quotas on device /dev/md2
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --    9832       0       0             25     0     0
quotausers --   3552    5000   10000             17    75   100

If you want a report for everything, use the "-a" option.

4.2. warnquota

The warnquota command is used to send e-mails to users who have exceeded their quota. Running the command without any parameters will email users that go over the limit.

[root@wrkstn ~]# warnquota

In order for an e-mail to be issued for groups that have gone over their quota, the group must be assigned a user responsible for it. This is done in the file '/etc/quotagrpadmins'.

#
# This is a sample groupadmins file (/etc/quotagrpadmins)
#
#  Comments begin with hash in the beginning of the line

# In this file you specify users responsible for space used by the group
users: root
quotausers: cjsavage

Once this is set, executing the warnquota command with the "-g" option will send the mail to use 'cjsavage'.

[root@wrkstn ~]# warnquota -g /home

You can customize the messages by editing '/etc/warnquota.conf'.

5. quotactl - C API

Quota tools also provides a C API that allows you to create your own quota tools. It is beyond the scope of this tutorial however Mike Chirico's Linux Quota Tutorial covers it in some detail.