Quotas keep individual users or groups from consuming all of the space available on a partition. Disk quotas are commonly used by Linux administrators to regulate the amount of space occupied by any single user for e-mail, website files, FTP files, and more. This prevents any particular user from uploading so much data that it crowds out a critical directory such as /boot or root ( / ). Without sufficient free space for these directories, Linux might even crash.
You can configure quotas with limits on the number of inodes. Each inode is associated with a specific file. Alternatively, you can set absolute limits in kilobytes. In other words, you can limit the number of files that a user or group can put on your system, or you can place an absolute limit on the amount of data that user or group can place on your system.
Quotas allow you to monitor the pattern of use of your system.
By default, the quota RPM package is installed and is active in Red Hat Linux. If you re not sure, run the command
rpm -q quota
If the packages are installed, you ll see the package name and version number in the standard output on your screen. If necessary, see Chapter 10 for instructions on how to install RPM packages such as quota-* .
Quotas are normally active in the kernel. Once they re active, you can configure quotas on a specific partition for users and/or for groups. In either case, you ll need to remount the target directory with active quota settings shown in /etc/fstab . Once you ve configured those settings, you can activate quotas yourself; they are activated in subsequent reboots in /etc/rc.d/rc.sysinit .
While the default Red Hat Linux kernel enables quotas, that setting may not apply for kernels that you download from other sources. Fortunately, checking the appropriate kernel setting is easy.
When you download the source code for a kernel, the files are saved to the /usr/src/linux or /usr/src/linux-2.4 directories. Red Hat Linux kernels are downloaded to a different directory, which is linked to /usr/src/linux-2.4 . For more information on kernel sources, see Chapter 12 .
The next big Linux Kernel release is scheduled for sometime in 2003. (As of this writing, it may be called 2.6 or 3.0.) Once released, the source code will probably be associated with the /usr/src/linux-2.6 or the /usr/src/linux-3.0 directory. Many of the features of that future kernel have already been incorporated into the kernel included with Red Hat Linux 9.0.
Once you ve identified the directory with your source code, there should be a .config file in that directory. If it isn t there, it means that this kernel has not been compiled for your computer. In that case, search this file for the CONFIG_QUOTA setting with the following command:
# grep CONFIG_QUOTA /usr/src/linux-2.4/.config
If the directory with your kernel source code is different, change this command accordingly . You should see one of the following results in the standard output:
In other words, quota support is active ( y ) or not active ( n ). If quota support is not active, you ll need to compile it into your kernel. See Chapter 12 for more information.
The version number of the kernel should be associated with the settings that you find in your bootloader configuration file, normally /boot/grub/grub.conf . For more information on the relationship between a bootloader and the kernel, see Chapter 12 .
To create a quota for specific users, follow these six basic steps:
Modify /etc/fstab to activate quota options for the filesystem of your choice.
Enable the change by remounting the filesystem.
Create the aquota.user file at the top of the subject filesystem. For example, if you re creating quotas on /home , create /home/aquota.user .
Scan the appropriate filesystem and create basic quota files with the quotacheck command.
Use edquota to apply quota limits for a specific user.
Finally, activate quotas with the quotaon command.
We explain these steps in more detail in the following sections.
It s easy to modify /etc/fstab for quotas. Take a typical line from this configuration file, which in this case sets up /home as a filesystem on a separate partition:
LABEL=/home /home ext3 defaults 1 2
Fortunately, there s room in /etc/fstab to add the User Quota setting, usrquota . Space is scarce in /etc/fstab , since the boot process may not work if you let this code wrap to the next line. So with the User Quota setting, this /etc/fstab line would read as follows :
LABEL=/home /home ext3 defaults,usrquota 1 2
Now you can activate the change by remounting the /home directory. Fortunately, you do not need to change runlevels or reboot with the rescue disk to make this work; all you need to activate /etc/fstab changes on /home is the following command:
# mount -o remount /home
It s easy to create the quota file that you need with the touch command. As we re creating quotas on the /home filesystem in this section, create an empty aquota.user file in the /home directory. The easiest way to do this is with the touch command:
# touch /home/aquota.user
It s important to set the security on this file so it s accessible only to the root user. Since this file need not be executable, you can do this with the following command:
# chmod 600 /aquota.user
Now you re ready to create appropriate quota files with the quotacheck -avum command. This scans ( -a ) /etc/mtab for filesystems with enabled quotas, creates verbose ( -v ) output, looks for user quotas ( -u ), and remounts the scanned filesystem ( -m ).
Next, you can set up quotas for a specific user. Run the edquota command for the user of your choice. For example, if you want to set quotas on user ez, run the following command:
# edquota ez
By default, this opens up the quota information file for user ez in the vi editor, as shown here:
Disk quotas for user ez (uid 512) Filesystem blocks soft hard inodes soft hard /dev/sda3 4 0 0 1 0 0
As you can see, there are four blocks of data (in KB) and one inode used in ez s home directory. You can set hard and soft limits in each category. But what are hard and soft limits?
Soft limit A soft limit is the maximum amount of space or inodes allocated to a user. If there is no grace period, this acts as a hard limit. You can set a grace period with the edquota -t command.
Hard limit If there is a grace period, the hard limit is the absolute limit on the amount of space or inodes allocated to a user.
Now if you want to set a 100MB soft limit and a 110MB hard limit, edit the quota for ez to look like the following:
Disk quotas for user ez (uid 512) Filesystem blocks soft hard inodes soft hard /dev/sda3 4 100000 110000 1 0 0
The last step, enabling quotas, is the simplest. You ve already done the necessary configuration work. Just run the following command to enable quotas for all configured users on the /home filesystem:
# quotaon /home
Alternatively, you can deactivate quotas on the same filesystem with the quotaoff /home command.
Creating group quotas is as easy as creating user quotas. The differences can be summarized in the same six steps:
Modify /etc/fstab to activate quota options for the filesystem of your choice. For group quotas, add the grpquota setting to the options for the target filesystem.
Enable the change by remounting the filesystem with the mount -o remount filesystem command.
Create the aquota.group file at the top of the subject filesystem. For example, if you re creating quotas on /home , create /home/aquota.group .
Scan the appropriate filesystem and create basic quota files with the quotacheck command. Use the -avgm switches; -g configures group quotas.
Use edquota to apply quota limits for a specific group.
Finally, activate quotas with the quotaon command.
Once you ve configured quotas in Red Hat Linux, the operating system can take over the next time you reboot. Quota checking and activation commands are included in the default /etc/rc.d/rc.sysinit startup script. The relevant section is shown in Figure 9.7, which also attempts to convert the quota files associated with Linux kernel version 2.2 ( quota.user and quota.group ).
You can set up common quotas for a number of different users. The edquota command allows you to set up the same quotas for a list of users. Assuming you ve already set up quotas for user ez, the following command copies the identical limits for the other users that follow, in this case, mj, jm, and tp:
# edquota -up ez mj jm tp
Now that you ve set up quotas, you can get reports on who is using disk space and inodes, and how much space they occupy. The repquota command gives you quota reports by users ( -u ) or groups ( -g ). You can also get a report on all filesystems with the repquota -a command.
If you want to check up on an individual user ( -u ) or group ( -g ), use the quota command. Individual users can check their own status with this command.