TrumanWong

quota

Display disk used space and limits

Supplementary instructions

quota command is used to display disk quota information for a user or workgroup. Output information includes disk usage and quota limits.

grammar

quota(option)(parameter)

Options

-g: List the disk space limit of the group;
-q: Concise list, only the parts that exceed the limit are listed;
-u: List the user’s disk space limits;
-v: Display the space limit of this user or group on all storage devices attached to the system;
-V: Display version information.

Parameters

User or workgroup: Specify the user or workgroup to be displayed.

Example

We can limit the maximum disk quota that a certain group can use, and we can also limit the maximum disk quota of a certain user. For example, if you make a paid application, VIPs can get more space. In addition, using Link method to allow mail to be used as a restricted quota (change the path /var/spool/mail), no, you need to plan a new hard disk! Just use Link directly to point to /home (or other quota disks that have been prepared)! This is usually used when the original planning is not good, but you don’t want to change the original host architecture!

Requirements: The Linux host mainly implements disk quotas for two users, quser1 and quser2, and these two users are hung in the qgroup group. Each user has a total of 50MB of disk space (not counting inode) limits! And the soft limit is 45 MB; the grace time is set to 1 day, but redundant files must be deleted within one day, otherwise the remaining space will not be used; the gquota group considers the maximum limit, so it is set to 90 MB! (Note that the advantage of this setting is that it is flexible. For example, the current mail service has so many users. The maximum space promised to each user is several GB. However, it is impossible for everyone to use such a large space, so the total space of the mail service , in fact it is definitely not the number of registered customers multiplied by the number of GB, otherwise how big would it be?)

[root@localhost ~]# groupadd qgroup
[root@localhost ~]# useradd -m -g qgroup quser1
[root@localhost ~]# useradd -m -g qgroup quser2
[root@localhost ~]# passwd quser1
[root@localhost ~]# passwd quser2
[root@localhost ~]# df ===> Find a suitable partition to do the experiment, use /disk2 here
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 5952252 3193292 2451720 57% /
/dev/hdb1 28267608 77904 26730604 1% /disk2
/dev/hda5 9492644 227252 8775412 3% /disk1

[root@localhost ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/disk1 /disk1 ext3 defaults 1 2
LABEL=/disk2 /disk2 ext3 defaults,usrquota,grpquota 1 2
/dev/hda3 swap swap defaults 0 0

Note that there are too many usrquota, grpquota, and there are no spaces between defaults, usrquota, grpquota, so be sure to write them correctly. In this way, even if the quota disk format is added! However, since the real quota reads the file /etc/mtab when reading, the file needs to be restarted before it can be rewritten with the new data of /etc/fstab! So you can choose at this time: reboot.

Remount remount filesystem to drive settings.

[root@localhost ~]# umount /dev/hdb1
[root@localhost ~]# mount -a
[root@localhost ~]# grep '/disk2' /etc/mtab
/dev/hdb1 /disk2 ext3 rw,usrquota,grpquota 0 0

In fact, you can also use the remount function of mount.

[root@localhost ~]# mount -o remount /disk2

In this way, the quota function of filesystem has been successfully added.

Scan the user status of the disk and generate important aquota.group and aquota.user:

[root@localhost ~]# quotacheck -avug
quotacheck: Scanning /dev/hdb1 [/disk2] done
quotacheck: Checked 3 directories and 4 files

[root@localhost ~]# ll /disk2
-rw------- 1 root root 6144 Sep 6 11:44 aquota.group
-rw------- 1 root root 6144 Sep 6 11:44 aquota.user

Using quotacheck, you can easily output the required data to him! But the strange thing is that in some Linux versions, quota cannot be started with aquota.user(group). This may be because of the old version of quota, so I made another link file to deceive the quota. This action is not necessary. . (The main reason is that it is important to learn this thinking)

[root@localhost ~]# cd /disk2
[root@localhost ~]# ln -s aquota.user quota.user
[root@localhost ~]# ln -s aquota.group quota.group

Enable quota quota:

[root@localhost ~]# quotaon -avug
/dev/hdb1 [/disk2]: group quotas turned on
/dev/hdb1 [/disk2]: user quotas turned on ===> Only when you see turned on is it really successful!

To edit a user's available space:

[root@localhost ~]# edquota -u quser1
Disk quotas for user quser1 (uid 502):
   Filesystem blocks soft hard inodes soft hard
   /dev/hdb1 0 45000 50000 0 0 0
[root@localhost ~]# edquota -p quser1 quser2 ===> Copy directly to quser2

Next, we need to set the grace time, or use edquota

[root@localhost ~]# edquota -t
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 1days 7days

Use quota -v to query:

[root@localhost ~]# quota -vu quser1 quser2
Disk quotas for user quser1 (uid 502):
      Filesystem blocks quota limit grace files quota limit grace
       /dev/hdb1 0 45000 50000 0 0 0
Disk quotas for user quser2 (uid 503):
      Filesystem blocks quota limit grace files quota limit grace
       /dev/hdb1 0 45000 50000 0 0 0

Note that since the user has not exceeded 45 MB, grace (grace time) will not appear.

Edit the space available to the group:

[root@localhost ~]# edquota -g qgroup
Disk quotas for group qgroup (gid 502):
   Filesystem blocks soft hard inodes soft hard
   /dev/hdb1 0 80000 90000 0 0 0

[root@localhost ~]# quota -vg qgroup
Disk quotas for group qgroup (gid 502):
      Filesystem blocks quota limit grace files quota limit grace
       /dev/hdb1 0 80000 90000 0 0 0