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:
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:
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/aquota.group chmod 600 /home/aquota.user /home/aquota.group
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 skx@undecided:~/Articles$
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'.
It's not clear what you want - if you give more details somebody might be able to help.
Steve
-- Steve.org.uk
[ Parent ]
for i in `wbinfo -u`; do quotatool -u $i -bq 200M -l '250 Mb' /home/DOMAIN/ doneNMC Nirina Michel RATOANDROMANANA
[ Parent ]
[ Parent ]
/etc/init.d/quota startbefore 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 processinvoking the quota init script enabled everything for me, so i didn't have to reboot.
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
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 ]
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 ]
[ Parent ]
c option to the quotacheck callOn 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 ]
[ View Weblogs ]
TYIA.
NMC
Nirina Michel RATOANDROMANANA
[ Parent ]