|
Quota Tutorial
In this series, we will walk you though enabling quota support within Linux. Quotas are important as a system administrator because they allow us to limit (by user or group) the number of inodes and/or blocks a user/group can use on a particular file system.
Blocks in the Linux world are a measurement of 1K increments. Every file system has a finite number of blocks, better know as free space. Once a file system runs out of blocks (free space), the file system can not be written to further until free blocks are made available. One can easily examine the number of free/used blocks on a file system with the df command (see example output below.) Enabling a block quota can ensure that any given user/group does not consume all the available free disk space.
| [root@Linux01 ~]# df |
Filesystem
|
1K-blocks
|
Used |
Available |
Use% |
Mounted on |
/dev/mapper/VolGroup00-LogVol04
|
3999424 |
2212740 |
1580248 |
59% |
/ |
/dev/sda1
|
101086
|
12174 |
83693 |
13% |
/boot |
tmpfs
|
1029908
|
0 |
1029908 |
0% |
/dev/shm |
| /dev/mapper/VolGroup00-LogVol00 |
1015704 |
41504 |
921772 |
5% |
/home |
| /dev/mapper/VolGroup00-LogVol02 |
1015704 |
70652 |
892624 |
8% |
/tmp |
/dev/mapper/VolGroup00-LogVol03
|
2031440
|
153976 |
1772608 |
8% |
/var |
|
Note: 1,240 blocks = 1 MB. So the /dev/mapper/VolGroup00-LogVol04 file system above with 3999424 blocks has a total size of 3.8GB (3999424 blocks / 1024K = 3905.6MB / 1024K = 3.8GB)
For those not familiar with the term inode or index node, they provide the ext3 file system with attribute values such as:
- File type (executable, block, special etc)
- Ower
- Group
- Permisions (read, write, executable)
- File size
- File access information (modification time, last access time, creation time etc.)
- Number of links (soft or hard)
- Extended attributes
- Access Control List information (ACL)
Every file on an ext3 file system has a inode, and just like disk space, you can run out of inodes. You can use the command df -i to inspect your free inode count (see below), but once the number of free inodes reaches 0, you will no longer be able to create new files on a file system. Enabling a inode quota will provide you with a means to limit the number of inodes a user/group can create. This has a direct correlation with the number of files the user/group will be able to create but can ensure that any one given user/group doesn't accidentally (or on purpose) use all the free indoes on the file system.
| [root@Linux01 ~]# df -i |
Filesystem
|
Inodes
|
IUsed |
IFree |
IUse% |
Mounted on |
/dev/mapper/VolGroup00-LogVol04
|
1032192 |
89266 |
942926 |
9% |
/ |
/dev/sda1
|
26104
|
33 |
26071 |
1% |
/boot |
tmpfs
|
257477
|
1 |
257476 |
1% |
/dev/shm |
| /dev/mapper/VolGroup00-LogVol00 |
262144 |
28 |
262116 |
1% |
/home |
| /dev/mapper/VolGroup00-LogVol02 |
262144 |
20 |
262124 |
1% |
/tmp |
/dev/mapper/VolGroup00-LogVol03
|
524288
|
900 |
523388 |
1% |
/var |
|
Note: You can see we have plenty of free inodes on each file system
Quota Configuration
Now that we have some background on the Linux Quota system, we are now ready to begin the quota configuration. Let's get started!
- Enable quota support by appending usrquota,grpquota to each of the file systems you wish to enforce a quota on within the /etc/fstab file. In the below example, we have enabled quota support on / and /home.
| /dev/VolGroup00/LogVol04 |
/
|
ext3 |
defaults,usrquota,grpquota |
1 |
1 |
| LABEL=/boot |
/boot |
ext3 |
defaults |
1 |
2 |
| devpts |
/dev/pts |
devpts |
gid=5,mode=620 |
0 |
0 |
| tmpfs |
/dev/shm |
tmpfs |
defaults |
0 |
0 |
| /dev/VolGroup00/LogVol00 |
/home
|
ext3 |
defaults,usrquota,grpquota |
1 |
2
|
| proc |
/proc |
proc |
defaults |
0 |
0 |
| sysfs |
/sys |
sysfs |
defaults |
0 |
0 |
| /dev/VolGroup00/LogVol02 |
/tmp |
ext3 |
defaults |
1 |
2 |
| /dev/VolGroup00/LogVol03 |
/var |
ext3 |
defaults |
1 |
2 |
| /dev/VolGroup00/LogVol01 |
swap |
swap |
defaults |
0 |
0 |
|
Note: The contents of your /etc/fstab file may differ. We have highlighted the additions which were added to our /etc/fstab file.
- Remount the file system(s) to enable quota support
[root@Linux01 ~]# mount -o remount / [root@Linux01 ~]# mount -o remount /home
|
- Initalize the new quota database. After running the quotacheck -cug <FILE SYSTEM> command, you will find a aquota.useraquota.group and file located in the root of each file system. These files describe the quota policy to be enforced on the file system(s) for each user and/or group and their associated grace time.
Initializing the database:
[root@Linux01 /]# quotacheck -cug / [root@Linux01 /]# quotacheck -cug /home/
|
Verify the creation of the quota database files:
[root@Linux01 /]# ls -al /aquota* -rw------- 1 root root 6144 May 26 17:15 /aquota.group -rw------- 1 root root 6144 May 26 17:15 /aquota.user [root@Linux01 /]# ls -al /home/aquota* -rw------- 1 root root 7168 May 26 17:16 /home/aquota.group -rw------- 1 root root 7168 May 26 17:16 /home/aquota.user
|
- Schedule a task in cron to scan the system for quota-checking. You should be aware that scanning the system can be I/O intensive. Your system may have different needs than the examples given below, but be aware and expect heavy I/O during the times the scans run (scheduling a scan in the middle of the day at peak production usage may not be the best idea.)
| #MIN (0-59) |
HOUR (0-23)
|
DoM (1-31) |
MONTH (1-12) |
DoW (0-7) |
CMD |
| 0 |
1 |
* |
* |
0 |
quotacheck -vug / |
| 20 |
1 |
* |
* |
* |
quotacheck -vug /home |
|
Note: In the above example, we have schedule a weekly scan of / for 1:00AM and a daily scan of /home scheduled for 1:20AM
- Enable quota support on the file system(s). The easiest way to enable quota support is to simply reboot the system. The systems init scripts should automatically enable quota support assuming its supported by the kernel. Optionally, you can use the quotaon command to enable quota support on a file system without having to reboot the system.
Note: For some distributions, you may have to enable quota support manually or create an init script to do so for you; consult you distributions documentation for details.
Enable quota support without a system reboot:
[root@Linux01 /]# quotaon /home [root@Linux01 /]# quotaon /
|
Verify quota support is enabled on a file system
[root@Linux01 /]# quotaon -p /home group quota on /home (/dev/mapper/VolGroup00-LogVol00) is on user quota on /home (/dev/mapper/VolGroup00-LogVol00) is on [root@Linux01 /]# quotaon -p / group quota on / (/dev/mapper/VolGroup00-LogVol04) is on user quota on / (/dev/mapper/VolGroup00-LogVol04) is on [root@Linux01 /]# |
Note: Quota support has been enabled on the /home and / file systems
Assigning Quota Policies
Now that we have configured our system with quota support, we are now ready to assign quota policies for our users and groups.
Before we begin however, its important to understand some of the terminology for policy enforcement. We will begin with limits. There are two types of limits, soft and hard. A soft limit provides a threshold for block count and/or inode usage that will trigger a warning message to a user/group once exceeded if used in conjunction with a grace period - more on grace periods in a moment. A hard limit, which also requires a grace period to be set, servers as a boundary for block counts and/or inode usage that a user/group can not exceed.
Grace periods serve as a count down for soft limit enforcement. Once the soft limit threshold has been passed, the grace period count down begins. Once the user/group's grace period has run out, the soft limit will be enforced as a hard limit. Grace periods are configured on a per file system bassis and can be set to seconds, minutes, hours or days.
Now that we understand limits and grace periods, we are ready to setup a quota. In the following example, we will set a quota for the user thirt, and set the default grace period for the / and /home file systems. We will set a block soft limit of 90MB, hard limit of 100MB with a 7 day grace period for /home and /. Let's begin!
- Start by editing the user's quota
[root@Linux01 /]# edquota thirt
|
- When edquota runs, you will be sent into the editor specified by your $EDITOR environment variable.
Note: If you are using the pico or nano editors, be very careful to avoid the line wraps associated with editing this file. Each file system should be contained on 1 line only!
You will see each of the file systems we have enabled quota support on (from the /etc/fstab) listed with the currently in-use blocks and inode counts for the user. Edit the users quota by changing the soft/hard columns of either the blocks and/or inodes for a given file system.
In the below, we will sets thirt's block quota to a warning limit of 90MB (90MB x 1024K = 92160 blocks) and a panic limit of 100MB (100MB x 1024K = 102400 blocks) on the /home file system (/dev/mapper/VolGroup00-LogVol00)
| Disk quotas for user thirt (uid 500): |
| Filesystem |
blocks |
soft |
hard |
inodes |
soft |
hard |
| /dev/mapper/VolGroup00-LogVol04 |
0 |
0 |
0 |
0 |
0 |
0 |
| /dev/mapper/VolGroup00-LogVol00 |
88 |
92160 |
102400 |
13 |
0 |
0 |
|
Note: A soft/hard limit of zero means no limit will be enforced
- Set the default grace period for each file system (this can be overridden on a per user bassis with a -T command line switch, see the edquota man pages for additional details.)
Set the default grace period for the / file system:
[root@Linux01 /]# edquota -f / -t
|
| Grace period before enforcing soft limits for users: |
| Time units may be: days, hours, minutes, or seconds |
| Filesystem |
Block grace period |
Inode grace period |
| /dev/mapper/VolGroup00-LogVol04 |
7days |
7days |
|
Set the default grace period for the /home file system:
[root@Linux01 /]# edquota -f /home -t
|
| Grace period before enforcing soft limits for users: |
| Time units may be: days, hours, minutes, or seconds |
| Filesystem |
Block grace period |
Inode grace period |
| /dev/mapper/VolGroup00-LogVol00 |
7days |
7days |
|
- Verify the quota configuration
Print all file systems and user/group quota information:
| [root@Linux01 /]# repquota -a |
| *** Report for user quotas on device /dev/mapper/VolGroup00-LogVol04 |
| Block grace time: 7days; Inode grace time: 7days |
|
|
Block limits |
File limits |
| User |
|
used
|
soft
|
hard
|
grace |
used
|
soft
|
hard
|
grace |
| root |
-- |
2391528 |
0 |
0 |
|
89211 |
0 |
0 |
|
rpm
|
-- |
796 |
0 |
0 |
|
49 |
0 |
0 |
|
|
| *** Report for user quotas on device /dev/mapper/VolGroup00-LogVol00 |
| Block grace time: 7days; Inode grace time: 7days |
|
|
Block limits |
File limits |
| User |
|
used
|
soft
|
hard
|
grace |
used
|
soft
|
hard
|
grace |
| root |
-- |
41428 |
0 |
0 |
|
8 |
0 |
0 |
|
thirt
|
-- |
88 |
92160 |
102400 |
|
13 |
0 |
0 |
|
|
|
Print a single user/groups quota information
| [root@Linux01 /]# quota thirt |
| Disk quotas for user thirt (uid 500): |
| Filesystem |
blocks |
quota |
limit |
grace |
files |
quota |
limit |
grace |
| /dev/mapper/VolGroup00-LogVol00 |
88 |
92160 |
102400 |
|
13 |
0 |
0 |
|
|
That's it! You should now be well on your way to configuring quotas in Linux! Best of luck!
Add this page to your favorite website
|