eric’s extremeboredom

adventures into and out of extreme boredom.

Linux Filesystem Quotas

I have a Xen VM set up on my server that I give accounts to friends on, and I thought it would be nice to set up filesystem quotas, so one user couldn’t take down the server for everyone else by filling up the disk.

Enabling quotas is easy, just add usrquota and grpquota to /etc/fstab, as such:

/dev/sda1       /       reiserfs        defaults,usrquota,grpquota      0 1

Then, remount the filesystem:

$ sudo mount -o remount /

Finally, install and enable the software:

$ sudo apt-get install quota quotatool
$ sudo /etc/init.d/quota start

After getting everything turned on, I quickly realized that the tools for actually setting quotas, while quite powerful, are not very user friendly.

I wanted to give everyone in the “users” group a 100MB quota, except for a few users who would get more. At first I thought I could set a group quota to accomplish this, but eventually figured out that group quotas apply to files owned by the group, not users in the group.

Rather than set every user by hand, I wrote a little script to make life easier.

To use, just change QUOTA_INFO at the top.

QUOTA_INFO = {
        'users' => {
                'eric'      => :unlimited,
                'jazzfreak' => 200,
                :default    => 100
        }
}

I also thought it would be nice if users saw how much disk space they had left upon login, and after searching the web for a while without finding anything, I wrote another quick script to do just that.

I stuck it in /usr/local/bin/ and added it to the bottom of /etc/profile so it would be run automatically on login.

Here’s what it looks like:

$ ssh orion
You have used 187.7 MB of 200 MB. 12.3 MB remaining.

eric@orion:~$

If anyone finds either of these scripts useful, please let me know!


Categorized as Open Source, Technology

1 Comments

  1. Thanks! Always wanted to know how to do this.

Leave a Reply