Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

User quota allocation on linux

How to allocate quota to users and control the resource utilization? by MaheshRathi
Posted: 25 Jan 02

1. Quota on Linux
What is Quota?
Quota allows the administrator to specify limits on two aspects of disk storage û
a.    The number of inodes a user or a group of users may possess, and
b.    The number of disk blocks that may be allocated to a user or a group of users.

What is the need of Quota?
 The idea behind quota is that users are forced to stay under their disk consumption limit, taking away their ability to consume unlimited disk space on a system.
Quota is handled on a per user, per file system basis.

2. Steps to enable the quota for the users

Create quota "quota.user" / "quota.group"
a.    Both quota record files, quota.user and quota.group, should be owned by root, and read-write permission for root and none for anybody else.
b.    Login as root. Go to the root of the partition you wish to enable quota, say /home, then create quota.user and quota.group by doing:

touch  /home/quota.user
touch  /home/quota.group
chmod 600 /home/quota.user
chmod 600 /home/quota.group

Modify /etc/fstab
a.    Partitions that you have not yet enabled quota normally look something like:
/dev/hda1    /        ext2    defaults        1       1
/dev/hda2    /home    ext2    defaults        1       1

b.    To enable user quota support on a file system, add "usrquota" to the fourth field containing the word "defaults" (man fstab for details).
/dev/hda1       /       ext2    defaults        1       1
/dev/hda2       /home    ext2    defaults,usrquota       1       1

c.    Replace "usrquota" with "grpquota", should you need group quota support on a file system.
/dev/hda1       /       ext2    defaults        1       1
/dev/hda2       /home    ext2    defaults,grpquota    1       1

d.    Need both user quota and group quota support on a file system?
/dev/hda1       /       ext2    defaults        1       1
/dev/hda2       /home    ext2    defaults,usrquota,grpquota       1       1

Check quota
You can check the quota using ôquotacheckö utility. It will update the quota.user and quota.group data files. ItÆs always preferable to run quotacheck with the flags -avug to obtain the most updated filesystems usage prior to editing quota.

/usr/sbin/quotacheck ûavug

Assigning Quota for users and Groups
This operation is performed with the edquota command.

a.    Assigning quota for a particular user
For example, LetÆs assign some quota to user Mahesh whose login id is mahesh. The command "edquota -u mahesh" takes us into vi to edit quota for user mahesh on each partition that has quota enabled:

Quotas for user mahesh:
 /dev/hda2: blocks in use: 504, limits (soft = 2500, hard = 5000)
       inodes in use: 156, limits (soft = 800, hard = 1500)

b.    Assigning quota for a particular group
For example, LetÆs assign some quota to group snmp. The command "edquota -g snmp" takes us into the vi editor again to edit quota for the group snmp:

Quotas for group snmp:
/dev/hda4: blocks in use: 3709, limits (soft = 5000, hard = 8000)
      inodes in use: 1254, limits (soft = 2500, hard = 4000)

c.    Assigning quota for a bunch of users with the same value
To rapidly set quotas for all the users, on a system to the same value as user mahesh, then we should first edit mahesh's quota information by hand, then execute:
        edquota -p mahesh `awk -F: '$3 > 499 {print $1}' /etc/passwd`

(Assuming that you assign your user UID's starting with 500.)

Turning on and off the quota
You can turn on the quota using the utility ôquotaonö.
    /usr/sbin/quotaon ûavug

You can turn off the quota using the utility ôquotaoffö.
    /usr/sbin/quotaoff ûa

Ideally, quota should be turn on only after your file systems in /etc/fstab have been mounted, otherwise quota will fail to work. So, turning quota on at the end of your system init script is always preferable.

3. Miscellaneous Quota Commands
a.    Quotacheck
Quotacheck is used to scan a file system for disk usages, and updates the quota record file "quota.user" to the most recent state. We can run quotacheck at system bootup, or via cronjob periodically.

b.    Repquota
Repquota produces a summarized quota information for a file system. Here is a sample output repquota gives:

    # repquota -a
Block limits                File limits
User        used    soft    hard    grace        used    soft    hard    grace
root          --    234932    0    0            4630    0    0       
mahesh    --    680    5000    7000            118    250    600    
viru        -+    852    5000    7000            572    250    600   none
mohit_g   ++    6060    5000    7000    none        579    250    600   none

c.    Quotaon and Quotaoff
Quotaon is used to turn on quota accouting; quotaoff to turn it off. Actually both files are similar. They are executed at system startup and shutdown.

4. Controlling the resources available for the processes
The command line utility ôulimitö provides control over the resources available to processes started by the shell, on systems that allow such control. The following options can be used for controlled use of resources:
æ-cÆ for maximum size of core files created.
æ-dÆ for maximum size of a process data segment.
æ-fÆ for maximum size of file created by the shell.
æ-nÆ for maximum number of open file descriptors.
æ-sÆ for maximum stack size.
æ-tÆ for maximum amount of cpu time in seconds.
æ-uÆ for maximum number of processes available for a single user.

For example,
ulimit ûn 1024 ûu 50 ûc 1000000
stands for û
1.    Maximum open file descriptors û 1024
2.    Maximum process, a single user can create û 50
3.    Maximum size of core file û 1000000 bytes

You can add this command at the end of ô/etc/profileö so that itÆs applicable to all the users.

4. Frequently Asked Questions

a.    What does ôblocks in useö and ôinodes in useö mean?
Ans.  "Blocks in use" is the total number of blocks (in kilobytes) a user has consumed on a partition. "Inodes in use" is the total number of files a user has on a partition.

b.    How can I change the default editor for edquota?
Ans.  Default ôviö editior can be changed by specifying the some other editor name in $EDITOR environment variable.

c.    What is Soft Limit?
Ans.  Soft limit indicates the maximum amount of disk usage a quota user has on a partition. When combined with grace period, it acts as the borderline, which a quota user is issued warnings about his impending quota violation when passed.

d.    What is Hard Limit?
Ans.  Hard limit works only when grace period is set. It specifies the absolute limit on the disk usage, which a quota user can't go beyond his hard limit.

e.    What is Grace Period?
Ans.  Executed with the command "edquota -t", grace period is a time limit before the soft limit is enforced for a file system with quota enabled. Time units of sec(onds), min(utes), hour(s), day(s), week(s), and month(s) can be used.

The command "edquota -t" gives this:

Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/hda2: block grace period: 0 days, file grace period: 0 days

We can change the 0 days part to any length of time say 7 days (or 1 week).

Back to Linux (server) FAQ Index
Back to Linux (server) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close