Create User Quotas

by Mike on October 6, 2009 · 3 comments

in Server Management

You will want to create and test user quotas to guarantee system resources for all users.  Having been a Linux administrator for over 10 years I have never found a group of users that does not have someone who will abuse the resources on the server by using it all for themselves.  And, no talking with them and explaining the problems of running out of resources does not do much good with this specific type of individual.

Lesson 3 | Lesson 5

Once you have install the quotas program you will need to create specific resource limits for users.

centos_serverb

Add a User
useradd tom

Edit /etc/fstab to enable user quotas

vi /etc/fstab

If the /home directory was created with LVM it will look like this:
/dev/VolGroup00/LogVol00     /home    ext3     defaults         1  1

If you are not using LVM it but have a label it will look like this:
LABEL=/home                 /home    ext3     defaults         1  1

Now change the default line above which is for a Logical Volume to the one below which enables quotas.

/dev/VolGroup00/LogVol00    /home     ext3     usrquota         1  1

Save the change and then remount the  /home directory.

mount -o remount /home

Start the quotacheck

Change to init level 1

init 1

Run the quotacheck command:

quotacheck -cug /home

Return to runlevel 5 or runlevel 3.

init 5

Turn the quota on

quotaon  /home

Set user quota specifics.  Here the setquota command is used and a soft limit of 200 and a hard limit of 800 is set.  Yes, this is very small but it provide a way for you to test how it all works as the limits are hit quickly in testing.  You want to be very familiar with how it all works before you roll it out to your users.

setquota -u tom  200  800  0   0   /home

Test your settings as tom

su – tom

quota       (this will show current quotas for the user)

dd if=/dev/zero  of=filespace   bs=1k    count=150

Each time you increase space usage run quota to see the changes.

dd if=/dev/zero  of=filespace   bs=1k    count=900

Once you are done with testing be sure you understand how to increase or decrease limits on your system.  Both of the options can be performed with the edquota command and the “-u” option so that you can modify the resources for a user.

edquota -u fred
This command will open up fredś quota file which has seven columns. The top of the file will list the userś name and UID.
The first column will list the directory file system. This is usually in the format of the partition that the quotas are on. An example:
/dev/hda6
The second column lists the number of blocks that are currently used by the user. These are 1KB blocks. An example:
4485296
This is almost 4.5 GB.
The next two columns represent the soft and hard limits for the users. 0 means that the user has no limits. 4000000 in the soft limit means that when the user reaches 4 GB they will activate a message that they are in violation of their quota. The grace period set in days gives this user the opportunity to make changes to move under the soft limit. Once the grace period is over, the user will be forced to make the necessary changes.
The hard limit represents a boundary that the user will not be able to cross. Administrators do not need to set hard limits unless the grace period is used. If an administrator does not use the grace period the result will be that the soft limit will be the boundary for users.
Typically, users appreciate a reasonable boundary with a warning system so that in the middle of an important project they are not forced with deleting data before they can save. Of course there are always the users that will push it to the limit.

{ 1 comment }

sunny March 27, 2010 at 10:35 pm

great great detail explanation given. thank you very much

{ 2 trackbacks }

Previous post:

Next post: