Linux Disk Quota Management

Source: Internet
Author: User
Article Title: linux Disk Quota Management. 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.

1. confirm that the quota package is installed.

[Root @ stu5 lv1] # rpm-qa | grep quota

2. Modify/etc/fstab to activate the quota option for the selected file system.

Use the vi editor as the root user to add the usrquota and (or) kgquota options to the file system that requires the quota:

:

LABEL = // ext3 defaults 1 1

LABEL =/boot ext3 defaults 1 2

LABEL =/home ext3 defaults, usrquota 1 2

None/dev/shm tmpfs defaults 0 0

/Dev/hda2 swap defaults 0 0

In the preceding example, the/home file system enables the user quota.

3. Remount the File System

After the userquota and kgquota options are added, Remount the file system with each corresponding fstab entry modified. If a file system is not used by any process, use the umount command followed by the mount command to re-mount the file system. If a file system is in use, the easiest way to re-mount the file system is to reboot the system or run the following command:

[Root @ stu5 lv1] # mount-o remount/home/

4. Scan the corresponding file system and use the quotacheck command to generate the basic quota file.

Run the quotacheck command to check the quota-enabled file system and create a table for each file system. This table is used to update the disk usage file of the operating system. In addition, the disk quota file of the file system is also updated. To create a quota file (aquota. user and aquota. group) on the file system, use the-c option of the quotacheck command. For example, if the/home partition is enabled for both the user and group quota, create these files in the/home directory:

Quotacheck-cmug/home

-C option specifies that the quota file should be created for each file system with the quota enabled. The-u option specifies to check the user quota, and the-g option specifies the inspection group quota.

If the-u or-g option is specified, only the user quota file is created. If only the-g option is specified, only the group quota file is created.

5. Use the edquota command to allocate disk quotas.

To configure a quota for a user, run the following command at the shell prompt as the root user:

Edquota-u username

Perform this step for each user who wants to implement the quota. For example, if the quota is enabled for/home partition (/dev/hda3) in/etc/fstab and the edquota testuser command is executed, the System Default Editor

In Disk quotas for user user1 (uid 501 ):

Filesystem blocks soft hard inodes soft hard

/Dev/sda5 0 0 0 0 0 0

/

~

There are seven topics in the file:

Filesystem => File System for quota control.

Blocks => Number of blocks in use (unit: 1 KB)

Soft => "soft" limit on the number of blocks used

Hard => "hard" limit on the number of blocks used

Inode => Number of inode in use

Soft => "soft" Restrictions on inode usage

Hard => hard "limit on inode usage

Edquota? T

Similar to the edquota command, this command also opens the current file system quota in the Text Editor:

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/hdb1 10 days 10 days

The other two operations can be used.

The preceding settings can also be set using the setquota command:

Setquota-u someone 0 0 3 5/dev/loop0

Setquota-t 864000 864000/dev/loop0

Ps. 864000 is the number of seconds for 10 days. One hour = 3600 seconds, and one day = 86400 seconds

After the disk quota is completed, you must use the quotaon-av command to enable quota management.

Quotacheck-mug/home

Manage disk quotas

If quotas are implemented, they need to be maintained-the main maintenance mode is observation. Check whether the quota is exceeded and ensure that the quota is correct. Of course, if users repeatedly exceed their quota or continuously reach their soft limits, the system administrator can make several decisions based on the impact of user types and disk space on their work. The administrator can help users search for disk space usage or increase user quotas as needed.

1. Report Disk Quota

Run the repquota tool to create a disk usage report. For example, the repquota/home command generates the following output:

[Root @ stu5 lv1] # repquota/home/

* ** Report for user quotas on device/dev/sda5

Block grace time: 7 days; Inode grace time: 7 days

Block limits File limits

User used soft hard grace

----------------------------------------------------------------------

Root -- 35836 0 0 4 0 0

Stu5 -- 96 0 0 12 0 0

User1 -- 48 64 128 12 0 0

User2 -- 48 0 0 12 0 0

User3 -- 48 0 0 12 0 0

To view the disk usage of all file systems with quotas enabled, run the following command:

Repquota-

Although this report looks very simple, I still need to explain some points. Displayed after each user-a quick way to determine whether the user has exceeded the block limit or the node limit. If any soft limit is exceeded, the corresponding-row is replaced by-. The first-indicates the block limit, and the second indicates the internal node limit. The grace column is usually blank. If a soft limit is exceeded, this column will contain the remaining time in the transition period. If the transition period has exceeded, none is displayed.

2. Enable and disable disk quotas

You do not have to set the quota to 0 to disable them. To disable user and group quotas, run the following command:

Quotaoff-vaug

If the-u or-g option is not specified, only the user quota is disabled. If only the-g option is specified, only the group quota is disabled.

To re-enable the quota, use the quotaon command with the same options.

For example, to enable user and group quotas for all file systems:

Quotaon-vaug

To enable the quota for a specified file system (such as/home:

Quotaon-vug/home

If the-u or-g option is not specified, only the user quota is enabled. If only the-g option is specified, only the group quota is enabled.

3. assign a quota for the group

The quota can also be allocated by group. For example, to set a group quota for a devel group, run the following command (This group must exist before setting the group quota ):

Edquota-g devel

The preceding command displays the existing group quota in the Text Editor:

Disk quotas for group devel (gid 505 ):

Filesystem blocks soft hard inodes soft hard

/Dev/hda3 440400 0 0 37418 0 0

Modify the limit, save the file, and configure the quota.

To check whether the group quota is set, run the following command:

Quota-g devel

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.