Praji’s Weblog

Welcome to praji’s world

Linux quota

leave a comment »

Quota allows to specify limits on two aspects of disk storage:

1. The number of inodes a user or a group of users may possess;
2. The number of disk blocks that may be allocated to a user or a group of users.

Implementing Disk Quotas on Linux

Installation

$ rpm -q quota
quota-3.12-6

Quotas

Run quotecheck. The first time you run this command, use the “-c” option to create the necessary database files. The following should be run as root.

1)     setquota – command line quota editor

You can also use the setquota command, which has the advantage of not using an editor making it ideal for implementing in a script. For example, to set the soft block limit to 100, a hard block limit of 200, a soft inode to 10 and a hard inode to 15 as we did above, execute the following command.

SYNTAX
1)  To ser quota we can use
# setquota -u chirico 100 200 10 15  -a /dev/loop0

2)  Turn quotas on with the following command.

# quotaon /quota
3)
quota
Disk quotas for user chirico (uid 500):
Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/loop0       1     100     200               1      10      20

Note that the number of files has not changed. However, if you create a symbolic link, sometimes called a soft link, with the “ln -s” command, the number will increse to 2, because an additional inode is created with a soft link.

$ ln -s /quota/share/t1 /quota/share/t3

$ quota
Disk quotas for user chirico (uid 500):
Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/loop0       2     100     200               2      10      20

Quotas for Groups

To set quotas for the group “quotagrp”, use the following command.

# edquota -g quotagrp
Disk quotas for group quotagrp (gid 619):
Filesystem                   blocks       soft       hard     inodes     soft     hard
/dev/loop0                        6          0          0          4        0        0

Now make the following changes.

Disk quotas for group quotagrp (gid 619):
Filesystem                   blocks       soft       hard     inodes     soft     hard
/dev/loop0                        6          5        100          4        6       10

Or, use the “setquota” command as follows:

# setquota -g quotagrp 5 100 6 10 -a /dev/loop0

Now run the following command under the user account that has group access, which will attempt to create 15 files.

$ for i in $(seq 15); do  touch “/quota/share/file_$i”; done
loop0: warning, group file quota exceeded.
loop0: write failed, group file limit reached.
touch: cannot touch `/quota/share/file_7′: Disk quota exceeded

Reports

The “repquota” command prints a summarized report. It should be run with root.

# repquota /quota
*** Report for user quotas on device /dev/loop0
Block grace time: 7days; Inode grace time: 7days
Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
———————————————————————-
root      —    1204       0       0              5     0     0
chirico   —      10     100     200              9    10    20

To get a report by group, use the -g option as follows.

# repquota -g /quota
*** Report for group quotas on device /dev/loop0
Block grace time: 7days; Inode grace time: 7days
Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
———————————————————————-
root      —    1202       0       0              4     0     0
quotagrp  ++      12       5     100  6days      10     6    10  6days

Note the “++” above for quotagrp indicating that both the block limit and inode limits have been exceeded.

Or to get everything, run repquota with the -a option as follows.

# repquota -a

warnquota – send mail to users over quota

Running warnquota without any options will email users that go over the limit.

# warnquota

However in this case no mail message will be sent, because the group limit was exceeded. The file “/etc/quotagrpadmins” needs to contain a username responsible for the group. Here will put in the user “sporkey”, so that the file looks as follows:

#
# This is a sample groupadmins file (/etc/quotagrpadmins)
#
#  Comments begin with hash in the beginning of the line

# In this file you specify users responsible for space used by the group
users: root
mygroup: chief
quotagrp: sporkey

Now if warnquota is execute with the -g option, mail will be send to user “sporkey”.

# warnquota -g /quota

Messages can be customized by editing the “/etc/warnquota.conf” file.

Written by praji

January 8, 2008 at 8:22 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: