Tuesday 13 September 2011

Managing Disk Usage with Quotas In Linux

Introduction:- You may eventually need to restrict the amount of disk space used on each partition by each user or group of users as your disk drives become filled with data. The disk quota feature of RedHat/Fedora Linux enables you to do this, and the setup is fairly simple.

 Steps to Implement Quota
Note :- Configuration of disk usage quotas on Linux - Perform the following as root:
Step1. Edit file /etc/fstab to add qualifier "usrquota" or "grpquota" to the partition. The following file system mounting options can be specified in /etc/fstab: grpquota, noquota, quota and usrquota. (These options are also accepted by the mount command but ignored.) The filesystem when mounted will show up in the file /etc/mtab, the list of all currently mounted filesystems.)

To enable user quota support on a file system, add "usrquota" to the fourth field containing the word "defaults".

/dev/hda2     /home   ext3    defaults,usrquota             1    1

Replace "usrquota" with "grpquota", should you need group quota support on a file system.

/dev/hda2     /home   ext3    defaults,grpquota             1    1

Need both user quota and group quota support on a file system?

/dev/hda2     /home   ext3    defaults,usrquota,grpquota   1    1

 This enables user and group quotas support on the /home file system.

Step 2. 

#touch /partition/aquota.user
where the partition might be /home or some partition defined in /etc/fstab.

then

#chmod 600 /partition/aquota.user

The file should be owned by root. Quotas may also be set for groups by using the file aquota.group
Quota file names:

    Quota Version 2 (Linux 2.4/2.6 kernel: Red Hat 7.1+/8/9,FC 1-3): aquota.user, aquota.group

    Quota Version 1 (Linux 2.2 kernel: Red Hat 6, 7.0): quota.user, quota.group

The files can be converted/upgraded using the convertquota command.


Step3. Re-boot or re-mount file partition with quotas.

    Re-boot: shutdown -r now

    Re-mount partition: mount -o remount /partition

After re-booting or re-mounting the file system, the partition will show up in the list of mounted filesystems as having quotas. Check /etc/mtab:

 /dev/hda5 / ext3 rw,usrquota 0 0

 Step 4. Initialize The Quota Table

 #quotacheck -vgum /partition
or

#quotacheck -vguma

 For example (Linux kernel 2.4+): quotacheck -vguma

quotacheck: WARNING -  Quotafile //aquota.user was probably truncated. ...
quotacheck: Scanning /dev/hda5 [/] done
quotacheck: Checked 9998 directories and 179487 files

Quotacheck is used to scan a file system for disk usages, and updates the quota record file quota.user/aquota.user" to the most recent state. It is recommended thet quotacheck be run at bootup

Step 5. # quotaon -av


System Response: /dev/hda6: user quotas turned on
quotaon - enable disk quotas on a file system.
quotaoff - turn off disk quotas for a file system.

Step 6. # edquota -u user_id

Edit directly using vi editor commands. (See below for more info.)

For example: # edquota -u user1

Disk quotas for user user1 (uid 501):
Filesystem  blocks       soft       hard   inodes   soft    hard
/dev/hda5  1944          0          0        120        0        0

    blocks: 1k blocks

    inodes: Number of entries in directory file

    soft: Max number of blocks/inodes user may have on partition before warning is issued and grace period  countdown begins.
    If set to "0" (zero) then no limit is enforced.

    hard: Max number of blocks/inodes user may have on partition.
    If set to "0" (zero) then no limit is enforced

If editing group quotas: # edquota -g group_name

 Step 7. List quotas: # quota -u user_id

For example: # quota -u user1

System response:

Disk quotas for user user1 (uid 501):

Filesystem blocks quota limit grace   files quota limit grace
/dev/hda6 992 50000 55000   71 10000 11000  






No comments:

Post a Comment

Do not post irrelevant comments, please!

Browser Name:
Browser Version:
Browser Code Name:
User-Agent: