Set disk quota in Linux system

xiaoxiao2021-03-06  19

Set disk quota in Linux system

Overview

The disk quota is a tool for system administrators to monitor and restrict users or groups of disks. Quota can limit: one, limit the number of inode (file number) that can be owned by the user or group; it limits the number of disk blocks assigned to the user or group (in kilobytes). By using Quota, the system administrator can limit the user's freely using disk space. The quota program is for each user and each file system, so each file system is set separately.

Compile the QUOTA kernel

First, make sure your Linux kernel is support quota. In the 2.2.14 version of the core, you must answer the following problem "Y" when compiling.

FileSystemsquota Support (config_quota) [N / Y /?] Y

Modify "/ etc / fstab" file

The "/ etc / fstab" file contains information about a wide variety of file systems installed in the Linux system. Before using quota, you must now set it into force. Because QUOTA is set separately for each file system, and in the "fstab" file, each file system is represented separately, so in order to support the Quota must be set separately in each line of "FSTAB". Depending on your needs, you can set quota separately for users, groups, or groups and users. In the following example, we assume that "/ home" directory is in "/ dev / sda6" device, there are three possible situations.

The first possible situation:

Set user quota on a specific file system, editing your "fstab" file (VI / etc / fstab), add "USRQUOTA" after "default" or other settings made for the file system.

E.g:

/ dev / sda6 / home ext2 defaults 1 2 (AS An Example: The Word "Defaults") / DEV / SDA6 / HOME EXT2 NOSUID, NODEV 1 2 (AS An Example: Any Other Options you have set)

Change to:

/ dev / sda6 / home ext2 defaults, usrquota 1 2 / dev / sda6 / home ext2 Nosuid, Nodev, USRQUOTA 1 2

The second possible situation:

Set the group quota on the file system, edit your "fstab" file (vi / etc / fstab), add "GRPQUOTA" after "defaults" or other settings made for the file system

E.g:

/ dev / sda6 / home ext2 defaults 1 2 (AS An Example: The Word "Defaults") / DEV / SDA6 / HOME EXT2 NOSUID, NODEV 1 2 (AS An Example: Any Other Options you have set)

Change to:

/ dev / sda6 / home ext2 defaults, Grpquota 1 2 / dev / sda6 / home ext2 Nosuid, Nodev, Grpquota 1 2

The third possible situation:

In the file system, you can also set the user and group quota, edit the "FSTAB" file (Vi / etc / fstab), add "USRQUOTA, GRPQUOTA" after "defaults" or other settings made for the file system.

E.g:

/ DEV / SDA6 / Home Ext2 Defaults 1 2 (AS An Example: The Word "Defaults") / DEV / SDA6 / HOME EXT2 NOSUID, NODEV 1 2 (AS An Example: Any Other Options You Have Set) Change to:

/ DEV / SDA6 / Home Ext2 Defaults, USRQUOTA, GRPQUOTA 1 2 / DEV / SDA6 / HOME Ext2 Nosuid, Nodev, USRQUOTA, GRPQUOTA 1 2

Create "quota.user" and "quota.group" files

After modifying the "/ etc / fstab" file, in order to establish Quota on the file system, there must be a "root" file with "root" in the root of the file system ("/ home"): If Set User Quota, you must create "quota.user"; if you set the group quota, you must create "quota.group"; if you want to set the user and group quota, these two files are created.

first step

Create "quota.usr" or "quota.group" file as "root" as you want to set the quota's partition.

[root @ weep /] # Touch /Home/quota.user[Root@deep /] # Touch /Home/quota.group[Root@deep /] # chmod 600 /Home/quota.user[Root@deep /] # CHMOD 600 /HOME/quota.group

"Touch" command creates an empty file in the "/ home" directory. . The "chmod" command sets only the "root" user readable write to these files.

Note: These two quota files, "quota.user" and "quota.group", must be "root", "root" users have read and write permissions, others do not have this permission.

Second step

Download We initialize the "Quota.user" and "Quota.Group" files under the root of the file system.

Initialize "Quota.user" and "Quota.Group" file with the following command:

[root @ deep /] # edquota -u wahib [root @ deep /] # Edquota -g wahib

The "quota.user" and "quota.group" file are initialized above. The "edquota" command "-u" parameter is the user "WaHib" set the quota, "- g" parameters set the quota "WAHIB". Please note that these two files will be edited later and set the specific quota.

third step

In the "/ etc / fstab" file, you set a right option for the Quota program, and create and initialize the "Quota.users" and "Quota.group" files, you need to restart the system to make changes to the change.

Restart the system with the following command:

[root @ deep /] # reboot

Assign Quota for users or groups

After restarting the system, you can assign disk quotas for users or groups. You can view the Man Help Edquota (8) with "edquota".

Edquota program

The Edquota program is used to set the quota editor, you can create a temporary issue, then Root users use this file to set the quota of the user or group. Here is an example of assigning quota for users and groups.

Assign users in Quota

For example, to assign quota to users who have logged into the name "WaHib". The following command allows you to enter the VI editor, set the disk quota on the partition that has entered into effect on each quota setting for the "Wahib" user. first step

Use the following command to edit or modify Quota: Wahota:

[root @ deep /] # edquota -u wahib

Quotas for User Wahib: / DEV / SDA6: Blocks in Use: 6, Limits (Soft = 0, HARD = 0) Inodes in Use: 5, Limits (Soft = 0, HARD = 0)

After the above command is executed, you can see some information about the "WAHIB" user is displayed on the screen. "Blocks in use:" indicates the total number of disk blocks that the user is using in this partition. "Inodes in Use:" indicates all the files in this partition.

Second step

Assign 5MB of Quota for users "Wahib", set some of the following parameters in the VI compiler:

Quotas for User Wahib: / DEV / SDA6: Blocks in Use: 6, Limits (Soft = 0, HARD = 0) Inodes in Use: 5, Limits (Soft = 0, HARD = 0)

Change to:

Quotas for User Wahib: / DEV / SDA6: Blocks in Use: 6, Limits (Soft = 5000, Hard = 0) Inodes in Use: 5, Limits (Soft = 0, HARD = 0)

"SOFT =" settings users can use up to how large disk space.

"HARD =" setting how much disk space for enforcing users. Note that only the value of "HARD =" setting after setting the "GRACE PERIOD" parameter is valid.

"Grace period" parameters

"GRACE PERIOD" parameter allows you to set up time intervals that users do not exceed disk quota. For example: This parameter can be used to warn a user's home directory for every seven days of a 5MB disk quota. As long as you think is reasonable, you can set any value greater than or equal to 0. Setting this parameter requires the following two steps (assuming time intervals 7 days).

first step

Edit the "GRACE PERIOD" parameter with the following command.

[root @ deep /] # edquota -t

Time Units May BE: Days, Hours, Minutes, or Secondsgrace Period Before Enforcing Soft Limits for Users: / dev / sda6: Block Grace Period: 0 Days, File Grace Period: 0 days

Second step

Change "GRACE PERIOD" to 7 days. Modify and set the following parameters with the VI editor:

Time Units May BE: Days, Hours, Minutes, or Secondsgrace Period Before Enforcing Soft Limits for Users: / dev / sda6: Block Grace Period: 0 Days, File Grace Period: 0 days

Change to:

Time Units May Be: Days, Hours, Minutes, or Secondsgrace Period Before Enforcing Soft Limits for users: / dev / sda6: Block Grace Period: 7 Days, File Grace Period: 7 Days

Assign quota for groups

Assume that there is a group in the system that group ID is "Webusers". The following command allows you to enter the VI editor, set the disk quota on the partition that has taken effect on each quota setting for the "Webusers" group. Use the following command to edit and modify quota:

[root @ deep /] # Edquota -g Webusers

Quotas for Group WebUsers: / dev / sda6: Blocks in Use: 6, Limits (Soft = 0, HARD = 0)

This process is the same as the process of assigning disk quotas for users, you must modify the "Soft =" parameter and save the modifications made.

Assign the same quota for group users

The Edquota program has a special parameter (-P) to assign the same quota based on a user who has already set the Quota user. Assume that you want to set the same quota as the "Wahib" user starting from 500, you can set the "wab" user's quota, and then run the following command.

Use the following command to set the same quota as "Wahib" users:

[root @ weep /] # Edquota -p wahib `awk -f: '$ 3> 499 {Print $ 1}' / etc / passwd`

The EDQUOTA program sets the same quota with the "Wahib" user in the "/ etc / passwd" file.

More information

$ man Edquota (8) - Edit User Quotas $ Man Quota (1) - Display Disk Usage and Limits $ Man Quotacheck (8) - Scan A File System for Disk Usages $ Man Quotactl (2) - Manipulate Disk Quotas $ Man Quotaon, Quotaoff (8) - Turn File System Quotas On and Off $ Man Repquota (8) - Summarize Quotas for a File System $ Man Rquota (3) - Implement Quotas On Remote Machines

command

The commands listed in the following are often used. You can refer to the Man Help page to get more information.

Quota

The "quota" command displays the usage of the user's disk space and its disk quota.

Use the following command to display the usage of the user's disk space and its disk quota:

[root @ deep /] # Quota -u wahibdisk Quotas for User Wahib (Uid 501): FileSystem Blocks Quota Limit GRACE FILES Quota Limit GRACE / DEV / SDA6 6001 * 6000 0 None 7 0 0

Use the following command to display the quota of the group where the user is located:

[root @ deep /] # Quota -g WahibDisk Quotas for Group Wahib (GID 501): Filesystem Blocks Quota Limit GRACE FILES Quota Limit GRACE / DEV / SDA6 5995 * 5000 0 None 1 0 0

Note: If there is no set group quota, there will be the following prompt information:

Disk Quotas for Group Wahib (GID 501): NONE

Repquota

Repquota generates a disk usage and the specified file system's quota information. Moreover, it displays the number of files used in each user and disk space.

Here is an example of "repquota" output:

[Root @ deep /] # repquota -aBlock limits File limitsUser used soft hard grace used soft hard graceRoo - 21 0 0 4 0 0Named - 6 0 0 5 0 0Admin - 388657 0 0 21 21 0 0Wahib - 6001 0 0 7 0 0

Block limits File limitsUser used soft hard grace used soft hard graceroot - 21 0 0 4 0 0named - 6 0 0 5 0 0admin - 388657 0 0 2121 0 0wahib - 6001 6000 0 none 7 0 0

Copyright statement

This article translated and adapted from Gerhard Mourani's "Securing and Optimizing Linux: Redhat Edition", the original text and its copyright agreement, please refer to: www.openna.com.

The copyright of the Chinese version belongs to the author brimmer and www.linuxaid.com.cn.

转载请注明原文地址:https://www.9cbs.com/read-43697.html

New Post(0)