home   articles   archive   forum   masthead  
Published at 11.04.2005
Author: Mathias Kresin
Translator: Sebastian Kueppers
Languages: de
Printer printer-version
Support Us!
 

Diskquotas under SuSE Linux

Table of contents

1. What are disk quotas?

2. Activating Disk Quotas

3. Quota tools
   3.1 Installing quota tools
   3.2 Compiling new quota tools

4. Setup
   4.1 fstab without quota support
   4.2 fstab with quota support

5. Defining disk quotas
   5.1. User quotas
   5.2. Group quotas
   5.3. Time till ban

6. Customising the eMail message
   6.1. Customising the configuration files
   6.2. Customising the source code

7. Automation of eMail warnings

8. The result

9. Overview on the programmes' functions

10. Sources


1. What are disk quotas?

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.

2. Activating Disk Quotas

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.

3. Quota tools

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.

3.1. Installing quota tools

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).

3.2. Compiling new quota tools

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::

edquota /usr/sbin/edquota
quota /usr/bin/quota
quotacheck /sbin/quotacheck
quotaon /sbin/quotaon
quotastats /usr/sbin/quotastats
repquota /usr/sbin/repquota
rpc.rquotad /usr/sbin/rpc.rquotad
setquota /usr/sbin/setquota
warnquota /usr/sbin/warnquota
warnquota.conf /etc/warnquota.conf


The Manual-Pages are copied into the specific directories at /usr/share/man/.

4. Setup

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

4.1. fstab without disk quota support

/etc/fstab
  /dev/sda8	swap		swap	defaults       		    0	0
  /dev/sda6	/		ext2	defaults       		    1	1
  /dev/sda5	/boot		ext2	defaults       		    1	2
  /dev/scd0	/cdrom		auto	ro,noauto,user,exec	    0	0
  /dev/fd0	/floppy		auto	noauto,user		    0	0
  none		/proc		proc	defaults		    0	0
  


4.2. fstab with disk quota support

/etc/fstab
  /dev/sda8	swap   		swap	defaults       		    0	0
  /dev/sda6	/		ext2	defaults       		    1	1
  /dev/sda5	/boot		ext2	defaults       		    1	2
  
  /dev/sda7	/home		ext2	defaults,usrquota	    1	1
  /dev/sda8	/beispiel	ext2	defaults,grpquota           1	1
  /dev/sda9	/beispiel2	ext2	defaults,usrquota,grpquota  1	1
  
  /dev/scd0	/cdrom		auto	ro,noauto,user,exec	    0	0
  /dev/fd0	/floppy		auto	noauto,user		    0	0
  none		/proc		proc	defaults		    0	0
  
  


5. Defining disk quotas

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.

5.1. User quotas

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.

5.2. Group quotas

For setting up qroup quotas just run edquota -g <groupname>. The configuration itself works as shown in 5.1.

5.3. Time till ban

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].

6. Customising the eMail message

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.

6.1 Customising the configuration files

In the warnquota.conf file the following entries can be modified:

Parameter Meaning Example
MAIL_CMD Path to MTA /usr/lib/sendmail -t
FROM Shown source of the mail admin@firma.de
SUBJECT EMail subject Warning!
CC_TO Who gets copies of this mail? chef@firma.de
SUPPORT Support-Adress named in the mail support@firma.de
PHONE Support-Phone named in the mail 123456 and 654321

You should change the file to fit your own purposes. The warnquota.conf should look like that:

warnquota.conf
   # Sample for warnquota.conf
   #
  
   MAIL_CMD = "/usr/lib/sendmail -t"
   FROM = "admin@firma.de"
  
   # Optional Parameter
   #
  
   SUBJECT = "Warning!"
   CC_TO = "chef@firma.de"
   SUPPORT = "support@firma.de"
   PHONE = "123456 and 654321"
  


6.2. Customizing the source code

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:

.
.
#define DEF_MESSAGE _("Hi,\n\n We are sorry to tell you that you have exceeded the amount of disk capacity we provide\n for your personal files. Every user is allowed to use 50 MB for their personal files.\n You have just exceeded this amount of disk capacity.\n\n Please delete/move unused files in the next 7 days. Otherwise the system will\n deny further writing requests to your directory. You will be able to write to your directory \n as soon as you fall below 50 MB again.\n\n You can store up to 100 MB in your account for 7 days. If you exceed 100 MB\n the system will deny further writing requests without further notice.\n You gain write access as soon as your total used space falls below 50 MB again.\n\n The following information is system information to ease up the administrative\n work and is of no consequence to you.\n\n")

#define DEF_SIGNATURE _("\n If you need more disk capacity or if there are further problems regarding\n your disk capacity contact us via mail\n %s or call %s.\n\n Yours sincerely\nAdministration Team\n")
.
.

Now the package can be compiled and installed as described in 3.2.

7. Automation of eMail warnings

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.

8. The result

From: admin@firma.de
Reply to: support@firma.de
To: user@firma.de
Copy to: chef@firma.de
Subject: Warning!
Message:

Hi

We are sorry to tell you that you have exceeded the amount of disk capacity we provide
for your personal files. Every user is allowed to use 50 MB for his personal files.
You have just exceeded this amount of disk capacity.

Please delete/move unused files in the next 7 days. Otherwise the system will
deny further writing requests to your directory. You will be able to write to your directory
as soon as you fall below 50 MB again.

You can store up to 100 MB in your account for 7 days. When you exceed this 100 MB
the system will deny further writing requests without further notice.
You gain write access as soon as you fall below 50 MB again.

The following information is system information to ease up the administrative
work and is of no consequence to you.

< Server Usage >

If you need more disk capacity or if there are further problems regarding
your disk capacity contact us via mail
support@firma.de or call 123456 and 654321.

Yours sincerely\nAdministration Team

Mit freundlichen Grüßen
Administrations Team

9. Overview of the programmes' functions

In the following the most important programs and their parameters are summarized:

edquota Changing disk quotas (textbased via Editor)
   edquota -u <username> change disk quotas for <user>
   edquota -g <groupname> change disk quota for <groupname>
   edquota -u -t <period> Period from exceeding soft limit till denying requests for users
   edquota -g -t <period> Period from exceeding soft limit till denying requests for groups
   
repquota Summary of used disk capacity
   repquota -q <groupname> used disk space for <groupname>
   repquota -u <username> used diskspace for <username>
   
setquota defining diskquotas (only via parameters)
   setquota -u <username> define quotas for <username>
   setquota -g <groupname> define disk quota for <groupname>
   
warnquota Command for checking quotas and sending eMail warnings

10. Sources


Autor of this article is Mathias Kresin.
His homepage can be found at http://www.kresinweb.de.
Translated by Sebastian Küppers.



Talkback Area




Enter Own Comment