Home » , , » RHCE Linux Disk Quota Implementation

RHCE Linux Disk Quota Implementation

Written By 1 on Saturday, February 5, 2011 | 12:26 PM

Disk quotas are commonly used by ISPs, by Web hosting companies, on FTP sites, and on corporate file servers to ensure continued availability of their systems.
Quotas are used to limit a users or a group of users ability to consume disk space. This prevents a small group of users from monopolizing disk capacity and potentially interfering with other users or the entire system.
Without quotas, one or more users can upload files on an FTP server to the point of filling a file system. Once the affected partition is full, other users are effectively denied upload access to the disk. This is also a reason to mount different file system directories on different partitions. For example, if you only had partitions for your root (/) directory and swap space, someone uploading to your computer could fill up all of the space in your root directory (/). Without at least a little free space in the root directory (/), your system could become unstable or even crash.
You have two ways to set quotas for users. You can limit users by inodes or by kilobyte-sized disk blocks. Every Linux file requires an inode. Therefore, you can limit users by the number of files or by absolute space. You can set up different quotas for different file systems. For example, you can set different quotas for users on the /home and /tmp directories if they are mounted on their own partitions. Limits on disk blocks restrict the amount of disk space available to a user on your system. Older versions of Red Hat Linux included LinuxConf, which included a graphical tool to configure quotas. Red Hat no longer has a graphical quota configuration tool. Today, you can configure quotas on RHEL only through the command line interface.
Lets look few basic terms used for implementation of disk quota
  • Soft limit
    This is the maximum amount of space a user can have on that partition. If you have set a grace period, this will act as an alarm. The user will then be notified she is in quota violation. If you have set a grace period, you will also need to set a hard limit. A grace period is the number of days a user is allowed to be above the given quota. After the grace period is over, the user must get under the soft limit to continue. By default grace period have seven days limits.
  • Hard limit
    Hard limits are necessary only when you are using grace periods. If grace periods are enabled, this will be the absolute limit a user can use. Any attempt to consume resources beyond this limit will be denied. If you are not using grace periods, the soft limit is the maximum amount of available space for each user.
  • Grace Periods
    Linux has provided the default of seven days for both inodes and block usage. That is, a user may exceed the soft limit on either resource for up to seven days. After that, further requests by that user to use files will be denied.
Reference Table
Soft Limit Disk space a user can use
Hard limit Absolute limit a user can use
Grace Periods Time duration till user can use hard limit space
1 inode 1 KB
dd used to create a blank file of specific size
required RPM quota-3.13-1.2.3.2.el5
/etc/fstab options usrquota, grpquota
Quota files aquota.user, aquota.group
Necessary command mount, quotaon, quotacheck, edquota, quotaoff

Quota Tools

Quota checks can be implemented on the file system of a hard disk partition mounted on your system. The quotas are enabled using the quotacheck and quotaon programs. They are executed in the /etc/rc.d/rc.sysinit script, which is run whenever you start up your system. Each partition needs to be mounted with the quota options, usrquota or grpquota. usrquota enables quota controls for users, and grpquota works for groups.
You also need to create quota.user and quota.group files for each partition for which you enable quotas. These are the quota databases that hold the quota information for each user and group. You can create these files by running the quotacheck command with the -a option or the device name of the file system where you want to enable quotas.

edquota

You can set disk quotas using the edquota command. With it, you can access the quota record for a particular user and group, which is maintained in the disk quota database. You can also set default quotas that will be applied to any user or group on the file system for which quotas have not been set. edquota will open the record in your default editor, and you can use your editor to make any changes. To open the record for a particular user, use the -u option and the username as an argument for edquota

quotacheck, quotaon, and quotaoff

The quota records are maintained in the quota database for that partition. Each partition that has quotas enabled has its own quota database. You can check the validity of your quota database with the quotacheck command. You can turn quotas on and off using the quotaon and quotaoff commands. When you start up your system, quotacheck is run to check the quota databases, and then quotaon is run to turn on quotas.

repquota

As the system administrator, you can use the repquota command to generate a summary of disk usage for a specified file system, checking to see what users are approaching or exceeding quota limits. repquota takes as its argument the file system to check; the -a option checks all file systems.
In our next article we will practically implement all these commands.

In our pervious article we learn about basic necessary concept used for disk quota implementation. Now we will first look at the outline of question that may be asked in RHCE exam.
Example 1
Quota is implemented on /home but not working properly. Find out the Problem and implement the quota to vinita to have a soft limit 50 inodes (files) and hard limit of 100 inodes (files).
Example 2
vinita user tried by:
dd if=/dev/zero of=/home/vinita/test bs=1024 count=50
files created successfully. Again vinita tried to create file having 100k using following command:
dd if=/dev/zero of=/home/vinita/test1 bs=1024 count=100
But she is unable to create the file. Make the user can create the file less then 100K.

Solutions

Example 2 is extremely complicated question from Redhat. Actually question is giving scenario to you to implement quota to vinita user. You should apply the quota to vinita user on /home that vinita user shouldn’t occupied space more than 100K.
To solve disk quota question follow these guides
Check the quota RPM (installed by default)
disk quota rpm
Now open /etc/fstab file to enable quota entry

/etc/fstab
You can tell Linux to start tracking user quotas by adding the keyword usrquota under the options column. Similarly, you can tell Linux to start tracking group quotas with the grpquota option.
I add both user and group quotas to the /home directory filesystem
/etc/fstab
Either Reboot the System or remount the partition and verify it
 remount home partition
The next step is to create quota files. For user and group quotas, you will need the aquota.user and aquota.group files in the selected filesystem before you can activate actual quotas.
You can do it either manually or the appropriate quotacheck command creates them automatically.
For the /home directory described earlier, you would use the following commands:
# mount -o remount /home
# quotacheck -cugm /home
The options for quotacheck are
  • -c Performs a new scan.
  • -v Performs a verbose scan.
  • -u Scans for user quotas.
  • -g Scans for group quotas.
  • -m Remounts the scanned filesystem.
This will check the current quota information for all users, groups, and partitions. It stores this information in the appropriate quota partitions. Once the command is run, you should be able to find the aquota.user and aquota.group files in the configured directory.

or you can create these files manually
#touch /home/aquota.group
#touch /home/aquota.user
aquota.group aquota.user files
On this quota by quotaon command and create an example user named vinita. use edquota command to set quota on vinita user.
edquota command will edits the aquota.user or aquota.group file with the vi editor. In our example, we have a user named vinita, and we want to restrict how much disk space she is allowed to use.
Set softlink to 50 and 100 to hard link

You can also set grace period for user ( set only if you are asked by examiner)

We will change default 7 days grace period to 10 days.


Remount the partition and verify it
 remount home partition
Verify that you have successfully implemented disk quota

Now login from vinita
When testing quotas, there is one useful technique that creates a blank file of the desired size. For example, if you want to create a 100MB file named test in the local directory, run this command
dd if=/dev/zero of=test bs=1k count=100000 .
impletementing disk quota
When user vinita run dd command first time to create a blank file more then 50 Mb she got an warning and the file was created. As she is allowed to exceed her soft limit for 10 days.
Second time she tried to create a file of 500 Mb. As you can see in image she was able only to create a file of 20 Mb. As she can not exceed her hard limit that is set to 100 inode.
In third time she is denied to use any more space as she have already crossed her hard limit.
You can verify the space of created file by du command with -h options.
After successfully completing your practical remove quota entry /etc/fstab

Now turn off quota by quotaoff command and remount home partition for further practical


0 Comment:

Post a Comment