Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux edquota command

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use the Linux edquota command". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the Linux edquota command.

Edquota is used to edit disk quotas for specified users or workgroups

Syntax edquota (options) (parameters) option-u: set the user's quota, which is the default parameter;-g: set the quota;-p of the group: apply the source user's quota settings to other users or groups;-t: set the grace period. Parameter user: specify the user name or workgroup to edit the disk quota limit.

Disk quota support for instance configuration system

First of all, disk quotas are regional, and we can decide which partition is used for disk quota and which partition is not used (naturally, there is no need to configure it). In general, as a web virtual host server, / home and / www (or similar) are partitions for users to hold resources, so disk quotas can be applied to these two partitions. Suppose we need to impose user-level restrictions on the / home partition and / www on a per-group user quota.

Step one:

Vi / etc/fstab finds the lines corresponding to / home and / www, for example:

/ dev/sda5 / home ext2 defaults 12 / dev/sda7 / www ext2 defaults 12 implements user-level disk quotas in / home, so the mount option field of the sda5 line is modified as follows:

/ dev/sda5 / home ext2 defaults,usrquota 12 Note, it's usrquota. Similarly, we can modify the / www line as follows:

/ dev/sda7 / www ext2 defaults,grpquota 1 2 if editing the root user

Change to / etc/fstab file

LABEL=/ / ext2 defaults,usrquota,grpquota 1 1 description: each line of the / etc/fstab file consists of six fields:

First field: comments for the file system (partition) (similar to volume label)

Second field: the mount point of the file system

Third field: file system type (disk quotas can only be implemented on ext2 file systems)

The fourth field: Mount the file system is the option used, if you only want to achieve user-based disk quotas, add the usrquota keyword, only want to achieve group-based disk quotas, add the grpqouta keyword, if you need both, write all, separated by commas.

The fifth field: indicates whether the file system (partition) is read-only, 0 means read-only, and 1 indicates read-write.

The sixth field: indicates the order of checks when the system starts to execute fsck.

Note: please pay special attention to the spelling here, which is usrquota and grpquota, not userquota and groupquota.

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

Quotacheck your catalog

Example:quotacheck /; quotacheck / home umount your device / dev/hda* if an error is reported in single user mode

Ok will be executed again, restart the system, and if everything is all right, quota will start to work properly.

Set the allocation of user and group quotas

Disk quotas are generally limited in terms of the size of the disk occupied by a user and the number of files. Before we do this, let's take a look at the two basic concepts of disk quotas: soft limits and hard limits.

Soft limit: the maximum disk space and the maximum number of files that a user can have on the file system, which can be temporarily exceeded within a grace period.

Hard limit: the absolute amount of disk space or files a user can have is never allowed to exceed this limit.

Edit the data file directly through edquota:

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

The command edquota-u lanf launches a default text editor, such as vi or other editor specified by the $EDITOR environment variable, with the following contents:

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 lanf users have so far used 0 blocks (in K units) in the / dev/sda5 partition (which is already under the control of usrquota), and there are no restrictions (including soft limit soft and hard limit hard). Similarly, lanf does not have any files and directories in this partition And there are no soft and hard restrictions. If we want to limit the disk capacity of the user, we only need to modify the limits part of the blocks line, noting that the unit uses K. For example, to assign 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 = 0hard = 0) similarly, to limit the number of file directories, you can modify the inodes line accordingly. We can also impose restrictions on both at the same time. You only need to modify the 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 12800 files / directories and a hard limit of 51200. After the new configuration is saved, the user's disk usage cannot exceed the hard limit. If the user attempts to exceed this limit, the operation will be cancelled and an error message will be given. However, if every user has to set up so troublesome, then this repetitive manual work is a bit chilling, and it is a waste of time. Fortunately, edquota also has a-p parameter (prototype) to copy existing user settings. For example, if we want to use the same quota configuration as lanf for Jack, Tom, and Chen, we can use the following command:

Edquota-p lanf-u Jack Tom Chen so that these three users are given the same disk quota as lanf.

For the quota of the group, except that the corresponding-u option in the edquota command is changed to the-g option, for example, the following operation on the webterm1 group:

Edquota-g webterm1 in fact, the above restrictions only work on the hard limits set by the user. If you need to make the soft limit work, you also need to set a grace period for the user's soft limit, which is infinite by default, which can be done using the-t option of the edquota command. Run the following command:

Edquota-tedquota opens the default editor and displays the following:

Time units may be:days,hours,minutes,or secondsGrace period before enforcing soft limits for users:/dev/sda5:block grace period:0 days,file grace period:0 days can set grace periods in days, hours, minutes, and seconds. For example, in the following example, the grace period for disk space limits is two days, while the grace period for file count limits is only six hours.

Time units may be:days,hours,minutes,or secondsGrace period before enforcing soft limits for users:/dev/sda5:block grace period:2 days,file grace period:6 hours joins through the setquota tool:

For example, to join 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 soft block number hard file number hard file number user name / group name view user disk usage

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

Quota-u lanf shows:

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 see the disk usage of a group.

Note:

If the user does not configure a disk quota, the output shows Disk quotas for user hujm (uid 503): none

If you run quota without any parameters, you are looking at your own quota usage.

Thank you for your reading, the above is the content of "how to use the Linux edquota command", after the study of this article, I believe you have a deeper understanding of how to use the Linux edquota command, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report