A disk quota is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of using disk quotas is to allocate limited disk space in a reasonable way.
Step 1. Verify that the package was installed successfully:
Step 2. You can query quota support from the kernel with the following command:
You should see a y next to the options to show that the kernel does indeed support quotas. For a working example, you can configure quotas on the /opt/hanthuy data file system system so that you can limit the amount of data that users can store in the hanthuy’s directory.
Setting Up Quotas
To start setting up the quotas, let’s look at some of the commands you can use with them:
quotaon Turns on quota tracking
quotaoff Turns off quota tracking
edquota Edits the settings of a users quota
quota Allows each user to see his disk consumption
repquota Generates a report of quota usage
quotacheck Initializes a quota database
Now that you have a listing of commands you can use, you first need to edit the /etc/fstab file to specify which file systems you want to utilize quotas. You can have quotas that limit users, groups, or both. You can enable both by adding the usrquota option and the grpquota option to the /etc/fstab file. It doesn’t hurt to enable them both in case you find a need for the other later.
You need to remount the /opt/hanthuy file system before the changes take effect.
With the quota options now in place on the /opt/hanthuy file system, you can begin setting up quotas for users. There are two files that maintain quotas for users and groups:
aquota.users User quota file
aquota.group Group quota file
These two files are automatically created in the top-level directory of the file system where you are turning quotas – in this case, the /opt/hanthuy file system. To start the quota system, use the quotacheck command.
Syntax: quotacheck [options] <partition>
-c Don’t read existing quota files
-u Checks only user quotas
-g Checks only group quotas
-m Doesn't remount the system as read only
-v Provides verbose output
The quotacheck command shouldn’t be run on file system that are actively being used because it can cause corruption. Now, you can create the quota files:
Enabling Quotas
The quotaon command can’t be called until the quota files are created in the root directory of the quota file system. Run the command manually the first time just to make sure that quotas are turned on:
Let’s briefly discuss the two different limits you can have when dealing with quotas:
+ Soft Limit: Has a grace period that acts as an alarm, signaling when you are reaching your limit. If your grace period expires, you are required to delete files until you are once again under your limit. If you don’t specify a grace period, the soft limit is the maximum number of files you can have.
+ Hard Limit: Required only when a grace period exists for soft limits. If the hard limit does exist, it is the maximum limit that you can hit before your grace period expires on the soft limit.
With these two limits in mind, you can begin creating limits for your first user01. Use the edquota command to set it up. To work with quotas for users and groups, you need to do some conversions in your head here. Each block is equal to 1KB; remember that 1,000KB = 1MB.
Syntax: edquota [-u | -g] [username | groupname]
# edquota -u user01
Now that user01 has a quota, you should also set a grace period for this user (because you specified a hard limit).
# edquota -t
Note: The edquota command offers a pretty cool feature. You can actually copy this over to other users as if it were a template.
# edquota -up user01 user02 user03
Now with the quotas in place for users, let’s start looking at some of the reporting options available to check on users.
Quota Usage Reports
You can use the repquota command to collect information about file system quotas.
Syntax: repquota [options] <partition>
-a Reports on all non-NFS file systems with quotas turned on
-u Reports on user quotas
-g Reports on group quotas
-v Provides verbose output
For example, use the repquota command to collect some information on the user quotas you have recently implemented:
Here, a nicely detailed report shows how quotas are doing for each individual user. Later, it might be helpful to setup a job for a daily or weekly report on user and group quota usage. This allow you, as an administrator, to keep an eye on your file systems and make sure that they aren’t getting out of hand.
Have fun!