C H A P T E R 7 |
File System Quotas |
File system quotas control the amounts of online and total disk space that can be consumed by a specific user, a group of users, or an admin set in a file system. An admin set is a site-determined group of users.
Quotas help control the size of a file system by limiting the amount of space and the number of inodes each user can consume. Quotas can be especially useful on file systems that contain user home directories. After quotas are enabled, you can monitor usage and adjust the quotas as needs change.
This chapter contains the following sections:
You can set file system quotas on a user, group, or a site-defined admin set basis. You, the system administrator, can set limits on the number of files, the number of blocks online, and the total number of blocks.
A file system provides a user with blocks for data and inodes for files. Each file uses one inode, and file data is stored in a disk allocation unit (DAU). DAU sizes are determined at the time the file system is created. Quotas account for disk usage in multiples of 512 bytes.
The following sections provide background information about using quotas:
TABLE 7-1 shows the terms that are used extensively in this chapter's quota documentation.
You can set quotas according to user ID, group ID, or an administrator's site-specific grouping. This site-specific grouping is called an admin set ID. You can use an admin set ID, for example, to identify a collection of users working on a project for which file system quotas are imposed.
Quotas are enabled when the system detects the presence of one or more quota files in the file system's root directory and the quota mount option is in effect. Note that the quota mount option is enabled by default, so you must not have disabled quotas by specifying the noquota mount option. If you mount the file system with noquota in effect, quotas are disabled. For more information about mount options, see the mount_samfs(1M) man page.
Each quota file contains a sequence of records. Record zero is the record for the system administrator's quotas. The system administrator's resource usage is accumulated in record zero. System administrator quotas are never enforced, but you can use any record, including the system administrator's record, as a template for subsequent records in the quota file. For more information about this practice, see To Enable or Change Limits for Users, Groups, or Admin Sets Using an Existing Quota File.
Record one is the record in the quota file for user one, group one, or admin set ID one, depending on the type of quota file. You can edit record one and all subsequent records in order to set different quotas for different users. TABLE 7-2 shows the quota file names and the quotas they enable in /root.
You can set default quota limits for users by editing record zero in the quota file and allowing the values in record zero to be used as the initial quota settings for all other users. By default, if user quota limits have not been set specifically, the system uses the values in record zero.
You can set both soft and hard limits. A hard limit specifies a fixed amount of system resources available for use, and the system never allows a user to exceed this limit. A soft limit specifies a level of system resource use that can be exceeded temporarily. The soft limits are never larger than the hard limits. If a new user attempts to allocate resources beyond his or her hard limit, the operation is aborted. In this case, the operation (typically a write(2) or creat(2)) fails and generates an EDQUOT error.
After a user exceeds a soft limit, a timer starts, and the user enters a grace period. While the timer is ticking, the user is allowed to operate above the soft limit but cannot exceed the hard limit. After the user goes below the soft limit, the timer is reset. If the grace period ends and the timer stops without the user having gone below the soft limit, the soft limit is then enforced as a hard limit.
For example, assume that a user has a soft limit of 10,000 blocks and a hard limit of 12,000 blocks. If the user's block usage exceeds 10,000 blocks and the timer exceeds the grace period, this user is no longer able to allocate more disk blocks on that file system until their usage drops below the 10,000-block soft limit.
You, the administrator, can use the samquota(1M) command to see the timer value. The squota(1) command is a user version of the samquota(1M) command. The squota(1) user command contains options that a user can specify to obtain information about quotas that pertain to them.
You can use quotas to limit the amount of data that a user is allowed to have on archive media in Sun StorEdge QFS and Sun StorEdge SAM-FS file systems.
Example. The stage(1) command brings data online from archive media. It is possible for a user quota to be exceeded when the stage(1) command is invoked at the system level in the following way:
A user quota is observed when a user issues the stage(1) -w command, as follows:
The system stages files until the user's quota is met. After that time, no more files are staged.
It is possible for a user to exceed an inode quota, without using any blocks, by creating all empty files. It is also possible for a user to use only one inode and still exceed the block quota by creating a file that is large enough to consume all data blocks in the user's quota.
File system quotas are expressed in terms of the number of 512-byte blocks that a user can allocate. However, disk space is allocated to user files in terms of DAUs. The DAU setting is specified by the -a allocation_unit option to the sammkfs(1M) command. It is preferable to set a block quota to a multiple of the file system DAU. If this is not done, users can allocate only up to the block count, rounded down to the nearest DAU.
You can enable quotas through a process that includes editing system files, creating quota files, and entering various quota commands.
TABLE 7-3 shows the commands used when manipulating quotas.
When it is run, the samfsck(1M) command checks the file system to make sure that usage values recorded in the quota files match the actual file system usage totals. If they do not match, the samfsck(1M) command issues notices, and it updates all existing, incorrect quota records if a file system repair is performed.
The following sections provide more details on how to configure a file system to use quotas and how to enable quotas.
Before you enable quotas, you should determine how much disk space and how many inodes to allocate to each user. If you want to be sure that the total file system space is never exceeded, you can divide the total size of the file system between the number of users. For example, if three users share a 100-megabyte slice and have equal disk space needs, you could allocate 33 megabytes to each. In environments in which not all users are likely to push their limits, you might want to set individual quotas so that they add up to more than the total size of the file system. For example, if three users share a 100-megabyte slice, you could allocate 40 megabytes to each.
You can use the following quota commands, in the formats shown, for displaying quota information:
To Configure a New File System to Use Quotas |
The following procedure shows how to configure a new file system to use quotas. This procedure applies if you are creating a new file system at this time and no files currently reside in the file system.
To configure an existing file system to use quotas, see To Configure an Existing File System to Use Quotas.
To create the file system, either follow the steps outlined in the Sun StorEdge QFS and Sun StorEdge SAM-FS Software Installation and Configuration Guide or use the examples in Configuration Examples to guide you through creating the mcf file, creating the mount point, initializing the file system, and so on.
3. Use the mount(1M) command to mount the file system.
Mount the file system using the mount(1M) command, as follows:
4. Use the dd(1M) command to create the quota file(s).
The arguments to this command differ depending on the type of quota you are creating, as follows:
For more information about the dd(1M) command, see the dd(1M) man page.
5. Use the umount(1M) command to unmount the file system.
Unmount the file system in which the quota files have been created using the umount(1M) command. For example:
The file system needs to be unmounted so it can be remounted and have its quota files read at mount time. For more information about the umount(1M) command, see the umount(1M) man page.
6. Use the samfsck(1M) command to perform a file system check.
Run the samfsck(1M) command on the file system. For example, the following command performs a file system check. The -F option resets the in-use values in the quota files.
7. Use the mount(1M) command to remount the file system.
Quotas are enabled when the system detects the presence of one or more quota files in the root directory of a file system.
For more information about the mount(1M) command, see the mount_samfs(1M) man page.
8. Use the samquota(1M) command to set quotas for users, groups, or admin sets.
Subsequent sections in this chapter provide procedures and show examples of this process. For more information about the samquota(1M) command, see the samquota(1M) man page.
To Configure an Existing File System to Use Quotas |
This procedure applies if you are creating quotas for a file system that is already populated with files.
If you are configuring a new file system to use quotas, see To Configure a New File System to Use Quotas.
1. Use the su(1) command to become superuser.
2. Use the mount(1M) command to ensure that the file system is mounted.
Examine the /etc/mnttab file using the mount(1M) command with no arguments, as follows:
3. Use the cd(1) command to change to the root directory.
Change to the root directory of the file system for which quotas are to be enabled. For example:
4. Verify that quotas do not already exist on the file system.
From the root directory, use the ls(1) -a command to retrieve the list of files in this directory. If at least one quota type (u, g, or a) is established for a file system, you can establish any other quota type later. Be careful not to modify existing quota files when adding new ones later.
If any of the following files are present, quotas are, or previously have been, enabled for this file system: .quota_u, .quota_g, .quota_a.
5. Use the dd(1M) command to create the quota file(s).
Create the quota files for the type(s) of quota(s) you wish to enforce. Determine the highest existing ID numbers of the types of quotas you wish to enforce. Make the initial, zero quota files large enough to hold the record for those IDs; each quota file record requires 128 bytes.
Example 1. If you want to enable admin set quotas, and the highest admin set ID in use on the file system is 1024, the calculation is as follows:
Example 2. If you want to enable group quotas, and group IDs up to 2000 are in use, the calculation is as follows:
Example 3. If you want to enable user ID quotas, and user IDs up to 4799 are in use, the calculation is as follows:
For more information about the dd(1M) command, see the dd(1M) man page.
6. Use the umount(1M) command to unmount the file system in which the quota files have been created.
The file system needs to be unmounted so it can be remounted and have its quota files read at mount time. For more information about unmounting a file system, see Unmounting a File System.
7. Use the samfsck(1M) command to perform a file system check.
Use the samfsck(1M) -F command to perform a file system check. The samfsck(1M) command updates the quota files with correct, current usage information.
Note - The command in this step updates only the records already allocated in the quota files. |
8. Use the mount(1M) command to remount the file system in which the quota files have been created.
The system enables quotas when it detects the presence of one or more quota files in the /root directory.
For more information about the mount(1M) command, see the mount_samfs(1M) man page.
9. Use the samquota(1M) command to set quotas for users, groups, or admin sets.
Subsequent sections in this chapter provide procedures and show examples of this process. For more information about the samquota(1M) command, see the samquota(1M) man page.
To Assign Admin Set IDs to Directories and Files |
1. Use the su(1) command to become superuser.
Use the samchaid(1M) command to change the admin set IDs for the directory or file, as follows:
For more information about the samchaid(1M) command, see the samchaid(1M) man page.
An infinite quota is a kind of special quota. Users with infinite quotas are never denied access to any available file system resource. You can set infinite quotas on a user, group, or admin set basis by setting both the hard block and hard file limits to zero. The file system treats an infinite quota as a special quota. You can set infinite quota values into record zero of the user, group, or admin set ID quota files, and from there they can become the default values for new users, groups, or admin set IDs.
Use the samquota(1M) command to set an infinite quota.
For example, the following command sets an infinite quota:
You can use the samquota(1M) command to set infinite quotas for particular users, groups, or admin set IDs by setting zero values for all hard and soft limits. CODE EXAMPLE 7-2 shows how to set infinite quotas.
You can use the samquota(1M) command to enable a default quota for a user, group, or admin set. This is accomplished by setting default limits into user, group, or admin set zero (0).
To Enable Default Quota Values for Users, Groups, or Admin Sets |
Use the samquota(1M) command to set an infinite quota.
For example, the following samquota(1M) command sets default quotas for all admin set IDs:
On first reference, the preceding command sets any user's uninitialized admin set quota limits as follows:
Note that if a quota record already exists, the existing values remain in effect. This occurs, for example, if the admin group already has blocks assigned to it.
You can set similar default quotas for users or groups by specifying -U 0 or -G 0, respectively, in place of -A 0.
For more information about the samquota(1M) command, see the samquota(1M) man page.
You can use the samquota(1M) command to enable a set of limits for a particular user, group, or admin set.
Use the samquota(1M) command to set limits for users, groups, or admin sets.
CODE EXAMPLE 7-3 shows commands that enable various limits.
For more information about the samquota(1M) command, see the samquota(1M) man page.
To Enable or Change Limits for Users, Groups, or Admin Sets Using an Existing Quota File |
After quotas are established, you can use an existing quota file as a template when creating limits for another user, group, or admin set. The following procedure shows this. You can also use this procedure to change any of the quota settings.
1. Use the samquota(1M) command to retrieve a quota file.
Use the -e option with one or more of the following additional options: -U userID, -G groupID, or -A adminsetID. Direct the output to a temporary file.
# samquota -G sam -f 200:s:o -f 300:h:o -f 200:s:t -f 300:h:t \ -b 40000:s:o -b 60000:h:o -b 40M:s:t -b 60M:h:t -t 0s:o -t 0s:t /sam6 |
You can use any temporary file. In Step 2, you use an editor to change one or more fields, so you can use a group quota entry as a template to create a user quota entry. CODE EXAMPLE 7-4 shows how to create and retrieve file quota.group to use as a template.
2. Use an editor to edit the file from Step 1.
For example, CODE EXAMPLE 7-5 shows the file that was generated in Step 1 opened in the vi(1) editor. This file also shows that group ID 101 is changed to 102. This has the effect of generating a command to copy the quotas set for group 101 to group 102.
3. Save the file and exit the editor.
4. Execute the file using the shell.
This step applies the changes made in the editor. For example:
In this example, the -x option directs the shell to echo the commands it executes. You can omit the -x option if desired.
In similar fashion, you can use this procedure to generate quota commands that copy quota limits between users, groups, admin IDs, file systems, and other entities.
After you have enabled disk and inode quotas, you can check these quotas. The samquota(1M) command is an administrator command that generates a quota report on an individual user, group, or admin set. The squota(1) command is a user command that enables users to check their own individual quotas. TABLE 7-4 shows commands you can use to check quotas.
To Check for Exceeded Quotas |
The following procedure shows how to check quotas for excess usage.
2. Use the samquota(1M) command to display the quotas in effect.
Use the samquota(1M) command in one of the following ways to display quotas for mounted file systems in which quotas are enabled:
For userID, specify the numeric user ID or user name of the user whose quotas are being examined.
For file, specify a specific file system for the selected user, group, or admin set. The file argument can also be the name of any file in the file system. Typically, file is the name of the root directory of the file system.
Example 1. CODE EXAMPLE 7-6 retrieves user hm1259's quota statistics in the sam6 file system on the server and displays output indicating that this user is not exceeding his quota.
Example 2. CODE EXAMPLE 7-7 retrieves user memil's quota statistics in all mounted Sun StorEdge QFS and Sun StorEdge SAM-FS file systems and displays output indicating that this user is exceeding the quota. Note the plus sign (+) in the Blocks row of the output. The plus sign would appear in the Files row, too, if the soft quota limit were being exceeded for files.
If a hard limit has been exceeded, or if the soft limit has been exceeded and the grace period has expired, the offending In Use field is marked with an asterisk character (*). If a quota record's limits are determined to be inconsistent, (for example if a soft limit is larger than a hard limit), an exclamation point is used to mark the field, and all allocation operations are prevented.
TABLE 7-5 shows the fields in the samquota(1M) output.
For groupID, specify the numeric group ID or the group name for the group of users whose quotas are being examined. For example, the following command retrieves user quota statistics for the group turtles in the qfs3 file system:
For adminsetID, specify the numeric admin set ID of the site-specific administrator set whose quotas are being examined. For example, the following command retrieves user quota statistics for the admin set 457 in all mounted Sun StorEdge QFS and Sun StorEdge SAM-FS file systems:
You can change quotas to adjust the amount of disk space or number of inodes allocated to users. You can also remove quotas from users or from an entire file system. The following sections describe how to change and remove quotas. The topics are as follows:
To Change the Grace Period |
You can use the samquota(1M) command to change the soft time limit grace period.
1. Use the samquota(1M) command to retrieve quota statistics.
You can use the samquota(1M) command on a user, group, or admin set basis. CODE EXAMPLE 7-8 shows how to retrieve quota statistics.
# samquota -U userID [ file ] # samquota -G groupID [ file ] # samquota -A adminsetID [ file ] |
TABLE 7-6 shows the arguments to these commands.
2. Examine the output from the samquota(1M) command.
Examine the output and determine what the new limits should be.
3. Use the samquota(1M) command to change the soft time limit grace period.
CODE EXAMPLE 7-9 shows using the samquota(1M) command options to use to change the soft time limit grace period.
# samquota -U userID -t interval file # samquota -G groupID -t interval file # samquota -A adminID -t interval file |
TABLE 7-7 shows the arguments to these commands.
Example. Assume that you want to change the grace period for user memil. CODE EXAMPLE 7-10 shows the samquota(1M) command used to verify the quotas and its output.
You enter the following command to lower the soft time limits:
CODE EXAMPLE 7-11 shows the samquota(1M) command to use to verify the new quotas.
If a user has exceeded their soft quota limit, changing the grace period itself does not modify the expiration timer of any grace periods that have already started. If the grace period is already in effect, you can use the samquota(1M) command to modify the grace period in one of the following ways:
Example. CODE EXAMPLE 7-12 retrieves information about group sam and shows that this group is over its soft limit.
CODE EXAMPLE 7-13 clears the timer so it starts counting the next time a user in group sam attempts to allocate a block or file in /sam6.
CODE EXAMPLE 7-14 resets the grace period.
CODE EXAMPLE 7-15 expires the grace period.
CODE EXAMPLE 7-16 sets a very long expiration period.
To Inhibit Additional File System Resource Allocations |
When the file system detects that quota values are not consistent for a user, group, or admin set, it prevents that user, group, or admin set from using any more system resources. You can inhibit file system resource allocations by creating inconsistent quota values. The samquota(1M) command detects these inconsistent values, and reports them in its output. For example, the software inhibits further allocation if the hard block or file limits are lower than the soft block or file limits, or if a user's soft limit is larger than the user's hard limit.
The file system treats an inconsisent quota setting as a special quota. You can set inconsistent quota values into record zero of the user, group, or admin set ID quota files, and from there they can become the default values for new users, groups, or admin set IDs.
The following procedure shows how to inhibit further system resource allocations for a user, group, or admin set.
2. Obtain, save, and examine current quota information.
CODE EXAMPLE 7-17 shows how to use the samquota(1M) command to retrieve current group quota information for group sam and write it to a backup file.
To obtain quota information about a user quota, specify the -U userID option in place of the -G option. To obtain quota information about an admin set quota, specify the -A adminID option in place of the -G option.
3. Use the samquota(1M) command to set soft quotas to nonzero quotas and hard quotas to zero quotas.
Use the samquota(1M) command to reset the quotas to invalid values. The following command sets the quotas for group sam to be inconsistent:
To make the quotas for users or admin sets inconsistent, specify the -U userID or -A adminID options in place of the -G option.
4. Use the samquota(1M) command to verify your changes.
Use the samquota(1M) command to verify that the quota has been correctly changed. The following example obtains quota information for a group quota of the group sam:
Enter the samquota(1M) command again to verify the changed quotas. CODE EXAMPLE 7-18 shows this.
In the preceding output, a zero quota is in effect. Note the exclamation point characters (!) to indicate the over-quota condition in the output.
5. Use the sh(1) and samquota(1M) commands to restore the group's quota.
CODE EXAMPLE 7-19 shows the commands to restore and verify the changed quotas.
To perform this operation on a user quota, specify the -U userID option in place of the -G option. To perform this operation on an admin set quota, specify the -A adminID option in place of the -G option.
To Remove a File System's Quotas |
To remove or disable quotas for a file system, you need to remove quota specifications from the mount process. The following procedure shows how to disable quotas for a file system.
1. Use the su(1) command to become superuser.
2. Add the noquota mount option to the /etc/vfstab or samfs.cmd file. (Optional)
Perform this step only if you have the quota mount option in the /etc/vfstab or samfs.cmd file.
Use a viewer, such as vi(1) or cat(1) to examine the /etc/vfstab or samfs.cmd file for the presence of the quota mount option.
If this mount option is present, edit the file and remove the quota mount option.
Note - Beginning with the Sun StorEdge QFS and Sun StorEdge SAM-FS 4.1 releases, you do not need to use the /etc/vfstab and samfs.cmd files for enabling or disabling quotas. |
3. Use the umount(1M) command to unmount the file system.
If the file system is mounted, use the umount(1M) command to unmount the file system.
If you have difficulty unmounting the file system, see Unmounting a File System.
4. Remount the file system using the mount(1M) command.
If you did not perform Step 2, include the noquota option on the mount(1M) command.
5. Dispense with the quota files.
If you expect to reinstate the quota feature at a later date, do not destroy the quota files. To preserve the quota files and reinstate quotas at a later date, unmount the file system, run the samfsck(1M) command with its -F option on the file system, and remount the file system again with the quota mount option. The quota mount option can be specified in either the /etc/vfstab file or in the samfs.cmd file as a mount option, or it can be specified on the mount(1M) command with the -o quota option.
If you do not expect to reinstate the quota feature at a later date, or if you want to reclaim the space consumed by the quota files, use the rm(1) command to remove the .quota_u, .quota_g, and .quota_a files. For example:
To Correct Quotas |
2. Use the umount(1M) command to unmount the file system.
If the file system is mounted, use the umount(1M) command to unmount the file system.
If you have difficulty unmounting the file system, see Unmounting a File System.
3. Use the samfsck(1M) -F command to perform a file system check.
The samfsck(1M) command updates the quota files with correct, current usage information. Note, however, that it updates only records already allocated in the quota files. For example:
4. Use the mount(1M) command to remount the file system.
Copyright © 2004, Sun Microsystems, Inc. All rights reserved.