CATEGORII DOCUMENTE |
Managing Disk Usage with Quotas
Introduction
You may eventually need to restrict the amount of disk space used on each partition by each user or group of users as your disk drives become filled with data. The disk quota feature of RedHat/Fedora Linux enables you to do this, and the setup is fairly simple.
Setting Up Quotas
For example, your family Linux server is running out of space in the /home filesystem because of an abundance of MP3 downloads.
Enter Single-User Mode
As you'll need to remount the /home filesystem, you make sure that no other users or processes are using it by first entering single-user mode from the console. If you are certain that you're the only user on the system, you might be able to skip this step. Entering single-user mode automatically logs off all users and stops cron jobs, so wait until after hours to do in a business environment. The procedure is quick:
1) Use the who command to see which users are logged in. If there are any, besides yourself, send a message stating that the system is about to shutdown with the wall command:
[root@bigboy tmp]# who
root pts/0 Nov 6
bob pts/0 Nov 6
bunny pts/0 Nov 6
[root@bigboy tmp]# wall The system is shutting down now!
Broadcast
message from root (pts/0) (Sun Nov 7
The system is shutting down now!
[root@bigboy tmp]#
2) Log into the VGA console and enter single user mode.
[root@bigboy tmp]# init 1
Simple eh?
Edit Your /etc/fstab File
The /etc/fstab file lists all the partitions that need to be auto-mounted when the system boots. You have to alert Linux that quotas are enabled on the filesystem by editing the /etc/fstab file and modifying the options for the /home directory. You'll need to add the usrquota option. In case you forget the name, the usrquota option is mentioned in the fstab man pages.
The old /etc/fstab looked like
LABEL=/home /home ext3 defaults 1 2
but your new /etc/fstab should be
LABEL=/home /home ext3 defaults,usrquota 1 2
Remount The Filesystem
Editing the /etc/fstab file isn't enough, Linux needs to reread the file to get its instructions for /home. You can do this using the mount command with the -o remount qualifier.
bash-2.05b# mount -o remount /home
Get Out of Single-user Mode
Return to your original run state by using either the exit, init 3 or init 5 commands. Continue to the next step once the system is back to its normal state. You can also use the exit command to return to your default runlevel.
bash-2.05b# exit
Create The Partition Quota Configuration Files
The uppermost directory of the filesystem needs to have an aquota.user file (defines quotas by user) and an aquota.group file (defines quotas by group), or both. The man page for quota lists them at the bottom. In this case just enable per-user quotas for the /home filesystem.
[root@bigboy tmp]# touch /home/aquota.user
[root@bigboy tmp]# chmod 600 /home/aquota.user
[root@bigboy tmp]#
Initialize The Quota Table
Editing the /etc/fstab file and remounting the file system only alerted Linux to the fact that the filesystem has quota capabilities. You have to generate a quota table, separate from the aquota files, that lists all the current allocations for each user on the file system. This table will be automatically and transparently updated each time a file is modified. Linux compares the values in this table with the quota limitations that the systems administrator has placed in the aquota files and uses this information to determine whether the user has rights to increased disk usage. You initialize the table with the quotacheck command. Be prepared: You'll get an error the first time you enter the command, because Linux will realize that the aquota file wasn't created using one of the quota commands:
[root@bigboy tmp]# quotacheck -vagum
quotacheck: WARNING - Quotafile /home/aquota.user was probably truncated. Can't save quota settings
quotacheck: Scanning /dev/hda3 [/home] done
quotacheck: Checked 185 directories and 926 files
[root@bigboy tmp]#
Edit The User's Quota Information
Now you need to edit the user's quota information. The edquota command enables you to selectively edit a portion of the aquota.user file on a per-user basis:
[root@bigboy tmp]# edquota -u mp3user
The command will invoke the vi editor.
Disk quotas for user mp3user (uid 503):
Filesystem blocks soft hard inodes soft hard
/dev/hda3 24 0 0 7 0 0
From here, you can edit a number of fields:
Blocks: The amount of space in 1K blocks the user is currently using.
Inodes: The number of files the user is currently using.
Soft Limit: The maximum blocks/inodes a quota user may have on a partition. The role of a soft limit changes if grace periods are used. When this occurs, the user is only warned that their soft limit has been exceeded. When the grace period expires, the user is barred from using additional disk space or files. When set to zero, limits are disabled.
Hard Limit: The maximum blocks/inodes a quota user may have on a partition when a grace period is set. Users may exceed a soft limit, but they can never exceed their hard limit.
Here user mp3user is limited to a maximum of 5MB of data storage on /dev/hda3 (/home):
Disk quotas for user mp3user (uid 503):
Filesystem blocks soft hard inodes soft hard
/dev/hda3 24 5000 0 7 0 0
Testing
Linux checks the total amount of disk space a user uses each time a file is accessed and compares it against the values in the quota file. If the values are exceeded, depending on the configuration, then Linux prevents the creation of new files or the expansion of existing files to use more disk space.
Other Quota Topics
Creating disk quotas frequently isn't enough. You also have to manage the process by reviewing the quota needs of each user and adjusting them according to the policies of your company. You'll need to make Linux scan its hard disks periodically to check for exceeded quotas. This section describes the most common quota management activities.
Editing Grace Periods
The edquota -t command sets the grace period for each filesystem. Like the edquota -u command, it invokes the vi editor.
The grace period is a time limit before the soft limit is enforced for a quota-enabled file system. You can use time units of seconds, minutes, hours, days, weeks, and months. This is what you'll see with the command edquota -t.
[root@bigboy tmp]# edquota -t
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/hda3 7days 7days
Note: There should be no spaces between the number and the unit of time measure. Therefore in this example, '7days' is correct and '7 days' is wrong.
Editing Group Quotas
Editing quotas on a per-group basis can be done similarly with the edquota -g command.
Getting Quota Reports
The repquota command lists quota usage limits of all users on the system. Here is an example.
[root@bigboy tmp]# repquota /home
*** Report for user quotas on device /dev/hda3
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
root -- 52696 0 0 1015 0 0
mp3user -- 24 0 0 7 0 0
[root@bigboy tmp]#
Conclusion
Disk quotas are good to put in place for specific users whose disk usage activities need to be curtailed. It helps to not only limit the use of physical disk resources that could potentially be put to better use, but also reduces the likelihood of having fragmented disk structures that slow disk access due to the presence of too many files. User education must play a major role in your strategy too; users must be made aware of the challenges you face as a result of excessive disk usage. Of course, there comes a time when you are faced with no option but to expand the number of disks in your system. Chapter 27, 'Expanding Disk Capacity', covers a variety of approaches to increasing your storage capacity.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 1457
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved