Our linux distribution comes with quota support, so we might want to enable it. If you trust your users and/or have unlimited disk space, you can simply skip this step. Knowing how to turn on quotas won't hurt I would say anyways. First we have to activate the quotas in 3 steps. First we enable quota on our machine during the boot-up, then we enable a volume / mount point for quotas and finally we add the quota database files. So we add the following lines to the end of the file /etc/rc.d/rc.local just before the last fi command
vi /etc/rc.d/rc.local # Check quota and then turn it on
if [ -x /sbin/quotacheck ]
then
echo "Checking quotas "
/sbin/quotacheck avug
echo "Done"
fi
if [ -x /sbin/quotaon ]
then
echo "Turning quota on "
/sbin/quotaon avug
fi
Now we will enable the /home mountpoint for quotas. This is done by adding some stuff to the /etc/fstab file:
vi /etc/fstab
Now look for the line that starts with "LABEL=/home" and change the word defaults to defaults,usrquota,grpquota so that it looks like this:
LABEL=/home /home ext2 defaults,usrquota,grpquota 1 2
Now we have to create the quota database files in the root of the directory with
cd /home
touch quota.user
touch quota.group
chmod 600 quota.*
That's all. We make a reboot and our system is at least ready to accept our quota commands! So let's add those commands for our testuser by typing:
edquota u testuser
And we will see something like this (hda5 will most likely be different for you):
Quotas for user testuser:
/dev/hda5: blocks in user: 28, limits (soft = 0, hard = 0)
inodes in use: 7, limits (soft = 0, hard = 0)
As you see the edquota command has launched the vi editor for you automatically. Whenever you're done with the changes just save them as you would usually with ZZ. But what changes ? First the explanation of a hard and soft limit. A soft limit let's a user exceed this limit for a limited amount of time, called the grace period. You can notifiy the user that this is happening. The hard limit is a limit that can not be exceeded at any costs unless it is changed. If the user exceeds it, he can not write to the directory anymore unless he cleans up or the administrator changes the hard limit.
But what are blocks and i-nodes? 1 block in linux is 1kb. So if you want to limit the quota to 1 Mb you will just use 1024 blocks. I-nodes are control structures that point to other i-nodes or to the file itself. So one file has one or more I-nodes assigned to it. I prefer to change only the block use.
So to limit the testuser's mailbox size (and everything else as well) to a soft limit (warning) of reasonable 10Mb, and an ultimate hard limit of 15Mb, we change the above output in vi to:
Quotas for user testuser:
/dev/hda5: blocks in user: 28, limits (soft = 10240, hard = 15360)
inodes in use: 7, limits (soft = 0, hard = 0)
Pretty neat, hmm? Never mind the filename vi displays while you edit, edquota manages all this for you. So how do you know what user used to be a mailman in his previous life? The program quotacheck lets you check the quota dat abase, and the program repquota shows you some current statistics. Just type
edquota a
And you see the current status for everybody. With perl you can run a daily job that sends emails to users or to you. The grace period is set to 7 days, by the way. If you want to change it for all users, type
edquota g t
To change it for all users, type
edquota u t
For users to view their quota information, they can use the program
quota
With the switch g the user can view statistics. The q switch prints a message to the user if he is over quota.