Linux Disk Quota configuration (2)

Source: Internet
Author: User
Article Title: Linux Disk Quota configuration details (2 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Practice quota

Quota is widely used. However, it is generally used for the following purposes:

Limit the maximum disk quota that a group can use (use group restrictions ):

You can classify users in your system into different categories, which is a bit like the current popular membership system for payment and free payment, the quota of the group you prefer is higher! Haha! Pai_^

Limit the maximum disk quota of a user (User restrictions ):

After a group is restricted, You can further restrict the individual so that the same group can be allocated more fairly!

Link-based mail can be used as the limit (change the path of/var/spool/mail ):

If it is a "email host system" for paying and paying-free members, do you need to re-plan a hard disk? No! Direct Link to/home (or other completed quota disks! This is usually used when the original planning is not good, but you do not want to change the original host architecture!

The main steps from preparing filesystem support for quota to completing the configuration are as follows:

1. Set the filesystem of partition to support the quota parameter:

Since quota must be supported by filesystem on partition, in general, the best support is ext2/ext3. The easiest way to start filesystem to support quota is to edit/etc/fstab, this allows the quota disk to be opened to support quota;

2. Create a quota record file:

As mentioned earlier, the archive of the limit value record for the entire quota disk is aquota. user/aquota. group. To create these two files, you must first use quotacheck to scan them! Therefore, the next step is to use quotacheck to scan the disk we want to use;

3. Edit the limit value data of quota:

Then, edquota is used to edit the available space of each user or group;

4. rescan and start quota:

After setting quota, we recommend that you perform quotacheck again and start it with quotaon!

The procedure for setting the entire quota is just like this. It's easy! Next we will introduce the entire process with an example, so that you can better understand the entire process! The example is as follows:

1. In the Linux host, quser1 and quser2 are used for disk quotas, and both users are attached to the qgroup group.

2. Each user has a total disk space of 50 MB (excluding inode! And soft limit is 45 MB;

3. the grace period is set to one day. That is to say, the two can exceed the limit of 45 MB, but the extra files must be deleted within one day. Otherwise, the remaining space cannot be used (that is, this account probably cannot create files );

4. The Group gquota considers the maximum quota, so it is set to 90 MB!

It is useless to say more, so we will actually proceed!

1. Prepare the test environment and establish the user and group:

These two accounts do not exist in our system, so please set them up!

[Root @ linux ~] # Groupadd qgroup

[Root @ linux ~] # Useradd-m-g qgroup quser1

[Root @ linux ~] # Useradd-m-g qgroup quser2

[Root @ linux ~] # Passwd quser1

[Root @ linux ~] # Passwd quser2

2. Set up quota support for filesystem:

Quota is fully supported and can be started only in the ext2/ext3 Linux file system. Therefore, we recommend that you set the disk startup parameters for enabling quota, write the disk settings of quota (/etc/fstab )! For example, you want to limit the quser1 and quser2 users in/disk2! This is because/disk2 is an independent sector, which can be queried using df. In addition, it is recommended that you do not use the root directory as the/for quota! Otherwise, some problems may occur! In addition, do not perform quota for root! It's useless to do it anyway!

[Root @ linux ~] # Df

Filesystem 1K-blocks Used Available Use % Mounted on

/Dev/hda1 5952252 3193292 2451720 57%/

/Dev/hdb1 28267608 77904 26730604 1%/disk2

/Dev/hda5 9492644 227252 8775412 3%/disk1

Well! /Disk2 is an independent partition, and its device name is/dev/hdb1. All right! Then I have to start the/disk2 quota file format of/dev/hdb1! So because the file format is set in/etc/fstab, let's edit it with vi! You only need to add usrquota and kgquota to/etc/fstab! (Note: Please note that these two projects must be written incorrectly! Please check again before writing/etc/fstab. This is because the system may fail to start up after an error is written. Although the probability of wrong writing is not high, it is very likely !)

[Root @ linux ~] # Vi/etc/fstab

LABEL = // ext3 defaults 1 1

LABEL =/disk1/disk1 ext3 defaults 1 2

LABEL =/disk2/disk2 ext3 defaults, usrquota, MAID 1 2

/Dev/hda3 swap defaults 0 0

Note that we need to set the/disk2 line. usrquota is added to the fourth field, and there is no space between "defaults, usrquota, or" kgquota!

In this case, the quota disk format is added! However, since the real quota reads the/etc/mtab file, however, this file must be restarted before it can be rewritten with new/etc/fstab data! Therefore, you can choose:

Restart (reboot );

Restart remount filesystem to Start Settings!

You can do this for people who do not like restarting the instance:

[Root @ linux ~] # Umount/dev/hdb1

[Root @ linux ~] # Mount-

[Root @ linux ~] # Grep '/disk2'/etc/mtab

/Dev/hdb1/disk2 ext3 rw, usrquota, kgquota 0 0

In fact, you can also use the mount remount function!

[Root @ linux ~] # Mount-o remount/disk2

In this way, we have successfully added the quota function of filesystem! In addition, here we use the ext3 disk format to test the quota!

3. Scan disk user usage and generate important aquota. group and aquota. user:

The next step is to scan the disk we need. Is there any extra space for us to set the quota? And output the scan results to the top layer of the disk (that is, under/disk2). This requires the help of the quotacheck command! With quotacheck, you can easily output the required data! The aquota. group and aquota. user Files are generated under/disk2!

[Root @ linux ~] # Quotacheck-avug

Quotacheck: Scanning/dev/hdb1 [/disk2] done

Quotacheck: Checked 3 directories and 4 files

[Root @ linux ~] # Ll/disk2

-Rw ------- 1 root 6144 Sep 6 11: 44 aquota. group

-Rw ------- 1 root 6144 Sep 6 11: 44 aquota. user

With quotacheck, you can easily output the required data to him! However, in some Linux versions. user (group) to start quota. This may be because of the relationship between the old version of quota, so another link file is created to fool quota:

[Root @ linux ~] # Cd/disk2

[Root @ linux ~] # Ln-s aquota. user quota. user

[Root @ linux ~] # Ln-s aquota. group quota. group

This problem does not occur unless your Linux distributions version is older. Therefore, you do not have to perform this operation!

4. quota for starting quota:

Start quota again! The startup method is also very simple! Just use quotaon-av:

[Root @ linux ~] # Quotaon-avug

/Dev/hdb1 [/disk2]: group quotas turned on

/Dev/hdb1 [/disk2]: user quotas turned on

Note: It is successful to see a turned on it!

5. Edit the user's available space:

Since we have two users to set up, set quser1 first, and use edquota:

[Root @ linux ~] # Edquota-u quser1

Disk quotas for user quser1 (uid 502 ):

Filesystem blocks soft hard inodes soft hard

/Dev/hdb1 0 45000 50000 0 0 0

[1] [2] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.