quota

quota

Disk quotas allow the administrator to limit the disk space used by users and

groups. The quota command can be used to create quotas for users stored

in /etc/passwd and for groups in /etc/group. Usually the restrictions are placed on

the directories that users have in /home but they can be applied to the filesystem

in /etc/fstab. Some Linux systems do not support quotas.

 

Quota limits are of five types:

1. Per-User Hard Limit - once limit is achieved the user will not be able to write to the disk

2. Per-User Soft Limit - once the user reaches the limit a warning is given and the user has

time to finish the write but the warning remains on the terminal until it is cleaned up

3. Per-Group Hard Limit - once limit is achieved the group, including all individual users

will not be able to write to the disk

4. Per-Group Soft Limit - once the group reaches the limit a warning is given and all the

users have time to finish the write but the warning remains on the terminals until it is

cleaned up

5. Grace Period - once the soft limit is reached a Grace Period is initiated, and the user/users have a set number of hours, days, etc. until it turns into a hard limit

 

 

 

Quota

 

Installation of Quotas
The kernel must be able to support quotas. By default quotas are setup on most systems, this is an example of a Enterprise Server found in /boot/config-2.4.*** The config file (kernel) name will be different on each system. Please note that if the config file does not have quota enabled it may have to be changed in the kernel.

 

# File systems

#

CONFIG_FS_POSIX_ACL=y

CONFIG_QUOTA=y

 

 

Check to see if the quota rpm is installed

 

rpm -qi quota

 

Find a list of tools that are associated with quota

rpm -ql quota

 

/sbin/quotaon /fs This command will enable quotas for the filesystem.

/sbin/quotaoff /fs This command will disable quotas for the filesystem.

/usr/sbin/edquota username Edit the quotas for a specific user.

/usr/bin/quota Users can review the quotas set for them.

/usr/sbin/repquota Generates a report of disk usage by users.

/sbin/quotacheck Checks for quota usage

 

Setting Up Quotas

When the computer starts there is a script that will check to see if

/etc/fstab has been modified to provide quotas. This script will run the two commands needed to enable quotas; quotacheck and quotaon.

The script is found at /etc/rc.sysinit if you would like to view it.

 

 

Edit /etc/fstab

In order for a directory to use quotas it must be set up in the
/etc/fstab file. Be careful, make a backup of /etc/fstab before making modifications. In the example below the upper line shows the default, the lower line shows the modifications to begin the process of setting up quotas. The second line sets up user quotas, the third line sets up user quotas and group quotas.

 

 

/dev/hda7 /home ext3 defaults 1 2

#####################################

/dev/hda7 /home ext3 exec,dev,suid,rw,usrquota 1 2

#####################################

/dev/hda7 /home ext3 exec,dev,suid,rw,usrquota,grpquota 1 2

 

Once the changes have been made, (you made a backup right?), then restart the system to remount the quotas after being set up.

 

Starting the Quota System

The following options can be employed with the command quotacheck to gain information for managing the server, run only when the filesystem is unmounted in most cases.

 

-a scan for quotas by checking the /etc/mtab file

-v verbose scan

-u scan for user quotas

-g scan for group quotas

-m remounts a scanned filesystem

 

If you run a command like this (only run it on an umounted system), it will check all the above:

 

quotacheck -avugm

 

This command will check the /etc/mtab.

 

If the quotas were set up correctly there should be a aquota file in the directory that the quotas were setup on. Try this command for quotas on the /home directory, assuming /home is on a separate partition.

 

ls -la /home/aquota.*

 

You should see the output that the file exists.

 

 

Set Up User Quotas

The edquota command is what you will use to edit a users quota. This command actually edits the aquota.user file if you are editing for users and the aquota.group file if you will be setting limits on groups.

 

edquota -u fred

 

This command will open up fredÅ› quota file which has seven columns.

The top of the file will list the userÅ› name and UID.

 

The first column will list the directory filesystem. This is usually in the format of the partition that the quotas are on. An example:

/dev/hda6

 

The second column lists the number of blocks that are currently used by the user. These are 1KB blocks. An example:

4485296

 

This is almost 4.5 GB.

 

The next two columns represent the soft and hard limits for the users. 0 means that the user has no limits. 4000000 in the soft limit means that when the user reaches 4 GB they will activate a message that they are in violation of their quota. The grace period set in days gives this user the opportunity to make changes to move under the soft limit. Once the grace period is over, the user will be forced to make the necessary changes.

 

The hard limit represents a boundary that the user will not be able to cross no matter what. Administrators do not need to set hard limits unless the grace period is used. If an administrator does not use the grace period the result will be that the soft limit will be the boundary for users.

 

Typically, users appreciate a reasonable boundary with a warning system so that in the middle of an important project they are not forced with deleting data before they can save. Of course there are always the users that will push it to the limit.

 

Creating a Profile:

One advantage of the edquota command is that an administrator is able to create one quota for a user and then use that user as a template or profile for other users. Create a profile for a user, save and test the quota to be sure it is correct. Then use the edquota command to roll out that profile to other users. Here is an example.

Disk quotas for user fred (uid 505):

Filesystem blocks soft hard inodes soft hard

/dev/sdc1 34000 35000 40000 234 0 0

 

 

Here fred represents the profile so that once fredÅ› quota file is saved it may be used to create other user quotas. Use this command to create similar quotas for harry and mary.

 

edquota -up fred harry mary

 

The edquota command may also be used to create group limits on space used. The -g option will provide this feature.

 

edquota -g office

 

The first thing to do is to make sure the group has been created. In the example, office group is used to create a limit for the whole of office users. Note this is a SCSI drive in the example not a IDE drive.

 

 

Disk quotas for user office (gid 509):

Filesystem blocks soft hard inodes soft hard

/dev/sdc1 34000 35000 40000 234 0 0

 

The quotacheck command must be run on a regular basis to maintain the quotas that have been set.

 

 

Quota Options:

 

quotacheck

The purpose of this command is to scan the filesystem for disk usage, create, check and repair quota files.

 

The quotacheck command should be run when the system boots and when it mounts non-valid filesystems. This command should only be run when the quotas are turned off as it can cause damage to data in quota files.

 

-a check for quotas in /etc/mstab

-v verbose

-u check for user quotas

-g check for group quotas

-m remount the directory that scanned for quotas

-d debugging mode

-f forces checking and writing of new quota files when the quotas are enabled....not recommended to use!

 

quota

This command checks the disk usage and the limits of users and groups.

 

-u check for user quotas

-g check for group quotas

-q show filesystems where the user is over the limit

 

 

repquota
This command creates a summary of quotas on a filesystem.

-u report on quotas for a user

-a report on quotas for entire filesystem

-v report all quotas even if no usage

-g report quotas fro groups

 

edquota
This provides a way to edit quotas for users.

 

-u edit user

-g edit group

-t edit soft limit time

 

View Quotas

The quota command displays the quota limits on users or groups. quota -u user quota followed by username quota -g group quota followed by group name Example: quota -u mike Returned info: Disk quotas for user mike (uid 500): none