Kernel, Cron, and User Administration, Part 1 - Quota Management Commands
(Page 5 of 11 )
The next step is to create quota files. For user and group quotas, you’ll need the aquota.user and aquota.group files in the selected filesystem. You need these files before you can activate actual quotas. You no longer need to create those files; once you’ve remounted the desired directory, you can create them directly with the appropriate quotacheck command. For the /home directory described earlier, you’d use the following commands:
# mount -o remount /home
# quotacheck -avugm
The quotacheck -avugm command automatically scans /etc/mtab, which includes the mounted directories from /etc/fstab. The options for quotacheck are
- -a Scans all filesystems with quotas enabled by checking /etc/mtab.
- -v Performs a verbose scan.
- -u Scans for user quotas.
- -g Scans for group quotas.
- -m Remounts the scanned filesystem.
This will check the current quota information for all users, groups, and partitions. It stores this information in the appropriate quota partitions. You should also find the aquota.user and aquota.group files in the configured directory. If you’re configuring quotas on the /home directory, you can check that it worked with the following command:
# ls -l /home/aquota.*
Using edquota to Set Up Disk Quotas To specify disk quotas, you need to run the edquota command. This edits the aquota.user or aquota.group file with the vi editor. In our example, we will pretend we have a user named nancy, and we want to restrict how much disk space she is allowed to use. We type the following command to edit their quota records:
# edquota -u nancy
This command launches the vi editor and opens the quota information for user nancy, as shown in Figure 5-1.
Disk Quotas for user nancy (uid 507):
FileSystem blocks soft hard inodes soft
hard 52 0 0 13 0
/dev/hdd1
0
Figure 5-1 Quota information
The quota information is formatted strangely. There are actually seven columns. The lines are wrapped. In this case, the filesystem with the quota is mounted on partition /dev/hdd1. There are soft and hard limits for both inodes and files. By default, soft and hard limits of 0 means that there are no limits for nancy.
We can see that nancy is currently using 52 blocks and has 13 files (inodes) on this partition. Each block takes up 1KB of space; thus, user nancy’s files total 52KB. We want to set a limit so that nancy does not take more than 20MB of space with her files.
First, we need to elaborate on the meaning of soft and hard limits.
- Soft limit This is the maximum amount of space a user can have on that partition. If you have set a grace period, then this will act as an alarm. The user will then be notified he is in quota violation. If you have set a grace period, you will also need to set a hard limit. A grace period is the number of days a user is allowed to be above the given quota. After the grace period is over, the user must get under the soft limit to continue.
- Hard limit Hard limits are necessary only when you are using grace periods. If grace periods are enabled, this will be the absolute limit a person can use. Any attempt to consume resources beyond this limit will be denied. If you are not using grace periods, the soft limit is the maximum amount of available to each user.
In our example, we will set our user an 18MB soft limit and a 20MB hard limit. As shown in Figure 5-2, this is written as a number of 1KB blocks in the quota file.
Disk Quotas for user nancy (uid 507):
FileSystem blocks soft hard inodes soft
hard
/dev/hdd1 52 18000 20000 13 0
0
Figure 5-2 Quotas with hard and soft limits
Note that we have not limited user nancy’s use of inodes. She is still able to use as many inodes (thus as many files) as she likes. To implement these quotas, we must save these settings. Assuming you’re still using the default vi editor, the :wq command does this job nicely.
We will also give user nancy a seven-day grace period, if and when she exceeds the soft limit. She has that amount of time to get back under the soft limit. To set the grace period for all users, run the edquota -t command. The result should look similar to what you see in Figure 5-3.
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem block grace period Inode grace period
/dev/hdd1 7 days 7 days
Figure 5-3 Quota grace period
Here, Linux has provided us with the default of seven days for both inodes and block usage. That is, a user may exceed his soft limit on either resource for up to seven days. After that, further requests by that user to use files will be denied. Our user nancy would have to delete files to get her total disk block consumption under 18MB before she could create new files or grow existing files. You can edit the grace period directly, using vi commands. To activate the new grace period, just save the file.
There is a quirk to quota grace periods. When you use edquota and specify the grace period, you cannot have a space between the number and the unit (for example, 7days, not 7 days). Fortunately, the quota system in RHEL 3 automatically fixes this problem.
ON THE JOB! In older versions of Red Hat Linux, a space between the number and the unit would lead to a quota error. The edquota command allows you to use an already configured user’s quota as a template for new users. To use this feature, you need to add the following switch and options, -p configured_user arguments:
# edquota -up nancy michael randy donna
This command will not provide any output, but it will take the quota configuration settings of user nancy and apply them to michael, randy, and donna. You can list as many users as you want to edit or apply templates to.
You can also set up quotas on a per-group basis. To do this, simply run edquota with the -g group_name argument. Here, group_name would need to be a valid group as specified in the /etc/group file.
# edquota -g nancy
This opens the block and inode quota for group nancy, as shown in Figure 5-4.
Disk Quotas for group nancy (uid 507):
FileSystem blocks soft hard inodes soft
hard
/dev/hdd1 52 0 0 13 0
0
Figure 5-4 Group quota
This is part one from the fifth chapter of Red Hat Certified Engineer Linux Study Guide (Exam RH302), fourth edition, by Michael Jang. (McGraw-Hill/Osborne, 2004, ISBN: 0-07-225365-7). Check it out at your favorite bookstore today. Buy this book now.
|
Next: Automating Quota Settings >>
More Administration Articles
More By McGraw-Hill/Osborne