Linux Disk Quota

Source: Internet
Author: User
Transferred from: China IT lab

 

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

 

Limit the maximum disk quota that a group can use (with group restrictions): You can classify users in your system, it's a bit like the current popular membership payment and free-of-charge membership system. The quota of the group you prefer is higher! Haha! Limit _^ limit the maximum disk quota of a user (use user limit): After the group is restricted, you can continue to restrict the disk quota for individual users, 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 "mail host system" for paid and 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 the filesystem above partition, the best support is ext2/ext3, the easiest way to enable filesystem to support quota is to edit/etc/fstab so that the quota disk to be opened can support quota; 2. create a quota record file: As mentioned earlier, the disk limit value record file for the entire quota 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 quota limit value data: Use edquota 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! Example: 1. In the Linux host, disk quotas are mainly applied to quser1 and quser2, 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 will probably not be able to create new files); 4. the gquota group has a 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 should not have our system, so 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 quser22. establish quota support for filesystem: Since quota is more complete, it must be enabled in the ext2/ext3 Linux File System, therefore, we recommend that you write the disk startup parameters for enabling quota to the disk settings for 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 ~] # DfFilesystem 1K-blocks Used Available Use % Mounted on/dev/hda1 5952252 3193292 2451720 57% 28267608 // dev/hdb1 77904 26730604 1% 9492644/disk2/dev/hda5 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/fstabLABEL = // ext3 defaults 1 LABEL =/disk1/disk1 ext3 defaults 1 2 LABEL =/disk2/disk2 ext3 defaults, usrquota, the/disk2 line that we need to set. In the fourth field, usrquota is added. Note that in the "ults, there is no space between usrquota and 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 to restart reboot and remount filesystem! For those who do not like to reboot, you can do this: [root @ linux ~] # Umount/dev/hdb1 [root @ linux ~] # Mount-a [root @ linux ~] # Grep '/disk2'/etc/mtab/dev/hdb1/disk2 ext3 rw, usrquota, and kgquota 0 0 actually, you can also use the mount remount function! [Root @ linux ~] # Mount-o remount/disk2 so that we have successfully added the quota function of filesystem! In addition, here we use the ext3 disk format to test the quota! 3. scans disk user usage and generates important aquota. group and aquota. user: Is there any extra disk space we need to scan? Can we 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-avugquotacheck: Scanning/dev/hdb1 [/disk2] donequotacheck: 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. the user can use quotacheck to output the required data easily! 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 unless your Linux distributions is a relatively old version, this issue will not occur, so you do not have to do this! 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 the appearance of a turned on it! 5. Edit the user's available space: because we have two users to set, set quser1 first, and use edquota: [root @ linux ~] # Edquota-u quser1Disk quotas for user quser1 (uid 502): Filesystem blocks soft hard inodes soft hard/dev/hdb1 0 45000 50000 0 0 0 again, because no data exists in my/disk2, blocks and inodes are both 0 in the above table. If you use/home for quota setting, so blocks/inodes won't be 0, so pay special attention to it here. Okay, the special fonts above are our settings, which are 45000 and 50000 respectively. The unit is KBytes. Converting to MBytes should be divided by 1024. However, just a few simple calculations. don't worry too much! ^_^. Then, copy the quser1 settings to quser2! [Root @ linux ~] # Edquota-p quser1 quser2: Set the grace period or use edquota! [Root @ linux ~] # Edquota-tGrace period before enforcing soft limits for users: Time units may be: days, hours, minutes, or secondsFilesystem Block grace period Inode grace period/dev/hdb1 1 days 7days change the time to 1 day (Originally 7 days to 1 days), okay! Check whether the settings are correct? Use quota-v to query: [root @ linux ~] # Quota-vu quser1 quser2Disk quotas for user quser1 (uid 502 ): filesystem blocks quota limit grace files quota limit grace/dev/hdb1 0 45000 50000 0 0 0 Disk quotas for user quser2 (uid 503 ): filesystem blocks quota limit grace files quota limit grace/dev/hdb1 0 45000 50000 0 0 note that since our users have not exceeded 45 MB, grace (grace time) it won't appear! Is that clear enough ?! 6. Edit the space available for the group: [root @ linux ~] # Edquota-g qgroupDisk quotas for group qgroup (gid 502): Filesystem blocks soft hard inodes soft hard/dev/hdb1 0 80000 90000 0 0 0 0 0 [root @ linux ~] # Quota-vg qgroupDisk quotfor group qgroup (gid 502 ): filesystem blocks quota limit grace files quota limit grace/dev/hdb1 0 80000 90000 0 0 0 0 so that the quota of the group is set! Similarly, because the total usage of the entire group has not reached 80000 KBytes, of course, that grace will not have any information displayed! However, many of my friends have asked a small question: "Why are the values of quser1 and quser2 set to 45/50 MB for soft and hard, but why is your group Total (hard) set to only 90 MB? 』, That is to say, when a user uses 50 MB, then the other user can use up to 40 MB? Why? Well, for a small system, since there are not many users, we can set the quota value for each user. Therefore, of course we can set it for users, you do not need to set the group's quota settings. However, if you think from another perspective, assuming that you are in a company with a large number of staff and a relatively small division of labor, we may not be able to really understand the needs of each user. At this time, setting for each user may be troublesome. On the other hand, we can set quota for each Department (group), because it is easier to directly ask the Department owner about the department requirements, the quota settings of users in this department can certainly be higher, because some users may have unique requirements! Anyway, you only need to comply with the group restrictions. If this department exceeds the limit of the entire group quota, haha! Let them handle it by themselves! ^_^ 7. set quota to start at startup: You don't need to worry about this part because Fedora Core 4 and Red Hat series boot scripts (/etc/rc. d/rc. sysinit) has written quota detection into it. Therefore, under the Preset conditions, quota will be automatically started. However, if you want to manually force quota to start it again at startup, you can use vi to edit/etc/rc. d/rc. local, add a line in it (directly add it to the last line): [root @ linux ~] # Vi/etc/rc. d/rc. local/sbin/quotaon-avug use quotaoff if you want to disable quota! That's right! This completes the quota settings! Easy !! (For SuSE Server 9, you may need to modify the file/etc/init. d/boot. local !) 8. use repquota to display more complete quota results reports: in fact, in addition to the quota limit values used by users and groups, we can also use more detailed quota report commands, this is the repquota command! Its basic usage is as follows: [root @ linux ~] # Repquota-a [-vug] parameter:-a: Go to/etc/mtab to search for the filesystem with the quota flag and report the quota result.-v: output all the quota results, rather than the quota limit of the subscriber.-u: displays the user's quota limit (which is the default value);-g: the quota limit of an individual group is displayed. Example: Example 1: Check the limit status of all filesystems with quota in the system: [root @ linux ~] # Repquota-av *** Report for user quotas on device/dev/hdb1Block grace time: 24:00; Inode grace time: 7 daysBlock limits File limitsUser used soft hard grace Limit root -- 77888 0 0 4 0 0quser1 -- 0 45000 50000 45000 0 0 0quser2 -- 0 50000 0 0 0 Statistics: <= This is the so-called system-related information. Use-v to display Total blocks: 7 Data blocks: 1 Entries: 3 Used average: 3.000000 Example 2: only list the quota Limits of user and group: [root @ linux ~] # Repquota-aug *** Report for user quotas on device/dev/hdb1Block grace time: 24:00; Inode grace time: 7 daysBlock limits File limitsUser used soft hard grace Limit root -- 77888 0 0 4 0 0 *** Report for group quotas on device/dev/hdb1Block grace time: 7 days; Inode grace time: 7 daysBlock limits File limitsGroup used soft hard grace ---------------------------------------------------------------------- root -- 77888 0 0 4 0

 

Based on this information, you can know the current restrictions! Pai_^

 

Complete!

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.