8.10. The Quota System for Hard Drive Space

First we need some additional packages, install them with apt-get install quota quotatool


tjener:~# apt-get install quota quotatool --simulate
tjener:~# apt-get install quota quotatool

Then we must umount the partition we want to apply quota on


tjener:~# umount /skole/tjener/home0/

Note

If you are using a 2-4-kernel, and not a 2.6-kernel, see booting with 2.6, you must manually insert the necessary module

modprobe quota_v2


tjener:~# modprobe quota_v2
Warning: loading /lib/modules/2.4.27-2-386/kernel/fs/quota_v2.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module quota_v2 loaded, with warnings
You should add it to the file /etc/modules, so that it gets loaded automatically at boot,

echo "quota_v2" >> /etc/modules

You might have to stopping nfs first, see resizing home0

You could probably also just run

mount -o remount,usrquota,grpquota /skole/tjener/home0/

Then we must mark that partition in /etc/fstab as having quotas, modify the home0-line so it looks like:

/dev/vg_data/lv_home0   /skole/tjener/home0     ext3    defaults,usrquota,grpquota      0 2

Then we may mount /skole/tjener/home0


tjener:~# mount /skole/tjener/home0/

Then we create the quota database files, and give the appropriate permissions


tjener:~# touch /skole/tjener/home0/aquota.user
tjener:~# touch /skole/tjener/home0/aquota.group
tjener:~# chmod 600 /skole/tjener/home0/aquota.user
tjener:~# chmod 600 /skole/tjener/home0/aquota.group

See that they have zero-size


tjener:~# ls -lh /skole/tjener/home0/aquota*
-rw-------  1 root root 0 2005-12-09 15:54 /skole/tjener/home0/aquota.group
-rw-------  1 root root 0 2005-12-09 15:54 /skole/tjener/home0/aquota.user

Now we populate the database files, and notice afterward that they no longer are of zerosize


tjener:~# quotacheck -avug
quotacheck: WARNING - Quotafile /skole/tjener/home0/aquota.user was probably truncated. Can't save quota settings...
quotacheck: WARNING - Quotafile /skole/tjener/home0/aquota.group was probably truncated. Can't save quota settings...
quotacheck: Scanning /dev/mapper/vg_data-lv_home0 [/skole/tjener/home0] done
quotacheck: Checked 3 directories and 3 files
tjener:~# ls -lh /skole/tjener/home0/aquota*
-rw-------  1 root root 32 2005-12-09 15:54 /skole/tjener/home0/aquota.group
-rw-------  1 root root 32 2005-12-09 15:54 /skole/tjener/home0/aquota.user

Note

Note that if you have lots of data on /skole/tjener/home0, the scanning process might take a long time.

Then we activate quotas


tjener:~# quotaon -a

We still haven't given any users any quotas, but we may see what they are using


tjener:~# repquota /skole/tjener/home0
*** Report for user quotas on device /dev/mapper/vg_data-lv_home0
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
ronja    --    7764       0       0            569     0     0
henrik   --    8328       0       0            569     0     0
anna     --   13232       0       0            684     0     0
agnes    --    7860       0       0            563     0     0
kristof  --    7856       0       0            606     0     0
matthias --   11044       0       0            668     0     0
sven     --   14848       0       0            650     0     0
gustav   --    8360       0       0            608     0     0
eli      --   10412       0       0            678     0     0
anna     --    7972       0       0            565     0     0
linemar  --    7804       0       0            564     0     0
marcus   --   15344       0       0            719     0     0
karl     --    7244       0       0            570     0     0
regine   --    9700       0       0            700     0     0

Now we are ready to put some quotas on our users. First we setup quotas for one user, then we use those settings for all our other users.

Lets setup for the user klaus, like this:

EDITOR=nano edquota -u klaus

This will use the well-known editor nano for setting up the quota.

Disk quotas for user klaus (uid 10011):
Filesystem                   blocks       soft       hard     inodes     soft     hard
/dev/mapper/vg_data-lv_home0       5252       6252       7252        275        0       0


                                     [ Read 3 lines ]
^G Get Help    ^O WriteOut    ^R Read File   ^Y Prev Page   ^K Cut Text    ^C Cur Pos
^X Exit        ^J Justify     ^W Where Is    ^V Next Page   ^U UnCut Txt   ^T To Spell   

Once you are done setting up quotas for one user, in this case the user klaus, you use the command

edquota -p klaus someone

This will give the user with the username someone the same quota as the user klaus.

There is also a Webmin module available for quotas.

apt-get install webmin-quota

The new Webmin quota-module is available in the "System"-section of Webmin, same place as the ldap-user-module. The url is Webmin Disk Quotas

Figure 8-12. Webmin disk quota icon

This is the Webmin disk quota icon, found under Systems

Figure 8-13. Filesystems with quotas

Figure 8-14. quotas for home0

Figure 8-15. Edit quota for user klaus

8.10.1. Stopping the File .xsession-error From Filling up Your Entire Hard Drive

Sometimes a program can get very troublesome and start writing enormous amount of error messages to the file .xsession-errors in a user's home directory. Some programs, especially GIMP, are fully capable in the space of only a few minutes of creating such a large .xsession-errors file that the whole hard drive gets full. So, everything stops working. Then the root user has to go in to the main server and find that file and delete it. This is not exactly what you want to do on a regular schoolday.

So, even if such error message files as .xessions-errors are surely useful to have when you need to diagnose a problem, they are really more of a hassle in the schoolday. So, you need to get rid of it. You can do this by redirecting all messages that would otherwise be written to this file, right into the waste bin /dev/null

By changing a few lines in the file /etc/X11/Xsession set a comment symbol(#) in front of these lines, in this way:


#ERRFILE=$HOME/.xsession-errors&&
#
## attempt to create an error file; abort if we cannot
#if touch "$ERRFILE" 2> /dev/null && [ -w "$ERRFILE" ] &&
#  [ ! -L "$ERRFILE" ]; then
#  chmod 600 "$ERRFILE"
#elif ERRFILE=$(tempfile 2> /dev/null); then
#  if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
#    message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
#             "\"$ERRFILE\"; look for session log/errors in" \
#             "\"$TMPDIR/xsession-$USER\"."
#  fi
#else
# errormsg "unable to create X session log/error file; aborting."
#fi
#
#exec >>"$ERRFILE" 2>&1
And set in these two lines instead:

errfile="/dev/null"
exec > "$errfile" 2>&1
Now you don't need to be afraid that .xsession-errors will fill up your entire hard drive.