Diskquotas under SuSE Linux
Table of contents
Disk quotas are a mechanism to limit the amount of disk space for users. Limits can be set for specific users and groups. Warnings can be emailed when the quota limit is reached.
Before activating the quotas you need to ensure that QUOTA-SUPPORT is included into your kernel. You'll find this entry in the Filesystems-menu of your kernel configuration.
The quota tools are used for setting up and maintaining disk quotas. Part of the quota tools compilation are warnquota, setquota, edquota, quota, quotacheck, quotaon, quotastats and repquota.
In my case after installing the quota tools from the SuSE CD, the eMail notification didn't work correctly. I decided to fetch the latest sources (*.tar.gz) from the internet. The easiest way is to query a package search engine like http://www.tuxfinder.com for "Quota".
Another advantage of Version 2.00 of the quota tools is the configuration of eMail warnings now being done via the configuration file /etc/warnquota.conf.
In the first place you should install the quota tools provided on the SuSE CD-ROM. Furthermore the packages ext2fs_d and gettext are needed as well as a Mail Transfer Agent (e.g. Sendmail).
Unpack the sources using the tar -xvfl <tarball-name> command. I won't give information about compilation options because they didn't work for me.
Now we just need to run ./configure followed by make and wait till the compiler finishes his work. You should leave out the usual make install because you can't provide a destination directory.
In the following list you can see where the individual tools should be copied to::
Disk Quotas can only be activated for whole partitions. Therefore, I suggest creating a special partition for the /home directories and to activate the disk quota support for this partition. By adding grpquota and/or usrqouta to the /etc/fstab file the diskqouta is activated for the specific partition. See further down for an example.
Depending on the quota system you want to use (usrqouta and/or grpquota) you have to create one or two files. Those files must be located in the top-directory of the concerned partition (in this case: /home, /beispiel and /beispiel2). You create those files using the touch command.
To create the needed files you have to execute the touch /home/quota.user, touch /beispiel/quota.group, touch /beispiel2/quota.user and touch /beispiel2/quota.group commands. For security reasons this files should only be read and writeable for ROOT (chmod 600).
To start the quota service when your machine boots just set the START_QUOTA entry in your /etc/rc.config to YES. Now it is time to reboot your system with the changed kernel.
To prepare the quota.* files finally you just have to run the quotacheck command. If only user quotas are needed you run quotacheck -u -a, using only group quotas you need quotacheck -g -a and using both kinds of quotas just run quotacheck -g -u -a. The -a option activate automatically all disk quotas for all quoted partitions in your system
Disk quotas are defined using the edquota tool. Running this tool will start the text editor specified in the $EDITOR variable and show an input mask. (This is an environment variable in your shell.)
Quotas are defined by a soft limit (eMail warning is sent on exceeding) and a hard limit (absolute limit, no more writing access is permitted when the limit is exceeded).
In my examples I only stick to limiting disk space in kilobytes instead of limiting the numbers of inodes.
You'll reach the input mask for limiting a users disk space by calling edquota -u <username>. Here only the amount for the soft limit (for eMail warning) is set. For my login, this limit is set to 51200 kilobytes (50 MB).
The hard limit is set to 1102400 kilobytes (100 MB). After reaching 100 MB of used userspace, the user will not be able to perform any more write operations.
For setting up qroup quotas just run edquota -g <groupname>. The configuration itself works as shown in 5.1.
To set a specified period till blocking write operations (when the quota has been exceeded) can be defined using the edquota -t command.
Periods for users are set with edquota -u -t <Period>. Periods for groups are set via edquota -g -t <Period>. This period will be valid for all paritions, users and groups for which quotas have been defined.
When no period is provided, the default value out of /linux/quota.h is taken (7 days). Possible periods are sec[onds], min[utes], hour[s], day[s], week[s] or month[s].
This step is IMHO necessary cause the original text may not be understood by some users. This mail is sent by warnquota when the quota limit is exceeded.
In the warnquota.conf file the following entries can be modified:
You should change the file to fit your own purposes. The warnquota.conf should look like that:
Unfortunately the only way to change the mail text is to edit the source file directly. According to the handy comments in the source it shouldn't be a problem (even for "non programmers"!). At least every 80 characters a newline should be inserted so the mail can be read properly on different systems. This can be done by inserting a "\n" which is equal to the newline.
The message text can be found in the "DEF_MESSAGE" section. A signature can be defined in the "DEF_SIGNATURE" section. Between those two texts some information about the partition concerned is added into the eMail.
Parameters set up in the warnquota.conf file can be accessed via the "%s" variable. The first call of %s inserts the string defined as "SUPPORT", the second use inserts the string defined as "PHONE"
The changed part could look like this:
Now the package can be compiled and installed as described in 3.2.
The automation works via a cron job. Specially when using in companies it is suggested to plan the quota check for lunchtime. In that case the users can react the same day and can (if needed) contact the support/administration team immediately. Lunchtime also should be a time when servers experience lower usage.
Simply add the following line to your /etc/crontab file:
0 12 * * 1-5 root /usr/sbin/warnquota
This line starts the warnquota tool every monday to friday at 12 o'clcok noon as root.
In the following the most important programs and their parameters are summarized:
Autor of this article is Mathias Kresin.
His homepage can be found at http://www.kresinweb.de.
Translated by Sebastian Küppers.
Enter Own Comment