🌐 🇵🇱 Polski · 🇬🇧 EN
QUOTAS - disk limits that define the available disk space sizes for individual users. If we’ve already covered all the topics from the previous chapters, let’s add another tool that streamlines system management and administration. We’ll see how to allocate a limited amount of disk space to a specific user.
Step 1 - Install the quota package.
# yum install – y quota
Step 2 - Verify the package installation
# rpm -qa | grep quota
quota-3.17-10.el6.x86_64
Although this package should be included in the system by default, it’s always worth checking if it’s installed and working correctly.
Step 3 - Check if the kernel supports quota
# grep -i config_quota /boot/config-`uname -r`
CONFIG_QUOTA=y
CONFIG_QUOTACTL=y
If you see "y", it means the kernel supports "quota".
CONFIGURING QUOTA LIMITS
First, let’s look at the commands we’ll be using:
- quotaon - Enable quota configuration
- quotaoff - Disable quota restrictions
- edquota - Edit user quota settings
- quota - Allow a user to use disk space
- repquota - Generate a quota usage report
- quotacheck - Initialize the quota database
We’ve already covered the commands we’ll use to set limits. Now, first, we need to edit the /etc/fstab file to specify which filesystems should enforce "quota". Restrictions can apply to users, groups, or both simultaneously.
Step 1 - Edit the /etc/fstab file by adding the following line:
/dev/hdb1 /opt/company_data ext4 defaults,usrquota,grpquota 1 2
Step 2 - Save and close the file
WARNING
If you edit the file in a text editor, it might incorrectly save the new line. Make sure this doesn’t happen. If the system detects during startup that the values in the /etc/fstab file are split across two lines, it will treat this as an error and the system will fail to boot.
Now, remount the filesystem to apply the changes.
Step 3 - Remount
# mount -o remount /opt/company_data
Step 4 - Verify the changes
# mount | grep company_data
/dev/hdb1 on /opt/company_data type ext4 (rw,usrquota,grpquota)
With the quota limitation options added to the /opt/company_data entry, we can now configure the specific limit options. There are two files where we define user and group limits:
aquota.users User quota limit file
aquota.group Group quota limit file
These two files are automatically created in the filesystem directory when quota options are enabled. The examples below apply to the /opt/company_data filesystem. To start using the quota system, use the quotacheck command.
The quotacheck command syntax: # quotacheck [options] <partition>
Quota check options:
Quota check options:
- -c - Do not read existing quota files
- -u - Check only user limits
- -g - Check only group limits
- -m - Do not remount the filesystem as read-only
- -v - Display information about current operations
Quota limits should not be set on actively used filesystems, as this can lead to corruption. To protect against this, the quota tool remounts the filesystem as read-only. Since we don’t want the /opt/company_data partition to become read-only, we can use the "-m" switch to prevent this. In this case, we also know that no other quota files existed, so corruption is unlikely.
Step 5 - Create quota limit files
# quotacheck -ugm /opt/company_data/
Step 6 - Verify that the files were created correctly
# ls /opt/company_data/
aquota.group aquota.user lost+found
ENABLING AND APPLYING QUOTA
Normally, we use the "quotaon" or "quotaoff" commands to enable or disable quota on filesystems. However, if we want quota to be applied automatically at system startup, the quotaon command cannot reference the limit files created in the "root" directory.
Step 1 - Manually enable quota
# quotaon -v /opt/company_data/
/dev/hdb1 [/opt/company_data]: group quotas turned on
/dev/hdb1 [/opt/company_data]: user quotas turned on
Let’s briefly discuss the two types of quota limits:
- Soft Limit - A limit defining the maximum disk space a user can use, with a grace period acting as an alarm when the limit is reached. If the grace period expires, the user must remove excess files. If no grace period is set, the soft limit defines the maximum number of files a user can own.
- Hard Limit - Applies when a grace period is set in the soft limit. If enabled, it represents the absolute maximum limit a user can reach before the soft limit’s grace period expires.
With these limits in mind, you can start setting restrictions for the users in the system you manage. In this system, there should already be a user named User01 (if not, create one). Let’s use the "edquota" command to configure their quota. Since the user doesn’t yet have access to this part of the filesystem, they aren’t using any space here. To properly allocate disk space for users, you should make some assumptions and plan accordingly. Each block equals 1 KB. Remember that in this case, 1,000 KB = 1 MB, so you’re only allocating 40 KB of free space. You can also limit the number of files a user can own. We can also set soft and hard limits for the User01 user. For this exercise, let’s set the limits to 20 MB for the soft limit and 25 MB for the hard limit. We’ll use the "edquota" command to configure these limits.
The edquota command syntax: # edquota [ -u | -g ] ( username | groupname)
Step 2 - Modify the /dev/hdb1 filesystem settings as follows:
# edquota -u user01
Disk quotas for user user01 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hdb1 0 20000 25000 0 0 0
Step 3 - Save changes and close the file
User01 now has defined space limits. Let’s also set grace periods for this user.
Step 4 - Use the edquota command again with a different switch
# edquota -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/hdb1 7days 7days
Step 5 - Modify the last line as follows:
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/hdb1 2days 2days
Step 6 - Save changes and close the file
WARNING
Do not use spaces when entering limits in the files.
To apply the same limits to other users, simply copy these permissions:
# edquota -up user01 user02 user03
The user restrictions have been applied. Now, let’s see how to review the set limits.
QUOTA REPORTS
We can use the "repquota" command to gather information about the set limits.
The repquota command syntax: # repquota [options] <partition>
Quota report options:
Quota report options:
- -a Report on all non-NFS filesystems
- -u Report user limits
- -g Report group limits
- -v Display information about ongoing tasks
Step 1 - Display user quota limit information for the system
# repquota -uv /opt/company_data/
*** Report for user quotas on device /dev/hdb1
Block grace time: 2days; Inode grace time: 2days
Block limits File limits
User used soft hard grace used soft
hard grace
—————————————————————————————————
——
root — 142656 0 0 4 0 0
user01 — 0 20000 25000 0 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
We see a lot of information about the set limits. Later, we can automate this process to collect daily, weekly, or other reports for specific users. This information gives administrators insight into how users utilize disk space in the environment.
Comments