SUSE Conversations


Linux Disk Quotas



By: DamianMyerscough

April 3, 2008 7:01 am

Reads:957

Comments:3

Rating:0

Linux Disk Quotas

In this article we are going to look at setting up disk quotas for individual users and a group of users. In this article we have the /home partition on a separate logical volume thus allowing us to enforce quota limits without having to reboot the machine. If you only have one partition you will need to reboot your machine to activate quotas.

So you may be wondering why you would want to setup and enforce disk quotas? The answer to this is question is simple, you want to restrict the amount of disk space the users occupy to stop them from hogging all of the disk space.

Installation

The first task that needs to be done before enabling and enforcing quotas is to install the quotas package, this can be done simply by issuing the “yast sw_single” or the “yast2” command. Once the YaST installation program starts you can search for the quota package by searching for the keyword “quota“.

Enabling Quotas

Once you have successfully installed the quota package you can enable user and group quotas. To enable user and group quotas you will need to edit the “/etc/fstab” file and in the fourth filed add: “usrquota,grpquota” as shown in Figure 1.

/dev/VolGroup00/LogVol03        /home                   reiserfs    acl,user_xattr,usrquota,grpquota        1 1

Figure 1: “/etc/fstab” table with quotas enabled.

Once you have modified the “/etc/fstab” file you can remount the partition as shown in Figure 1.2, however, if the mount point you have enabled quotas on is the root of the file system (i.e. “/”) you will need to reboot your machine.

linux-48l1:/ # mount /home -o remount

Figure 1.2: Remounting the “/home” partition with quotas.

Once you have issued the “mount” command you can issue the command on its own to see if the partition has been mounted with user and group quotas as shown in Figure 1.3.

/dev/mapper/VolGroup00-LogVol03 on /home type reiserfs (rw,acl,user_xattr,usrquota,grpquota)

Figure 1.3: Checking the quotas are enabled.

Turning Quotas on

Once you have verified that the partitions have been remounted with user and group quotas enabled you will need to build a table of the current disk space usage. This can be done using the “quotacheck” command as shown in Figure 2.

linux-48l1:/ # quotacheck -cugv /home

Figure 2: Building a table of the current disk usage.

Once the “quotacheck” utility has finished building the disk space usage table you may notice two files in the “/home” directory called: “aquota.group” and “aquota.user”. These two files contain information on how much space is being used and by whom it is being used by.

Once the two quota tables have been created you can now turn the quotas on by issuing the “quotaon” command as shown in Figure 2.1.

linux-48l1:/ # quotaon -ugv /home

Figure 2.1: Turning user and group quotas on.

Once the quotas have been enabled you can set and enforce quotas for users and groups.

Setting a user quota

In this section of the article we will look at setting up a quota for the user “damian”. The command to manage quotas is “edquota“. The “edquota” command uses the “-u” qualifier to modify users quotas as shown in Figure 3.

linux-48l1:/ # edquota -u damian

Figure 3: Edit the user “damian” quota.

Once you issue the command shown in Figure 3 you will be able to set a quota for the user “damian”. Table 1 explains what each column in the “edquota” command does.

Column Description
Filesystem This field specifies the file system which the quota will apply to.
blocks This field is the total number of blocks in kilobytes the user has consumed on that partition.
soft This field allows you to set a soft limit for the user allowing them to create files that exceed the quota but warning them about it.
hard This field allows you to set a hard limit for the user which denies the user from exceeding the quota.
inodes This field is the total number of files the user has on the partition.
soft This field allows you to set a soft limit for the user allowing them to create files that exceed the quota but warning them about it.
hard This field allows you to set a hard limit for the user which denies the user from exceeding the quota.

Table 1: Quota fields explained.Quota fields explained.

Setting Group quotas

Once you have set up a user quota it is the same process for setting up a group quota. The “edquota” command issued with the “-g” qualifier allows you to modify group quotas as shown in Figure 4.

linux-48l1:/ # edquota -g users

Figure 4: Modifying the “users” group quota.

Once you have issued the “edquota” command you will be present with the same options that you were with the user quotas. Table 1 explains what each field is for.

Quota Status

Once you have set a quota you can easily create a mini reports on how much a user has used etc. The command to produce quota reports is “repquota” as shown in Figure 5.

linux-48l1:/ # repquota

Figure 5: Getting a quota report.

Final Thoughts

Once you have setup user a group quotas you can easily manage your storage thus allowing users not to hog all of the disk space, when using disk quotas you make your users more tidy as users and groups of users will not fill their home directories with junk or old documents that are no longer needed.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: , , ,
Categories: Enterprise Linux, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

3 Comments

  1. By:scsmith

    I received this comment in Bugzilla report about this page.

    “This technique is not available if setting up XFS. Please see this
    page to setup disk quotas on XFS.
    http://linux.die.net/man/8/xfs_quota
    You may also search for quotas on XFS…”

    The reporter was anonymous. Hopefully this is helpful…

  2. By:Anonymous

    I’m trying to set a 50GB limit but its not recognising the blocks, I have 58 Gb in my /home, but that does not = 706058 blocks does it ?
    would really appreciate if someone could explain
    Disk quotas for user msmith (uid 1088):
    Filesystem blocks soft hard inodes soft hard
    /dev/sdb1 706058 102400000 153600000 2226 0 0

  3. By:DamianMyerscough

    Sorry for such a late reply. I have just been so busy.

    Blocks. How much hard disk space is currently used, with soft and hard limits listed.
    The values for blocks are given in blocks of 1 KB (independent of the block size for the ext2 file system).

    Inodes. How many files belong to the user on the file system, with soft and hard limits listed.

    I hope this helps anyone in the future.

Comment

RSS