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 give disk quota in linux

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly shows you "how to give disk quota in linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to give disk quota in linux".

Several situations where disk quotas (quota) are more commonly used are:

* for WWW server, for example, the capacity limit of each person's web space

* for mail server, for example, email space restrictions per person

* for file server: the maximum network hard disk space available to everyone (more common in the teaching environment)

The above is designed for network services. If it is for the settings above on the host of the linux system, it is used for the following purposes:

* limit the maximum disk quota of a user group. You can set ordinary user group and VIP user group, which is similar to the membership system. The corresponding disk space for VIP users is larger. Ordinary users want to become VIP. Hey, pay a membership fee.

* limit the disk quota of a user, and continue to set each user of the user group after the restriction, so that there can be a fairer distribution under the user group.

* use Link to make mail available as a limited quota (change the path / var/spool/mail)

The specification setting options for Quota =

* limit the number or capacity of files (inode or block). It is common to set block

* soft/hard,hard > soft. If you exceed soft, you will be warned that the disk is full after logging in to the system within grace time (grace time).

* the grace time grace time for countdown. If it is not lower than soft after this time, the disk usage is locked directly, and the hard is reduced to the soft value.

It's better to sit up than to walk. Let's design a practical example of quota:

* the accounts of the five people are user1,user2,user3,user4,user5, the passwords are all 123456, the initial user group is quotagroup, and the attributes of other accounts are default.

* disk capacity limit of account: all five users can obtain the disk usage (hard) of 300MB, and there is no limit on the number of files. In addition, warning is given whenever the capacity exceeds the 250MB (soft)

* user group limit: since there may be other users in my system, I only admit that the group quotagroup uses the maximum capacity of 1GB. That is, if user1,user2,user3 uses 280MB space, then user4,user5 can only use 1000MB-280MB*3 = 160MB space.

* grace date: 14 days. After reaching the 250MB 250MB value, you will be warned within 14 days. If the disk capacity is not lower than that of Microsoft within 14 days, lock the user directly. He told you to put the movie on the hard drive without deleting it.

Create shell scripts for 5 accounts:

The code is as follows:

#! / bin/bash

# use script to create a new environment for experimental quota

Groupadd quotagroup

For username in user1 user2 user3 user4 user5

Do

Useradd-g quotagroup $username

Echo "123456" | passwd-- stdin $username

Done

Let's practice the quota process:

# df-h / home

File system capacity used available used% mount point

/ dev/sda3 69G 4.4G 62G 7% /

Because the virtual machine I use is automatically partitioned, there is only one root partition / mount sda3 file system, so I will do it for /, but generally speaking, it is not recommended to set quota directly under /.

# mount | grep'\ s /\ s'

/ dev/sda3 on / type ext4 (rw,relatime,seclabel,user_xattr,barrier=1,data=ordered)

By looking at the data of / dev/sda3, we know that it is the ext4 file system, then quota is definitely supported.

Modify the configuration file / etc/fstab to make / support quota:

UUID=2f08675e-289a-404a-a13e-4802dec910e9 / ext4 defaults,usrquota,grpquota 1 1

Focus on the usrquota,grpquota shown in bold above

# umount / (damn it, how do you umount the root directory? restart it)

# mount-a

# mount | grep "\ s /\ s"

/ dev/sda3 on / type ext4 (rw,relatime,seclabel,user_xattr,barrier=1,data=ordered,usrquota,grpquota)

As you can see, disk quotas are available for user groups and users.

= New quota profile =

# quotacheck [- avugfM] [/ mount_point]

-a: scan all file systems supported by quota in / etc/mtab. After adding this parameter, the following / mount_point does not need to be written.

-u: create a new aquota.user for the usage of files and directories scanned by the user

-g: scan the usage of files and directories for user groups, and create a new aquota.group

-v: displays scanning process information

-f: force to scan the file system and write to the quota configuration file (dangerous, use with caution)

-M: forces the file system to be scanned read-write, and is used only in special cases.

In fact, you only need to remember the first four parameters-augv.

# ll-d / a *

-rw---. 1 root root 8192 October 27 02:06 / aquota.group

-rw---. 1 root root 7168 October 27 02:06 / aquota.user

Do not manually modify these two quota configuration files, this is updated by quota itself.

Setting of quota startup, shutdown and limit values

# quotaon [- avug]

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

Servers

Wechat

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

12
Report