Limiting your users use of disk space with quotas

Posted by Steve on Tue 23 Nov 2004 at 19:22

When you run a multi-user system it's possible for a single user to unduly hog the system, by filling their home directory with a lot of files, and filling a disk so that other users have no space of their own. Quotas are a system of preventing this. It's possible to setup limits on the amount of space a single user, or a single group, can use.

Using quotas on Debian is very straight forward as the Debian kernel packages all have quota support compiled in.

There are two ways to use quotas:

  • Per user
  • Per group

When using per-user quotas you are effectively giving a limit on how much disk space the specific user may consume. In the case of per-group quotas you're giving a limit on the total disk usage of all members in that group combined.

Generally I find it much more useful to apply quotas on a per-user basis, as this way you dont have to work out which member of a group is consuming all the space.

To setup quota usage on your system you'll need to do three things:

  • Mount your filesystems with quota support
  • Install the quota software
  • Configure your limits

Quota support is enabled as the filesystems are mounted, and so it must be specified in the options section of your /etc/fstab file.

Specifying the quota options is as simple as adding usrquota for per-user quota, or grpquota for per-group quotes in the options column.

For example this first entry without quotas:

/dev/hda1       /home       ext2    defaults           1       1

Would become the following with per-user quotas enabled:

/dev/hda1       /home       ext2    defaults,usrquota  1       1

Once this has been added you can remount the partition by rebooting, and install the software. This will setup the partitions to be mounted with quota support enabled, however you haven't enabled them for the running system.

To change the options run:

mount -o remount,usrquota /home

(Repeat for any other filesystems you wish to modify).

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:

modprobe quota_v2
echo 'quota_v2' >> /etc/modules

The quota system has a notion of a soft limit and a hard limit. A soft limit is a limit which the user can live with for a while (by default 7 days). A hard limit is a limit which cannot be crossed ever.

These limits are recorded inside special files which we need to create for each filesystem which is being used with quotas.

Continuing with our example of /home we would create one file for group quotas and one file for user quotas:

touch /home/aquota.user
touch /home/
chmod 600 /home/aquota.user /home/

Now we're ready to install the software.

apt-get install quota quotatool

As you installed the software you will have been prompted to see if you wish to email your users when their quotas are exceeded, this is their soft limit.

If you don't reboot you'll need to turn on the quota system by running:

quotacheck -vagum

To set the soft limits to 200Mb and the hard limit to 250Mb for a user called skx you would run:

quotatool -u skx -bq 200M -l '250 Mb' /home

A cronjob will run every day to check and warn them if they exceed their soft quota (if you said 'Yes' to the email notification question when the packages were installed), and the user will be informed immediately if they exceed their hard quota:

skx@undecided:~/Articles$ mkdir f
mkdir: cannot create directory `f': Disk quota exceeded

The system administrator can see what the disk and quota usage is like by invoking:

repquota /home

If ever you wish to remove a quota for a user simply set their hard and soft limits to '0'.



Posted by debstar (193.251.xx.xx) on Wed 8 Jun 2005 at 13:20
[ View debstar's Scratchpad | View Weblogs ]
Please, do you have a trick to use quotatool with a lot of users in a shell script?



[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 8 Jun 2005 at 14:31
[ View Steve's Scratchpad | View Weblogs ]

It's not clear what you want - if you give more details somebody might be able to help.


[ Parent | Reply to this comment ]

Posted by debstar (193.251.xx.xx) on Mon 13 Jun 2005 at 08:20
[ View debstar's Scratchpad | View Weblogs ]
I wanted to set a disk quota on homedir of NT Domain users so they won't fill the server disk space by copying files via shares. This command will do all the job with the help of wbinfo:
for i in `wbinfo -u`; do  quotatool -u $i -bq 200M -l '250 Mb' /home/DOMAIN/ done

[ Parent | Reply to this comment ]

Posted by suspended user gg234 (195.14.xx.xx) on Wed 12 Oct 2005 at 10:20

I want to limit the users for 30 MB under perticular directory

example:- i want create users directories /home/www

any new user created under this should be having only 30MB of data

How to create this

Thanks for your help

best regards

[ Parent | Reply to this comment ]

Posted by Anonymous (62.68.xx.xx) on Thu 30 Jun 2011 at 16:25
Yes, I want to know how to do it.

[ Parent | Reply to this comment ]

Posted by dkg (216.254.xx.xx) on Tue 25 Apr 2006 at 04:43
[ View dkg's Scratchpad | View Weblogs ]
Just a note for other users: if you install the packages before inserting the kernel module, you'll also need to do:
/etc/init.d/quota start
before any of the quotatool commands will work.

I installed the packages before inserting the module, and my attempts to invoke quotatool all failed with an error like:

quotatool: Error while detecting kernel quota version: No such process
invoking the quota init script enabled everything for me, so i didn't have to reboot.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.28.xx.xx) on Wed 22 Sep 2010 at 15:34
Thank you for replying. This was my case, and it solved with the quota start.

[ Parent | Reply to this comment ]

Posted by Anonymous (142.103.xx.xx) on Thu 12 Oct 2006 at 02:41
A word of warning, the group quota sets it for all users in a group, not per user in a group.

If one user uses up all the space the group allowed, then other users in the group cannot have more space.

This is an annoying feature about Linux-Quotas.

[ Parent | Reply to this comment ]

Posted by Anonymous (64.76.xx.xx) on Wed 20 Jun 2007 at 14:01
if this disturb you it isnt group quotas what you want :-). Perhaps user+group quotas ?

[ Parent | Reply to this comment ]

Posted by Anonymous (116.199.xx.xx) on Wed 23 Feb 2011 at 13:25
sir i have created Raid-0 and i am trying to implement Quota to the directory where i am mounting my Raid parition.while i am checking the quota with quotacheck -vagum command it is showing the below error :

quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/md0 [/mnt/enjayvol1] quotacheck: error (2133571347) while opening /dev/md0

[ Parent | Reply to this comment ]

Posted by Anonymous (140.105.xx.xx) on Mon 17 Oct 2011 at 12:42
You have to change the lines in fstab to


[ Parent | Reply to this comment ]

Posted by Anonymous (117.192.xx.xx) on Mon 19 Dec 2011 at 17:56
can the same procedure be followed for reiserfs and ext4 fs

[ Parent | Reply to this comment ]

Posted by Anonymous (194.208.xx.xx) on Tue 3 Apr 2012 at 19:51

If you run into the following error message:

quotacheck: Cannot guess format from filename on /dev/example/disk. Please specify format on commandline.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.

It’s most likely that you have some kind of VPS which is running inside a virtual machine. To get this up and running run the following:

# quotacheck -F vfsv0 -afcvugm

If you want debugging information add a d to the last bunch of options:

# quotacheck -F vfsv0 -afcvdugm

Thanks for this article, very helpful and easily to follow!

[ Parent | Reply to this comment ]

Posted by Anonymous (77.79.xx.xx) on Tue 3 Apr 2012 at 22:23

Setting GB like:

quotatool -u joe -bq 20G -l '25 Gb' /home

won't work, you'll have to convert it!

quotatool -u joe -bq 20480M -l '25600 Mb' /home

[ Parent | Reply to this comment ]

Posted by LazyBoy (181.46.xx.xx) on Wed 17 Oct 2012 at 00:32
Excellent Tuto!!!! Thanx a lot!!!

[ Parent | Reply to this comment ]

Posted by Anonymous (82.67.xx.xx) on Fri 6 Nov 2015 at 12:05

just add the c option to the quotacheck call

On Debian systems, it appears that only touching {a,}quota.{user,group} files does not work.

Instead, one add a 'c' option to the quotacheck command line. It creates the needed files, by browsing the volume, and it fixed my setup on Debian SID.

[ Parent | Reply to this comment ]

Sign In







Current Poll

Will you stick to systemd as the default in Debian?

( 25 votes ~ 1 comments )