Installing and configuring Quota on Ubuntu

Writing this article because I had some weird stuff installing en enabling quota on my Ubuntu virtual server:

When using a shared webserver, it is always nice to know which site is using what amount of disk space. This is of course, when each site runs under its own user. Of course you can use df or other tools to find out, but using quota on Ubuntu is the way to go.

First we start by installing quota itself:

After installing this, you need to enable quota (usrquota and grpquota) on the disk which contains the websites.

and change the / partition by adding usrquota,grpquota to the mount option

In my case, on my Xen virtual machine:

Prepare quota to be enabled by creating the quota files:

You will also need to load the quota kernel module, and cause that to be loaded at boot time. You can do that by running:

Then run the quotacheck command:

 the quotacheck parameters above explained:
-a: checks all filesystems
-v: verbose check
-u: Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked.  This is the default action.
-g:  Only group quotas listed in /etc/mtab or on the filesystems specified are to be checked
-m: same as –no-remount and thus forces quotacheck to run while the filesystem is mounted read/write, this way you don’t have to stop any services in order to perform the quotacheck.
-F vfsv0: to specify the quotaformat

This might take a while to complete… So grab a coffee.When the quotacheck has finished, enable quota itself by:

When I did this, I got the following errors: 

Fix this by:

Now, when you check the quota.user and file sizes, this might seem odd:

Wow, huge files! Now, don’t worry about this, as df show up as:

Also as explained on: HP SystemAdmin Forums

This is not a problem. The quota files are sparse files, i.e., they have “holes” of empty space that don’t actually take up any disk space. If you do an ls -ls on the file, the first field is the ACTUAL disk space used in KB. You’ll see that the file really occupies much less disk space than the length field would suggest. This is because the quota files are indexed based on the UID (for quota.user) or GID (for If you have very large UIDs or GIDs (or negative ones, which translate to very very large unsigned integers) it will make the files appear very large.

You can’t change this, short of removing the large UIDs/GIDs and changing ownership of any files belonging to them, and you can’t remove the quota files. But it’s really not a problem. The Tru64 backup utilities, and most third-party ones as well, handle the quota files properly. They either don’t back them up at all, or back up them up as sparse files.

Show all userquota’s with this command:


If you want to enable Hard and Soft Quota’s limits for your users and websites, you can implement this with quotatool. For now this is out of the scope of this article, as I’m not (yet) interested in this. 🙂



Kernel update errors on a Debian Squeeze Xen Virtual Machine

When performing a apt-get upgrade on a Xen Debian Squeeze Virtual Machine, you might encounted errors like:


This happens because grub cannot find the virtual disk in order to rewrite the server’s initrd image.

Since Xen kernel management is transparent to your machine itself, you can safely remove grub by:

This is the output of the remove command:



Schedule cron jobs to run every 2 weeks

There is no straight forward way to schedule a cron job so that a certain command gets executed biweekly, let’s say every 2 sunday nights…

To be able to do this, you need to extend your cron command with a command that tests the day of the week.

In my case I needed to perform a ‘clone MySQL database’ on the 2nd and 4th sunday of each month to a sandbox environment.

This is how I’ve implemented this:

You see that the cron job itselfs is scheduled to happen from:

The 8th until 14th of each month and from the 22nd until the 28th of each month.

When executing, I test if the day is the 1st of the week (Sunday = day 1 of the week). When this result is positive, the shell script will be executed.