Sunday, 9 February 2014

Configure Quota in Linux

Configure Quota in Linux

Quota is a feature that allow you to set specific limit for specific user or group on particular disk partition. There are two types of limits A-soft limit: when user exceed their soft limit a warning appear but user is allowed to store data. B-Hard limit when exceed hard limit user is not allowed to store data beyond this limit.
For a working example, you can configure quotas on the /companydata file system so that you can limit the amount of data that users can store in this directory.

Follow these steps to apply quota.
You need to install the required packages before you can use quotas on your system.
To install the quota package, use the following:
# yum install – y quota

Verify that the package is installed successfully:
# rpm -qa | grep quota
quota-3.17-10.el6.x86_64

Although Red Hat supports quotas in the kernel by default but you can verify quota support from the kernel with the following command:
# grep -i config_quota /boot/config-`uname -r`
CONFIG_QUOTA=y
CONFIG_QUOTACTL=y
y means that the kernel support quotas.
After verifying that the package is installed and that the kernel does support quotas, you can start configuring Quota.

To start setting up quotas, let’s look at some of the commands:
quotaon    Turns on quota tracking
quotaoff   Turns off quota tracking
edquota    Edits the settings of a user’s quota
quota       Allows each user to see his disk consumption
repquota   Generates a report of quota usage
quotacheck Initializes a quota database

Configure quota
You first need to edit the /etc/fstab file to specify which file systems you want to utilize quotas. You can
apply quota limit for users, groups, or both.

Step 1. In the /etc/fstab file, edit the following line:
For example if i want to apply quota on /dev/sda5 partition which is mounted on /companydata and filesystem uses as ext4.

#vim /etc/fstab
/dev/sda5 /companydata ext4 defaults,usrquota,grpquota 1 2
Save and close the file.

Step 2. You now need to remount the /companydata file system before the changes take effect.
# mount -o remount /companydata

There are two files that maintain quotas for users and groups:
aquota.users User quota file
aquota.group Group quota file

To start the quota system, you use the quotacheck command.
Syntax: quotacheck [options] <partition>
-c Don’t read existing quota files
-u Checks user quotas
-g Checks group quotas
-m Doesn’t remount the file system as read-only

Step 3. Create the quota files:
# quotacheck -ugm /companydata/

Step 4. Verify that the quota files were created successfully:
# ls /companydata/
aquota.group aquota.user lost+found

Step 5. Run the command manually the first time just to make sure that quotas are turned on:
# quotaon -v /companydata/

Step 6. Now set the limit with edquota command
Syntax: edquota [-u | -g] [username | groupname]
Change the line for the /dev/sda5 file system to look like the following:
# edquota -u kamal
Disk quotas for user kamal (uid 502):
Filesystem     blocks   soft    hard   inodes soft hard
/dev/sda5       0       2000   2500   0       0   0
(where 2000 is soft limit and 2500 is hard limit in KB)
Save your changes and close the file.

Step 7. Login as kamal user and create some files and directories, Use the repquota command to verify uses quota limit.
# repquota -uv /companydata/

No comments:

Post a Comment

RADIUS Server Configure in Server 2012

Home About Me Apple Networking Software Storage Downloads Links Contact How to setup Radius for authentication wi...