edquota

Used to edit disk quotas for specified users or workgroups

Supplementary instructions

edquota command is used to edit the disk quota of a specified user or workgroup. By default, edquota will use vi to edit the quota settings of a user or group.

grammar

edquota(option)(parameter)

Options

-u: Set the user's quota, which is the default parameter;
-g: Set the quota of the group;
-p <source user name>: Apply the source user's quota settings to other users or groups;
-t: Set grace period.

Parameters

User: Specify the user name or workgroup to edit disk quota limits.

Example

Configure system disk quota support

First of all, disk quotas are regional. We can decide which partitions have disk quotas and which partitions do not use them (naturally, there is no need to configure them). Generally speaking, as a web virtual host server, /home and /www (or similar) are partitions for users to store resources, so disk quotas can be applied to these two partitions. Suppose we need to implement user-level restrictions on the /home partition, and implement per-group user quotas on /www.

first step:

vi /etc/fstab

Find the lines corresponding to /home and /www, for example:

/dev/sda5 /home ext2 defaults 1 2
/dev/sda7 /www ext2 defaults 1 2

To implement user-level disk quotas in /home, make the following modifications to the mount option field of the sda5 line:

/dev/sda5 /home ext2 defaults, usrquota 1 2

Note, it is usrquota. Similarly, we can modify the /www line as follows:

/dev/sda7 /www ext2 defaults, grpquota 1 2

To edit the root user

Change the /etc/fstab file

LABEL=/ / ext2 defaults,usrquota,grpquota 1 1

Note: Each line of the /etc/fstab file consists of six fields:

Note: Please pay special attention to the spelling here, it is usrquota and grpquota, do not write userquota and groupquota.

Enter single-user mode and use quotacheck to generate .user or .group files

quotacheck your directory

example:quotacheck / ; quotacheck /home

If an error is reported in single-user mode, umount your device /dev/hda*

If you execute it again, it will be ok. Restart the system. If everything is normal, quota will start to work normally.

Set allocation amounts for user and group quotas

Disk quota restrictions are generally based on two aspects: the disk size occupied by a user and the number of all files. Before the specific operation, we first understand the two basic concepts of disk quotas: soft limits and hard limits.

Use the edit quota command edquota to configure quotas for users. After restarting the system, we assume that lanf is the system account that requires quotas. You can use the following command to allocate disk quotas to users:

edquota -u lanf

This command will start the default text editor (such as vi or other editor specified by the $EDITOR environment variable) with the following content:

Quotas for user lanf:
/dev/sda5:blocks in use:0,limits(soft = 0,hard = 0)
inodes in use:0,limits(soft = 0,hard = 0)

This means that the lanf user has so far used 0 data blocks (in K) in the /dev/sda5 partition (which is already under the control of usrquota) and has no limits (including soft and hard limits) hard), similarly, lanf does not have any files or directories in this partition, and there are no soft or hard restrictions. If we want to limit the disk capacity for users, we only need to modify the limits part of the blocks line. Note that the unit is K. For example, to allocate a soft limit of 100M disk and a hard limit of 400M to lanf, you can use the following settings:

Quotas for user lanf:
/dev/sda5:blocks in use:0,limits(soft = 102400,hard = 409800)
inodes in use:0,limits(soft = 0,hard = 0)

Similarly, if you want to limit the number of file directories, you can modify the inodes line accordingly. We can also limit both at the same time. Just modify Quotas for user lanf as follows:

/dev/sda5:blocks in use:0,limits(soft = 102400,hard = 409800)
inodes in use:0,limits(soft = 12800,hard = 51200)

This means that in addition to the corresponding capacity limit, there is also a soft limit of 12,800 and a hard limit of 51,200 on the number of files/directories. After saving the new configuration, the user's disk usage cannot exceed the hard limit. If the user attempts to exceed this limit, the operation will be canceled and an error message will be obtained. However, if every user has to go through such troublesome settings, then this kind of repetitive manual labor is really a bit chilling and a waste of time. Fortunately, edquota also has a -p parameter (prototype) that can copy existing user settings. For example, if we want to use the same quota configuration as lanf for the three users Jack, Tom, and Chen, we can use the following command:

edquota -p lanf -u Jack Tom Chen

In this way, these three users are given the same disk quota as lanf.

For group quotas, except for the -u option in the edquota command, it is changed to the -g option. For example, the following operation for the webterm1 group:

edquota -g webterm1

In fact, the above restrictions are just hard limits set by the user. If you need to make the soft limit also take effect, you also need to set a grace period for the user's soft limit. The default soft limit grace period is infinite. This can be achieved using the -t option of the edquota command. Run the following command:

edquota-t

edquota will open the default editor and display the following content:

time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/sda5:block grace period:0 days,file grace period:0 days

The grace period can be set in days, hours, minutes, and seconds. For example, in the following example, the disk space limit has a grace period of two days, while the file limit has a grace period of only 6 hours.

Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/sda5:block grace period:2 days,file grace period:6 hours

Join via setquota tool:

For example, to add the disk quota of user bye2000, execute the following command:

setquota –u / 2000 2500 100 110 bye2000

The following is a brief description of the usage of the setquota command:

setquota [-u|-g] Mount point Number of soft blocks Number of hard blocks Number of soft files Number of hard files User name/group name

View user disk usage

To find out how much disk space is used by a certain user, such as lanf, you can use the following command:

quota-ulanf

show:

Disk quotas for user lanf(uid 503):
Filesystem blocks quota limit grace file quota limit grace
/dev/sda5 3 102400 409800 1 12800 51200

Similarly, you can use the quota -g groupname command to view the disk usage of a certain group.

Notice: