This post is in conjunction with the “the ‘dd’ way” post I made some weeks ago. The problem arose when we needed to control the hard disk space usage of some users in our IBM p5 server. Our setup was a client-server type where the clients are thin clients . The problem that plagued us was that some users saved files that were too large that other users ran out of hard disk space. This is obviously a problem, and being a Linux user/admin, I/we had to simply find a way.
Luckily for us, there’s the ‘quota’ family of tools for adding, applying, editing and restricting user hard disk space consumption. If you’re using Ubuntu, any Debian based Linux distribution, or if you just like to use
apt-get
, you can easily get the quota family of tools by issuing:
sudo apt-get install quota
Usually, Linux distros have the quota family of tools in their main repositories, so this shouldn’t be a problem.
Quotas are applied on a file-system basis. This means that if you have for example a partition in your hard drive, mounted in /media/hdb4, you can create separate quotas for another partition, say /media/hdc1.
You can enable quotas on your partitions by adding the
usrquota
and
grpquota
mount options on your
/etc/fstab
file. To do this, open
/etc/fstab
using you preferred text editor and edit it so it looks something like:
/dev/sda3 / ext3 acl,user_xattr,usrquota,grpquota 1 1
If you haven’t edited or bothered to wonder about your
/etc/fstab/
you don’t have to worry (or edit it for that matter) at this time. All you need to know is that you want to add quotas on your partition (in the previous example, /dev/sda3) by adding the mount options
usrquota
and
grpquota
.
After adding the mount options you need to remount your partitions where you added the
usrquota
and
grpquota
options so you can finally apply quotas.
sudo mount -o remount /dev/sda3
The previous command only remounts the specified partition, so you won’t need to reboot in order for the quota options to be applied. To check if the quota options were successfully applied, enter the command:
mount | grep quota
. You should see an output similar to this:
/dev/sda3 on / type ext3 (rw,acl,user_xattr,usrquota,grpquota)
You can then issue
quotacheck
especially if you’ve applied quotas before, to prepare for the final step which is
sudo quotaon -augv
which tries to turn all quotas for all user and group quotas, and be verbose about it. One other thing I usually do (most often actually) is to use this command instead:
sudo /etc/init.d/quota start
which I think is more convenient.
How to apply individual quotas to users/groups
To add a hard disk limit (or quota) to user eee13_200366176 in our server, I use the command
sudo edquota -u eee13_200366176
The previous command opens a text editor (usually Vi or Vim by default). In this case I want to limit this user’s hard disk space to only 200 MB, as there will be dozens of students for dozens of courses. Once the text editor opens, the initial output (assuming there weren’t any quotas previously) should look like this:
Disk quotas for user eee13_200366176 (uid 1200): Filesystem blocks soft hard inodes soft hard /dev/sda3 224 0 0 42 0 0
Which means that the user is currently using ony 224 KB on his/her account. I edit it to look like so, in order to impose a 200 MB hard disk limit:
Disk quotas for user eee13_200366176 (uid 1200): Filesystem blocks soft hard inodes soft hard /dev/sda3 224 0 200000 42 0 0
You can check the other options and parameters used by the quota family by reading its man page.
Finally, to apply the quota I placed, save the file you edited and exit. Don’t worry about the spacing/indentation, the file will be automatically indented to the proper positions after you save and exit. Then again use the command
/etc/init.d/quota start
to turn on the quotas. To check the fruit of your labors, enter
repquota -a
and you should see an output such as this:
eee13_199703431 -- 29320 0 200000 1751 0 0 eee13_200004928 -- 20632 0 200000 712 0 0 eee13_200346669 -- 36112 0 200000 2630 0 0 eee13_200366176 -- 224 0 200000 42 0 0 eee13_200402395 -- 6168 0 200000 274 0 0 eee13_200411066 -- 11116 0 200000 588 0 0 eee13_200411386 -- 10796 0 200000 331 0 0 eee13_200414739 -- 14268 0 200000 386 0 0 eee13_200436040 -- 16260 0 200000 352 0 0 eee13_200438007 -- 9096 0 200000 273 0 0 ........ eee13_200366176 -- 224 0 200000 42 0 0
And there we have it. The user whose quota we edited has a 200 MB limit now. Now you can test/check if the quota works by reading and following my previous post about the
dd
tool. If you have comments and suggestions, please do post them. In the next few days I’ll create a script to automate all of these.
August 22, 2007 at 9:46 pm |
[...] read more | digg story [...]