Showing posts with label Quota System Configuration. Show all posts
Showing posts with label Quota System Configuration. Show all posts

Configuring Disk Quotas | Disk Quotas

 Disk Quotas:

Disk space can be restricted by implementing disk quotas which alert a system administrator before a user consumes too much disk space or a partition becomes full..

Disk quotas can be configured for individual users as well as user groups. This makes it possible to manage the space allocated for user-specific files (such as email) separately from the space allocated to the projects a user works on (assuming the projects are given their own groups).

In addition, quotas can be set not just to control the number of disk blocks consumed but to control the number of inodes (data structures that contain information about files in UNIX file systems).

Because inodes are used to contain file-related information, this allows control over the number of files that can be created.
The quota RPM must be installed to implement disk quotas. 

Configuring Disk Quotas

To implement disk quotas, use the following steps:
  1. Enable quotas per file system by modifying the /etc/fstab file.
  2. Remount the file system(s).
  3. Create the quota database files and generate the disk usage table.
  4. Assign quota policies.
Each of these steps is discussed in detail in the following sections.

Enabling Quotas

As root, using a text editor, edit the /etc/fstab file.
Edit /etc/fstab
For example, to use the text editor vim type the following:
# vim /etc/fstab
Add the usrquota and/or grpquota options to the file systems that require quotas:
Add quotas
/dev/VolGroup00/LogVol00 /         ext3    defaults        1 1 
LABEL=/boot              /boot     ext3    defaults        1 2 
none                     /dev/pts  devpts  gid=5,mode=620  0 0 
none                     /dev/shm  tmpfs   defaults        0 0 
none                     /proc     proc    defaults        0 0 
none                     /sys      sysfs   defaults        0 0 
/dev/VolGroup00/LogVol02 /home     ext3    defaults,usrquota,grpquota  1 2 
/dev/VolGroup00/LogVol01 swap      swap    defaults        0 0 . . .
In this example, the /home file system has both user and group quotas enabled.

Note
The following examples assume that a separate /home partition was created during the installation of Red Hat Enterprise Linux. The root (/) partition can be used for setting quota policies in the /etc/fstab file.

Remounting the File Systems

After adding the usrquota and/or grpquota options, remount each file system whose fstab entry has been modified. If the file system is not in use by any process, use one of the following methods:
  • Issue the umount command followed by the mount command to remount the file system. Refer to the man page for both umount and mount for the specific syntax for mounting and unmounting various file system types.
  • Issue the mount -o remount file-system command (where file-system is the name of the file system) to remount the file system. For example, to remount the /home file system, the command to issue is mount -o remount /home.
If the file system is currently in use, the easiest method for remounting the file system is to reboot the system.

Creating the Quota Database Files

After each quota-enabled file system is remounted run the quotacheck command.
The quotacheck command examines quota-enabled file systems and builds a table of the current disk usage per file system. The table is then used to update the operating system's copy of disk usage. In addition, the file system's disk quota files are updated.
To create the quota files (aquota.user and aquota.group) on the file system, use the -c option of the quotacheck command.
Create quota files
For example, if user and group quotas are enabled for the /home file system, create the files in the /home directory:
# quotacheck -cug /home
The -c option specifies that the quota files should be created for each file system with quotas enabled, the -u option specifies to check for user quotas, and the -g option specifies to check for group quotas.
If neither the -u or -g options are specified, only the user quota file is created. If only -g is specified, only the group quota file is created.
After the files are created, run the following command to generate the table of current disk usage per file system with quotas enabled:
# quotacheck -avug
The options used are as follows:
a
Check all quota-enabled, locally-mounted file systems
v
Display verbose status information as the quota check proceeds
u
Check user disk quota information
g
Check group disk quota information
After quotacheck has finished running, the quota files corresponding to the enabled quotas (user and/or group) are populated with data for each quota-enabled locally-mounted file system such as /home.

Assigning Quotas per User

The last step is assigning the disk quotas with the edquota command.
To configure the quota for a user, as root in a shell prompt, execute the command:
# edquota username 
Perform this step for each user who needs a quota. For example, if a quota is enabled in /etc/fstab for the /home partition (/dev/VolGroup00/LogVol02 in the example below) and the command edquota testuser is executed, the following is shown in the editor configured as the default for the system:
Disk quotas for user testuser (uid 501):   
Filesystem                blocks     soft     hard    inodes   soft   hard   
/dev/VolGroup00/LogVol02  440436        0        0     37418      0      0
 
Note
The text editor defined by the EDITOR environment variable is used by edquota. To change the editor, set the EDITOR environment variable in your ~/.bash_profile file to the full path of the editor of your choice.
The first column is the name of the file system that has a quota enabled for it. The second column shows how many blocks the user is currently using. The next two columns are used to set soft and hard block limits for the user on the file system. The inodes column shows how many inodes the user is currently using. The last two columns are used to set the soft and hard inode limits for the user on the file system.
The hard block limit is the absolute maximum amount of disk space that a user or group can use. Once this limit is reached, no further disk space can be used.
The soft block limit defines the maximum amount of disk space that can be used. However, unlike the hard limit, the soft limit can be exceeded for a certain amount of time.

That time is known as the grace period. The grace period can be expressed in seconds, minutes, hours, days, weeks, or months.
If any of the values are set to 0, that limit is not set. In the text editor, change the desired limits.
Change desired limits
For example:
Disk quotas for user testuser (uid 501):   
Filesystem                blocks     soft     hard   inodes   soft   hard   
/dev/VolGroup00/LogVol02  440436   500000   550000    37418      0      0

To verify that the quota for the user has been set, use the command:
# quota username
Disk quotas for user username (uid 501): 
   Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
     /dev/sdb    1000*   1000    1000               0       0       0

Assigning Quotas per Group

Quotas can also be assigned on a per-group basis. For example, to set a group quota for the devel group (the group must exist prior to setting the group quota), use the command:
# edquota -g devel
This command displays the existing quota for the group in the text editor:
Disk quotas for group devel (gid 505):   
Filesystem                blocks    soft     hard    inodes    soft    hard   
/dev/VolGroup00/LogVol02  440400       0        0     37418       0       0
Modify the limits, then save the file.
To verify that the group quota has been set, use the command:
# quota -g devel

Setting the Grace Period for Soft Limits

If a given quota has soft limits, you can edit the grace period (i.e. the amount of time a soft limit can be exceeded) with the following command:
# edquota -t
This command works on quotas for inodes or blocks, for either users or groups.
Important
While other edquota commands operate on quotas for a particular user or group, the -t option operates on every file system with quotas enabled. 

Managing Disk Quotas

If quotas are implemented, they need some maintenance — mostly in the form of watching to see if the quotas are exceeded and making sure the quotas are accurate.
Of course, if users repeatedly exceed their quotas or consistently reach their soft limits, a system administrator has a few choices to make depending on what type of users they are and how much disk space impacts their work. The administrator can either help the user determine how to use less disk space or increase the user's disk quota.

Enabling and Disabling

It is possible to disable quotas without setting them to 0. To turn all user and group quotas off, use the following command:
# quotaoff -vaug 
If neither the -u or -g options are specified, only the user quotas are disabled. If only -g is specified, only group quotas are disabled. The -v switch causes verbose status information to display as the command executes.
To enable quotas again, use the quotaon command with the same options.
For example, to enable user and group quotas for all file systems, use the following command:
# quotaon -vaug 
To enable quotas for a specific file system, such as /home, use the following command:
# quotaon -vug /home 
If neither the -u or -g options are specified, only the user quotas are enabled. If only -g is specified, only group quotas are enabled. 

 Reporting on Disk Quotas


Creating a disk usage report entails running the repquota utility.
Output of repquota command
For example, the command repquota /home produces this output:
*** Report for user quotas on device /dev/mapper/VolGroup00-LogVol02 
Block grace time: 7days; Inode grace time: 7days
   Block limits   File limits  
User  used soft hard grace used soft hard grace 
---------------------------------------------------------------------- 
root      --      36       0       0              4     0     0 
kristin   --     540       0       0            125     0     0 
testuser  --  440400  500000  550000          37418     0     0

To view the disk usage report for all (option -a) quota-enabled file systems, use the command:
# repquota -a 
While the report is easy to read, a few points should be explained. The -- displayed after each user is a quick way to determine whether the block or inode limits have been exceeded. If either soft limit is exceeded, a + appears in place of the corresponding -; the first - represents the block limit, and the second represents the inode limit.
The grace columns are normally blank. If a soft limit has been exceeded, the column contains a time specification equal to the amount of time remaining on the grace period. If the grace period has expired, none appears in its place. 

Keeping Quotas Accurate

When a file system fails to unmount cleanly (due to a system crash, for example), it is necessary to run quotacheck. However, quotacheck can be run on a regular basis, even if the system has not crashed. Safe methods for periodically running quotacheck include:
Ensuring quotacheck runs on next reboot
 
Note: Best method for most systems
This method works best for (busy) multiuser systems which are periodically rebooted.
As root, place a shell script into the /etc/cron.daily/ or /etc/cron.weekly/ directory—or schedule one using the crontab -e command—that contains the touch /forcequotacheck command.

This creates an empty forcequotacheck file in the root directory, which the system init script looks for at boot time. If it is found, the init script runs quotacheck. Afterward, the init script removes the /forcequotacheck file; thus, scheduling this file to be created periodically with cron ensures that quotacheck is run during the next reboot.
For more information about cron, refer to man cron

Running quotacheck in single user mode

An alternative way to safely run quotacheck is to boot the system into single-user mode to prevent the possibility of data corruption in quota files and run the following commands:
# quotaoff -vaug /file_system
# quotacheck -vaug /file_system
# quotaon -vaug /file_system

Running quotacheck on a running system

If necessary, it is possible to run quotacheck on a machine during a time when no users are logged in, and thus have no open files on the file system being checked. Run the command quotacheck -vaug file_system ;

this command will fail if quotacheck cannot remount the given file_system as read-only. Note that, following the check, the file system will be remounted read-write.
Warning
Running quotacheck on a live file system mounted read-write is not recommended due to the possibility of quota file corruption.
Refer to man cron for more information about configuring cron

References

For more information on disk quotas, refer to the man pages of the following commands:
  • quotacheck
  • edquota
  • repquota
  • quota
  • quotaon
  • quotaoff

Setup User and Group Disk Quota on UNIX / Linux

On Linux, you can setup disk quota using one of the following methods:
  • File system base disk quota allocation
  • User or group based disk quota allocation
On the user or group based quota, following are three important factors to consider:
  • Hard limit – For example, if you specify 2GB as hard limit, user will not be able to create new files after 2GB
  • Soft limit – For example, if you specify 1GB as soft limit, user will get a warning message “disk quota exceeded”, once they reach 1GB limit. But, they’ll still be able to create new files until they reach the hard limit
  • Grace Period – For example, if you specify 10 days as a grace period, after user reach their hard limit, they would be allowed additional 10 days to create new files. In that time period, they should try to get back to the quota limit.

1. Enable quota check on filesystem

First, you should specify which filesystem are allowed for quota check.

Modify the /etc/fstab, and add the keyword usrquota and grpquota to the corresponding filesystem that you would like to monitor.

The following example indicates that both user and group quota check is enabled on /home filesystem
# cat /etc/fstab  
LABEL=/home    /home   ext2   defaults,usrquota,grpquota  1 2
Reboot the server after the above change.

2. Initial quota check on Linux filesystem using quotacheck

Once you’ve enabled disk quota check on the filesystem, collect all quota information initially as shown below.
# quotacheck -avug
quotacheck: Scanning /dev/sda3 [/home] done
quotacheck: Checked 5182 directories and 31566 files
quotacheck: Old file not found.
quotacheck: Old file not found.
In the above command:
  • a: Check all quota-enabled filesystem
  • v: Verbose mode
  • u: Check for user disk quota
  • g: Check for group disk quota
The above command will create a aquota file for user and group under the filesystem directory as shown below.
# ls -l /home/

-rw-------    1 root     root        11264 Jun 21 14:49 aquota.user
-rw-------    1 root     root        11264 Jun 21 14:49 aquota.group

3. Assign disk quota to a user using edquota command

Use the edquota command as shown below, to edit the quota information for a specific user.
For example, to change the disk quota for user ‘ramesh’, use edquota command, which will open the soft, hard limit values in an editor as shown below.
# edquota madesh
Disk quotas for user madesh (uid 500):
  Filesystem           blocks       soft       hard     inodes     soft     hard
  /dev/sda3           1419352          0          0       1686        0        0

Once the edquota command opens the quota settings for the specific user in a editor, you can set the following limits:
  • soft and hard limit for disk quota size for the particular user.
  • soft and hard limit for the total number of inodes that are allowed for the particular user.

4. Report the disk quota usage for users and group using repquota

Use the repquota command as shown below to report the disk quota usage for the users and groups.
# repquota /home 
*** Report for user quotas on device /dev/sda3
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --  566488       0       0           5401     0     0
nobody    --    1448       0       0             30     0     0
ramesh    -- 1419352       0       0           1686     0     0
john      --   26604       0       0            172     0     0

5. Add quotacheck to daily cron job

Add the quotacheck to the daily cron job. Create a quotacheck file as shown below under the /etc/cron.daily directory, that will run the quotacheck command everyday. This will send the output of the quotacheck command to root email address.
# cat /etc/cron.daily/quotacheck
quotacheck -avug

About the Disk Quota System | Setup of the Disk Quota System

About the Disk Quota System

A disk quota system, providing a method for controlling disk space usage, has been implemented in AIX Versions 3.2 and 4.x.

This system is based on the Berkeley Disk Quota System and allows assignment of quotas for the AIX journaled file system only.

Disk quotas may be assigned based on three parameters and can be modified with the edquota command. The three parameters are:
  • a user's or group's soft limits - the number of 1KB disk blocks or files below which the user should remain
  • a user's or group's hard limits - the maximum number of disk blocks or files the user can accumulate
  • quota grace period - There is a grace period during which the soft limit can be exceeded (the default is one week). If the user fails to reduce usage below the soft limit during the specified time, the system interprets the soft limit as the maximum allocation for that user. No further storage is allocated to the user. The user may correct this condition by removing enough files to reduce usage to be below the soft limit.
The disk quota system tracks user and group quotas in the quota.user and quota.group files. These files reside in the root directories of file systems that have quotas assigned. These files are created with the edquota and quotacheck commands and are readable with the quota commands.

When to Use the Quota System

Typically, quotas are only used for file systems that contain user home directories and files. It is recommended that disk quotas never be assigned for the /tmp file system.

A system administrator would consider implementing the disk quota system under the following conditions:
  • The system has limited disk space.
  • More file system security is desired.
  • Disk usage levels by users are large.

Setup of the Disk Quota System

To set up the disk quota system, you must have root-user-level authority.
  1. Determine the file systems to which you will apply quotas (user directories default to the /home file system).  
  2. The stanza that applies to the /home file system (or to another file system to which you are applying quotas) should be identified and edited in the /etc/filesystems file so that it includes quota, userquota, and groupquota configuration attributes. 
  3. Here is an example stanza line that enables user quotas:
    quota = userquota  
    In a file system that has both user and group quotas enabled, the entry 
    might look similar to the following:
       /home: 
             dev       = /dev/hd1 
             vol       = "/home" 
             mount     = true 
             check     = true 
             free      = false 
             vfs       = jfs 
             log       = /dev/hd8 
             quota     = userquota,groupquota 
             options   = rw  
    
  4. You have the option of specifying disk quota file names. The default files are quota.user and quota.group, located in the root directory of the file system enabled with quotas. 
  5. You may specify alternate names or directories for these quota files with the userquota and groupquota attributes. Here is a sample:
       /home: 
             dev        = /dev/hd1 
             vol        = "/home" 
             mount      = true 
             check      = true 
             free       = false 
             vfs        = jfs 
             log        = /dev/hd8 
             quota      = userquota,groupquota 
             userquota  = /home/myquota 
             groupquota = /home/myquota 
             options    = rw  
    
  6. If the file systems are not mounted, mount them. 
  7. Use the edquota command to set the user or group soft and hard limits. The edquota command has the following syntax:
    User Quotas
    edquota  -u  ( -p Proto-UserName ) UserName .. 
    
    Group Quotas  
    edquota  -g ( -p Proto-GroupName ) GroupName ... 
    
    When -p is used with the -u flag, it duplicates the quotas established for a prototypical user for each specified user.

    The edquota command creates and edits quotas. It creates a temporary file that contains each user's and group's current disk quotas. It determines the list of file systems with established quotas from the /etc/filesystems file.

    The edquota command invokes the vi editor (or the editor specified by the EDITOR environment variable) on the temporary file, so that quotas can be added and modified.
    The fields that are displayed in the temporary file are:.

    • Blocks in use: The current number of 1KB file system blocks used by this user or group 
    • Inodes in use: The current number of files used by this user or group
    • Block soft limit: The number of 1KB blocks the user or group will be allowed to use during normal operations
    • Block hard limit: The total amount of 1KB blocks the user or group will be allowed to use, including temporary storage during a quota grace period
    • Inode soft limit: The number of files the user or group will be allowed to create during normal operations
    • Inode hard limit: The total number of files the user or group will be allowed to create, including temporary files created during a quota grace period 
    NOTE: A hard limit with a value of 1 indicates that no allocations are permitted. A soft limit with a value of 1, in conjunction with a hard limit with a value of 0, indicates that allocations are permitted only on a temporary basis.

    More information on the edquota command can be found in the edquota man page or in the softcopy and hardcopy product documentation.

    Here is a sample edquota command and editing session:
       #edquota -u bill 
          Quotas for user bill: 
          /home: blocks in use: 16, limits (soft = 10, hard = 30) 
                 inodes in use: 4, limits (soft = 0, hard = 0) 
    
     Change User or Group Grace Period 
    #edquota  -t  -u   |  -g  
    -t changes the grace period during which quotas can be exceeded before a soft limit is imposed as a hard limit. The default value of the grace period is 1 week. When invoked with the -u flag, the grace period is set for all file systems with user quotas specified in the /etc/filesystems file. When invoked with the -g flag, the grace period is set for all file systems with group quotas specified in the /etc/filesystems file.   
  8. NOTE: If the grace period is changed and repquota shows that some users have already reached their old grace period - before the new grace period can take effect for these users - these users must reduce their quotas to below their soft limits to reset the old grace period. In the future if these users exceed their soft limits, the new grace period will be in effect.
    Also, if another user (like root) exceeds the quotas of some other user, the grace period as reported by the requota command will show (none). The overlimit must be corrected by the user. Then when the quota limit is exceeded the next time, the grace period will be seen with the correct value.
  9. The quota system must be enabled with the quotaon command, whose purpose is to turn file system quotas on and off. The syntax for the quotaon and quotaoff commands are:
    quotaon  [ -g  -u  -v ] { -a | FileSystem ... } 
    quotaoff [ -g  -u  -v ] { -a | FileSystem ... } 
      The quotaon command enables disk quotas for one or more file systems specified by the FileSystem parameter. The specified file system must have an entry in the /etc/filesystems file and must be mounted. The quotaon command looks for the quota.user and quota.group default files in the root directory of the associated file system. These file names may be changed in the /etc/filesystems file.
    By default, both user and group quotas are enabled. The related flags or options are:
    -a
    enables or disables all file systems that are read-write and have disk quotas, as indicated by the /etc/filesystems file. When used with the -g flag, it enables or disables only group quotas in the /etc/filesystems file; when used with the -u flag, it enables or disables only user quotas in the /etc/filesystems file.
    -g
    specifies that only group quotas are enabled or disabled.
    -u
    specifies that only user quotas are enabled or disabled.
    -v
    prints a message for each file system in which quotas are turned on or off.
    Examples:
    • To enable user quotas for the /home file system, enter:
         quotaon -u /home 
      
    • To disable user and group quotas for all file systems in the /etc/filesystems file and print a message, enter:
         quotaoff -v -a  
      
  10. Use the quotacheck command to check the quota files against actual disk usage. It is recommended that you do this each time you first enable quotas on a file system and after you reboot the system.  WARNING: It is recommended that the specified file system not be active while the quotacheck command is running. Executing quotacheck on an active file system (that is, one in which users have open files) can result in corrupt or incorrect quota data. Run quotacheck only from single-user mode or from the /etc/rc file during boot up (as shown in subsequent discussion).
    The quotacheck process can be automated during boot up with the following entries added near the end of the /etc/rc file (after execution of the fsck command but before the "multi-user initialization completed" message):
    echo " Enabling file system quotas" 
    /usr/sbin/quotacheck [-g -u -v] { -a | FileSystem...} 
    /usr/sbin/quotaon [-g -u -v] { -a | FileSystem...} 
    
    The quotacheck command checks for file system consistency and has the following format and syntax:
    quotacheck  [-g  -u  -v]  { -a | FileSystem ...} 
    
    By default, both user and group quotas are checked.
    The flags are
    -a
    checks all file systems with disk quotas and read-write permissions indicated by the /etc/filesystems file.
    -g
    checks group quotas only.
    -u
    checks user quotas only.
    -v
    reports discrepancies between the calculated and recorded disk quotas.
    Examples:
    • To check the user and group quotas in the /home file system, enter:
         quotacheck /home 
      
    • To check only the group quotas in the /home file system, enter:
         quotacheck -g /home 
      
  11. You can use the repquota command to print a summary of quotas and disk usage for a file system. If the -a flag is specified instead of a file system, the repquota command prints the summary for all file systems enabled with quotas. By default,
    repquota  [-v  -g  -u] { -a | FileSystem ...} 
      -a    specifies that quotas are printed for all file systems 
            enabled. 
      -g    specifies that only group quotas are printed. 
      -u    specifies that only user quotas are printed. 
      -v    prints a header line before the summary of quotas 
            for each file system. 
    
    Example:
    To print a summary of user quotas in the /home file system, enter:
       repquota -u /home 
    
    The system prints the following information:
                          Block limits               File limit 
    User          used   soft   hard  grace    used  soft  hard  grace 
    root     --     16      0      0              2     0     0 
    lanczi   --     12   3000   5000              3  3600  4500 
    biff     --      8     20     40              2    30    39 
    bill     --     16     10     30  7days       4    11    30