You may eventually need to restrict the amount of disk space used on each partition by each user or group of users. Redhat linux allows this to occur its disk quota feature. The setup is very simple.
Setting up Quotas
We will implement disk quotas on /home filesystem. As we will need to remount the /home filesystem it's best to ensure that no other users or processes are using it. This is best achieved by entering single user mode from the console. This may be unnecessary if you are certain that you're the only user on the system.
[root@joel tmp]# init 1
Edit your /etc/fstab file
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.
Old fstab
LABEL=/home /home ext3 defaults 1 2
New fstab
LABEL=/home /home ext3 defaults,usrquota 1 2
Remount the Filesystem
Editing the /etc/fstab file isn't enough, Linux needs to re-read the file to get its instructions from /home. This can be done using the mount command with the "-o remount" qualifier.
[root@joel tmp]# mount -o remount /home
[root@joel tmp]#
Create the Partition Quota Configuration Files
The top most directory of the filesystem needs to have aquota.user file (defines quotas by user) and/or a aquota.group file (defines quotas by group). The man page for "quota" lists them at the bottom.
In this case we will just enable "per user" quotas
[root@joel tmp]# touch /home/aquota.user
[root@joel tmp]# chmod 600 /home/aquota.user
[root@joel tmp]#
Making Linux Read The Quota Config File
This is done using the quotacheck command. You will get an error the first time you enter the command as Linux will realize that the file wasn't created using one of the quota commands.
[root@joel tmp]# quotacheck -vagum
quotacheck: WARNING - Quotafile /home/aquota.user was probably truncated. Cant save quota setting...
quotacheck: Scanning /dev/hda3 [/home] done
quotacheck: Checked 185 directories and 926 files
[root@joel tmp]#
Edit The User's Quota Information
Now we need to edit user's quota information. This is done with edquota command which allows you to selectively edit a portion of the aquota.user file on per user basis.
[root@joel tmp]# edquota -u test
The command will invoke the vi editor which will allow you to edit a number of fields.
Disk quotas for user test (uid 505):
Filesystem blocks soft hard inodes
soft hard
/dev/hda3 24 0 0 7
0 0
Blocks: The amount of space in 1k blocks 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 roule of soft limit changes if grace periods are userd. 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 havoe on a partition when a grace period is set. Users may exceed a soft limit, but they cannot never exceed their hard limit.
In the example below we will limit user test to a maximun of 5 MB of data storage on /dev/hda3 (home).
Disk quotas for user test (uid 505):
Filesystem blocks soft hard inodes
soft hard
/dev/hda3 24 5000 0 7
0 0
Get Out Of Single User Mode
Return to your original run state by using either the "init 3" or " init 5" command.