How to configure file system quotas
This article explains how to enable file systems quotas on HP-UX Operating Environment.
Using disk quotas allows the administrator to control disk space usage by limiting the number of files users can create and the total number of system blocks they can use.
You implement disk quotas on a local file system and its users by placing soft limits and hard limits on users’ file system usage. Soft limits are limits that can only be exceeded for a specified amount of time. A hard limit can never be exceeded. If users fail to reduce usage below soft limits before the specified time limit or reach a hard limit, they will be unable to create files or increase the size of existing files.
Typically, you will set disk quotas on file systems that would otherwise become full without limitations. For example, to prevent users from using /tmp or /var/tmp as storage, set the soft limits small and the time limits for remedial action short.
Because disk quota statistics reside in memory, using disk quotas rarely impairs performance. However, the time required to reboot a crashed system will take longer because of the time required to run /usr/sbin/quotacheck whenever the system is booted.
NOTE: You cannot use SAM to perform disk quota tasks.
Setting Up and Turning On Disk Quotas
Here are the main steps for setting up and turning on disk quotas:
1. Mount the file system.
Suppose you want to implement quotas on /home, which is accessed via the device file /dev/vg00/lvol3. This file system will be mounted automatically at bootup if it is listed in your /etc/fstab file. If the file system is not mounted, enter:
# mount /dev/vg00/lvol3 /home
2. Create a quotas file.
Use the cpset command to create an empty file named quotas within the directory. This file will contain, in binary form, the limits and usage statistics for each user to be limited in creating files within the file system. For example, to install the quotas file for the mounted /home file system, enter:
# cpset /dev/null /home/quotas 600 root bin
In this example, /dev/null specifies that the file created is empty, /home/quotas specifies that the file quotas is to be in /home directory, and 600 root bin is the mode, owner, and group of the file. For syntax, see cpset(1M).
NOTE: To control the size of the quotas file, refrain from using large user identification numbers (UIDs). This will not be a concern if you use SAM to add users because SAM selects the UIDs in numerical order.
Set the user quotas
Use the /usr/sbin/edquota command to set or subsequently modify quotas of individual users. The edquota utility creates a temporary file for a text representation of disk quotas for a user and invokes an editor. Once you enter the quotas and leave the editor, the text is converted to binary form for storing within the quotas file. For syntax, see edquota(1M).
To set uniform limits for users in a file system, create limits for one or more initial users, then apply those limits to the remaining users. For example, the following shows how to assign limits for a typical user whose home directory is within the file system /home and then implement those limits to other users. For this example, assume these limits: a soft limit of 10,000 blocks, a hard limit of 12,000 blocks, a soft limit of 250 files, and a hard limit of 300 files.
Set the limits for a prototype user, patrick.
1. Invoke the quota editor:
# edquota patrick
2. To input the disk-usage limits, type the following:
fs /home blocks (soft = 10000, hard = 12000) inodes (soft = 250, hard = 300)
There must be one such line for every file system with a quotas file. Be sure to type the line exactly as shown in order to get the correct spacing between items. Bad formatting and/or typographical errors may cause incorrect setting of quotas.
Save the file. This updates the quotas file. Exit the editor.
3. Apply the prototype user’s limits to other users of the /home file system:
# edquota -p patrick alice ellis dallas
This assigns the limits of the prototype user, patrick, to the other users, alice, ellis, and dallas.
NOTE: When removing a user from the system, run edquota and set the user’s limits to zero. Thus, when the user is removed from the system, there will be no entry for that user in the quotas file.
4. Use the edquota command with the -t option to set the time limit users will have to take corrective action when exceeding a soft limit. Unlike limits on files and blocks, a single time limit applies uniformly to all users of a file system.
For example, to edit the quotas file and set a time limit of 10 days for file system blocks and 15 days for files in the file system /home, enter the following:
Invoke the quota editor:
# edquota -t
5. To input a time limit, type the following:
fs /home blocks time limit = 10.00 days,files time limit = 15.00 days
Be sure to type the line as shown with the correct spacing between items. Bad formatting and typographical errors may cause incorrect setting of quotas.
The default time limit for both file system blocks and files is seven days. You can specify the default time limits by entering zeros in fields where you would specify the limits. For example, to implement default limits for the /home file system, enter this line:
fs /home blocks time limit = 0, files time limit = 0
Turn on quota
Disk quotas can be enabled in any of the following ways:
1. Turn on disk quotas when rebooting.
If you want disk quotas to be turned on automatically when the system starts up, add the quota option to the file system entry in the /etc/fstab file. For example:
/dev/vg00/lvol3 /home hfs rw,suid,quota 0 2
2. Turn on disk quotas by re-mounting the file system.
Disk quotas can be turned on when you mount a file system with the quota option of the mount command. To do this, you must first unmount the file system. For example:
# umount /dev/vg00/lvol3mount -o quota /dev/vg00/lvol3 /home
Note that if you have already added the quota option to the /etc/fstab file (see above), you do not need to specify the quota option to the mount command. Instead, simply specify one of the following commands:
# mount -a
# mount /home
After remounting the file system, you must run quotacheck on the file system to update usage information stored in the quotas file.
3. Turn on disk quotas using the quotaon command.
If you want to enable quotas on a file system, but are unable to unmount the file system (perhaps because it is being used), follow these steps. (These steps will also work for the root (/) file system.)
Use the /usr/sbin/quotaon command to turn on disk quotas for a mounted file system for which disk quotas are set up, but not currently turned on. The file quotas must exist in the mount directory of the file system. For example, issuing the command
# quotaon -v /home
Starts quotas on the /home file system. The -v (verbose) option generates a message to the screen listing each file system affected. This command has no effect on a file system for which quotas are already turned on.
You can also specify the -a option, which turns on disk quotas for all mounted file systems listed in the file /etc/fstab that include the quota option. See quotaon(1M) for more information.
4. Check the file system for consistency. For example:
# quotacheck /dev/vg00/lvol3
See quotacheck(1M) for syntax.
Turning Off Disk Quotas
When you unmount a file system, HP-UX automatically turns off disk quotas.
You can turn off disk quotas for a file system without unmounting that file system by using the /usr/sbin/quotaoff command. However, using this command is not recommended because once quotas are turned off, actual disk usage may become inconsistent with the usage information stored in the quotas file, thus requiring quotacheck when quotas are re-enabled. See quotaoff(1M) for more information.
What To Do When Exceeding a Soft Limit
After creating a file that causes a soft limit quota to be exceeded, a user on locally mounted file systems will see a message similar to this:
WARNING: disk quota (/home) exceeded
The user has a limited time to remove unnecessary files. The user will receive no further warnings until he attempts to exceed hard limits or allows the time to expire without reducing usage to normal levels. Once a user corrects his usage levels, the system removes any time constraints.
NOTE: Users of remote file systems (such as NFS mounts) will not receive soft limit warnings. Thus, users having quotas on remote file systems can reach hard limits without prior warning, so they should frequently check their usage levels using the /usr/bin/quota command. For details on checking levels, see quota(1). Only a user with superuser privileges can use the user option of the quota command to view specific usage and quota information about other users.
What To Do When Exceeding a Hard Limit
When users reach a hard limit or fail to reduce their usage below soft limits within the allotted time, an error message appears on their terminal. If a user reaches a block limit, the following message appears:
DISK LIMIT REACHED - WRITE FAILED
If he reaches a file limit, he sees:
FILE LIMIT REACHED - CREATE FAILED
How to recover from reaching a hard limit depends on whether or not the user was using an editor when the message was received. The next sections describe both cases.
When Not Using an Editor
When not using an editor, follow these steps:
Abort the process or processes that are using the file system.
Remove enough files to lower the number of files and/or file system blocks below the soft limits established in the quotas file.
The quota command reports whether a user is above or below the limit in the specific file system. To determine the current number of blocks in files and directories, use the du or the find command (see du(1) and find(1) for details).
Run the aborted processes again.
When Using an Editor
When using an editor, the user needs to remove files to a level below the quota limits and still preserve the recent changes made to the file being edited. If possible, a user can do this by opening a new window or by logging in from a remote node. This way, the user can get a shell prompt without aborting the editor. Alternatively, the user can follow these steps:
Write the file to another file system (such as /var/tmp) where quotas are not exceeded.
Exit the editor.
Remove files until the remaining number is well below the file and/or file system block quotas determined by the soft limits.
Move the file back into the original file system.
Or, when using a job-control shell:
Go to the shell and type a “suspend” character (for example, pressing the CTRL and Z keys at the same time) to suspend the editor.
Remove files until the number remaining is below the file and/or file system block quotas.
Type fg at the shell prompt to return to the editor.