Posted by: kezhong | June 17, 2009

Manage disk space using quota

On Linux system, each user can access unused disk space as a common resource. If one user occupied too much disk space, the other users would get less space. So it is very important for a system administrator to limit the user disk space using quota.  

The limit is classified into a soft limit and a hard limit on the number of blocks or inodes. The hard limit defines the absolute maximum disk space available to a user. When this value is reached, the user can’t use any more space. The soft limit is that the user is only warned when he exceeds the limit. He can still create new files and use more space, as long as you set a grace period, which is a length of time for which the user is allowed to exceed the soft limit.

In my lab, I did the test on Fedora 10. I set 10MB soft limit (7 days grace period) and 15MB hard limit for a user named joker.

1. Edit the /etc/fstab file, and add qualifier “usrquota” or “grpquota” to the partition.
# vi  /etc/fstab
/dev/sda5   /home  ext3   defaults,usrquota,grpquota   1  2

And remount the partition.
# mount -o remount /home  

2. Create quota files using the quotacheck command. After issue it, the aquota.user and aquota.group files will be generate under the /home directory.
# quotacheck  -vguma
quotacheck: Scanning /dev/sda5 [/home] done
quotacheck: Checked 75 directories and 79 files

3. Enable disk quotas.
# quotaon  -guva
/dev/sda5 [/home]: group quotas turned on
/dev/sda5 [/home]: user quotas turned on

4. Edit the quotas for the user and group using the edquota command. The method of edit is the same with vi editor commands.
# edquota  -u  joker
Disk quotas for user joker (uid 500):
  Filesystem                   blocks       soft       hard       inodes     soft     hard
  /dev/sda5                      872          10240    15360        149      1000    1200

# edquota  -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem             Block grace period     Inode grace period
/dev/sda5                      7days                  7days

5. List quotas I have set:
# quota -u joker
Disk quotas for user joker (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sda5     872   10240   15360              149*   1000   1200  6days
    

6. Verify
Turn off and turn on the quotas. Log in with the user joker and create a big file that the size exceeds the hard limit (15MB).
# quotaoff –guvf /home
# quotaon –guva

 $ dd if=/dev/zero of=test1 bs=1M count=16
Dd: writing ‘test1’: Disk quota exceeded
15+0 records in
14+0 records out
14815232 bytes (15MB) copied, 0.113032 s, 131 MB/s

7. Check the quota report.
#repquota  -a
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
                       Block limits                File limits
User            used    soft    hard       grace    used  soft  hard  grace
———————————————————————-

root      —   34116       0       0                       4        0          0
joker     +-   15360   10240  15360  6days     150  1000    1200

References
http://www.linux.com/archive/feature/118885
http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html

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

Categories

%d bloggers like this: