Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

6.7 Disk capacity quota


May 23, 2021 That's what Linux should learn



As this book said earlier, Linux systems are designed to allow many people to work together and perform their own tasks, making them multi-user, multi-tasking operating systems. H owever, hardware resources are fixed and limited, and if some users continue to create files or store movies on Linux systems, hard disk space will one day be filled. I n this case, the root administrator needs to use the disk capacity quota service to limit the maximum amount of hard disk space or maximum number of files that a user or group of users can use for a particular folder, and once this maximum is reached, continued use is no longer allowed. Y ou can use the quota command for disk capacity quota management to limit the available capacity of a user's hard disk or the maximum number of files that can be created. The quota command also has the ability to have soft and hard limits.

Soft limit: The user is prompted when the soft limit is reached, but the user is still allowed to continue using it for a limited amount.

Hard limit: The user is prompted when the hard limit is reached and the user's actions are forcibly terminated.

The quota disk capacity quota service package is already installed in the RHEL 7 system, but the storage device does not turn on support for quota by default, requiring manual editing of the profile so that the /boot directory in the RHEL 7 system can support the quota disk quota technology. I n addition, special attention needs to be paid to readers who have studied early Linux systems or have experience with RHEL 6 systems. E arly Linux systems wanted hard disk devices to support the quota disk capacity quota service, using the usrquota parameter, while the RHEL 7 system used the uquota parameter. After restarting the system and viewing with the mount command, you can see that the /boot directory already supports the quota disk quota technology:

[root@linuxprobe ~]# vim /etc/fstab #

/etc/fstab

  1. # Created by anaconda on Wed May 4 19:26:23 2017
  2. #
  3. # Accessible filesystems, by reference, are maintained under '/dev/disk'
  4. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  5. #
  6. /dev/mapper/rhel-root / xfs defaults 1 1
  7. UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults,uquota 1 2
  8. /dev/mapper/rhel-swap swap swap defaults 0 0
  9. /dev/cdrom /media/cdrom iso9660 defaults 0 0
  10. /dev/sdb1 /newFS xfs defaults 0 0
  11. /dev/sdb2 swap swap defaults 0 0
  12. [root@linuxprobe ~]# reboot
  13. [root@linuxprobe ~]# mount | grep boot
  14. /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

Next, create a user tom to check the quota disk capacity quota effect and add write permissions for others for the /boot directory to ensure that the user can write data normally:

[root@linuxprobe ~]# useradd tom [root@linuxprobe ~]# chmod -Rf o+w /boot

  1. xfs_quota command

xfs_quota command is a command designed specifically for the XFS file system to manage the quota disk capacity quota service in the format of "xfs_quota (Parameters) Quota File System." A mong them, the -c parameter is used to set the command to be executed in the form of parameters, and the -x parameter is expert mode, allowing operations personnel to make more complex configurations of the quota service. N ext, we use xfs_quota command to set the quota disk capacity quota for the user tom/boot directory. Specific limit controls include: soft and hard limits for hard drive usage are 3MB and 6MB, respectively, and soft and hard limits for the number of files created are 3 and 6, respectively.

[root@linuxprobe ~]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 tom' /boot [root@linuxprobe ~]# xfs_quota -x -c report /boot User quota on /boot (/dev/sda1) Blocks User ID Used Soft Hard Warn/Grace


  1. root 95084 0 0 00 [--------]
  2. tom 0 3072 6144 00 [--------]

When the various hard and soft limits above are configured, try switching to this normal user, and then try to create a file with a volume of 5MB and 8MB, respectively. As you can see, there are system restrictions when creating 8MB files:

[root@linuxprobe ~]# su - tom [tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=5M count=1 1+0 records in 1+0 records out 5242880 bytes (5.2 MB) copied, 0.123966 s, 42.3 MB/s [tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=8M count=1 dd: error writing ‘/boot/tom’: Disk quota exceeded 1+0 records in 0+0 records out 6291456 bytes (6.3 MB) copied, 0.0201593 s, 312 MB/s

  1. edquota command

The edquota command is used to edit the user's quota quota limit in the format "edquota (parameters) (users). A fter you set a quota disk capacity quota limit for users, you can use the edquota command to modify the value of the limit as needed. W here the -u parameter indicates which user to set for, and the -g parameter indicates which user group to set for. T he edquota command calls the Vi or Vim editor to let the root administrator modify the specifics to be restricted. Here's how to increase the hard limit for user tom's hard drive usage from 5MB to 8MB:

[root@linuxprobe ~]# edquota -u tom Disk quotas for user tom (uid 1001): Filesystem blocks soft hard inodes soft hard /dev/sda1 6144 3072 8192 1 3 6 [root@linuxprobe ~]# su - tom Last login: Mon Sep 7 16:43:12 CST 2017 on pts/0 [tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=8M count=1 1+0 records in 1+0 records out 8388608 bytes (8.4 MB) copied, 0.0268044 s, 313 MB/s [tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=10M count=1 dd: error writing ‘/boot/tom’: Disk quota exceeded 1+0 records in 0+0 records out 8388608 bytes (8.4 MB) copied, 0.167529 s, 50.1 MB/s