-->
Page 311
want them to play a game.
There are other restrictions you can put in place. The next section shows you how you can limit how much of your system's hard drive can be used.
On large, multiuser systems, disk quotas are not only a way of life, but a necessity. You can impose disk quotas on your Linux system, and you should, especially if you worry about your disk space, or if you're afraid the users will create huge files and overrun your hard drive. You can also use disk quotas as a warning device (and maybe justification for a new hard drive?). This section explains how to start, set, and stop disk quotas.
Quota Manipulation with the quota, quotaon, and quotaoff Commandsquota | To report on disk quotas |
quotaon | To turn on and set disk quotas for users |
quotaoff | To turn off disk quotas for users |
repquot | Also reports on quotas |
edquota | Edits user quotas |
quotacheck | Checks filesystem on quota usage |
This book won't go into all the details of these programs (read the manual pages), but this section shows you how to set a disk quota for the new user you created. The first thing you must do is to enable quotas for your Linux filesystem. This involves editing the filesystem table, fstab, in the /etc/ directory. Be careful! You must make sure you don't make any other changes, or you could cause boot problems. You have been warned!
Make sure you're logged in as root, then use your favorite text editor to open the fstab file, and edit the line containing the entry for your Linux partition, for example:
# <device> <mountpoint> <filesystemtype> <options> <dump> <fsckorder> /dev/hda3 / ext2 defaults 1 1
Now add a command and the word usrquota to the word default, for example:
/dev/hda3 / ext2 defaults,usrquota 1 1
Save the /etc/fstab file. Next, use the touch command to create a file called quota.user, and make the file read-write enabled, for example:
# touch /quota.user # chmod 600 /quota.user
Page 312
After you have done this, reboot your computer by using the shutdown command with the -r, or restart, option. Log back in as root, and use the edquota command, found under the /usr/sbin directory, along with the -u option, to edit quotas for your new user, for example:
# edquota -u cloobie
The edquota command will read in the user.quota file under your root, or /, directory. This file is normally a binary file, but edquota will open the file using the text editor defined in your EDITOR environment variable. If you don't like the default editor, you can first specify your own temporarily as follows:
# EDITOR=/usr/bin/pico;export EDITOR
This will make the edquota command use the pico text editor. When edquota runs, you'll end up in your editor with the following text:
Quotas for user cloobie: /dev/hda3: blocks in use: 58, limits (soft = 0, hard = 0) inodes in use: 41, limits (soft = 0, hard = 0)
Although it is not important to understand all the information here (see Albert M.C. Tam's mini-HOWTO, Quota, under the /usr/doc/HOWTO/mini for details), you can easily set both the maximum number of files and the maximum size of your user's directory. To set limits to 3_5MB for disk space, and between 500 and 1000 files, use
Quotas for user cloobie: /dev/hda3: blocks in use: 58, limits (soft = 3000, hard = 5000) inodes in use: 41, limits (soft = 500, hard = 1000
Save the file. Then, as a last step, you must set a grace period using edquota again, but this time with the -t option. Your new user will be warned if the lower, or "soft," limit is exceeded, for example:
# edquota -t cloobie
You can then set the grace-period warnings for either exceeding the number of files or disk use, for example:
Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: /dev/hda3: block grace period: 1 days, file grace period: 1 days
If you want to warn your user right away, use a grace period of one day (you can also use minutes or seconds). Finally, you can use the quota command to check the new quota, for example:
# quota cloobie Disk quotas for user cloobie (uid 502): Filesystem blocks quota limit grace files quota limit grace /dev/hda3 58 3000 5000 41 500 1000
Using disk quotas may sometimes be necessary. If your disk space is at a premium, this could be one way to manage your hard drive resources.