Setting up User Quotas on Rehat
First there was the machine. And it was good. Then there were users. And disk space beacame scarce. Inevitably when admining a box with lots of users you’re going to run in to disk usage issues. You can tackle this before it becomes a problem by setting up disk space quotas for each user (or for groups but I’ll explain that later)
So the first thing you gotta do is enable quotas on the partition that your users reside on. To do this we edit fstab. In this example we’re going to set up quotas for users in /home. Append usrquotas to the defaults field in your fstab.
Change
/dev/hda5 /home ext3 defaults 1 1
To
/dev/hda5 /home ext3 defaults,usrquota 1 1
Now give it the old :wq!.
Since we’re edited fstab we need to remount the affected directory.
mount -o remount,rw /home
Okay, time for the nitty gritty. You need to set up the reference files quotas will need to run. Run:
quotacheck -C /home
This will create .aquota.user and .aquota.group which you won’t really touch.
So let’s set up a quota for user badmonkey. Run:
edquota badmonkey
You’ll enter vi file that looks like this.
Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 0 0 19 0 0
Presently badmonkey is using 112K and has 19 files. You can set up quotas by 1K blocks or by inodes or both. The number under soft is the limit they can hit before recieving a warning. The number under hard is what they can hit before the system stops them from creating any new files.
Let’s say we want a hard limit of 512M and 800 files. We’ll make the soft limit 3/4’s of the hard limit. We’ll edit the file so it looks like this:
Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 393216 524288 19 600 800
Do a :wq!. Now all that’s left is to turn quotas on.
quotaon /home.
You are done! badmonkey can no longer be such a badmonkey w/o dealing wiht the consequences. Bear in mind when you add a new user you’ll want to run quotacheck -C /home again (Which will require you to turn quotas off)
You can apply the same thing to groups. Howver you’ll also want to add grpquota to /etc/fstab.