linux系统中磁盘容量配额

磁盘容量配额?

管理员用户设置普通用户或用户组针对特定文件夹可以使用的最大磁盘空间及最多文件数目

1、修改配置文件,使特定目录支持磁盘容量配额技术

[root@PC1linuxprobe dev]# vim /etc/fstab
[root@PC1linuxprobe dev]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Nov 5 15:23:01 2020 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/rhel-root / xfs defaults 1 1 UUID=0ba20ae9-dd51-459f-ac48-7f7e81385eb8 /boot xfs defaults,uquota 1 2 /dev/mapper/rhel-swap swap swap defaults 0 0 /dev/sdb1 /devide xfs defaults 0 0 /dev/sdb swap swap defaults 0 0

2、重启系统

3、查看是否支持磁盘容量配额

[root@PC1linuxprobe dev]# mount | grep boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

4、增加其他人/boot目录下写得权限

[root@PC1linuxprobe dev]# chmod -Rf o+w /boot
[root@PC1linuxprobe dev]# ll -d /boot/
dr-xr-xrwx. 3 root root 4096 Nov  5 15:28 /boot/

5、创建测试用户

[root@PC1linuxprobe dev]# useradd testuser

6、使用xfs_quota命令设置/boot目录针对testuser的磁盘容量配额

[root@PC1linuxprobe dev]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 testuser' /boot

7、查看/boot对testuser的磁盘容量配额

[root@PC1linuxprobe dev]# xfs_quota -x -c report /boot
User quota on /boot (/dev/sda1)
                               Blocks                     
User ID          Used       Soft       Hard    Warn/Grace     
---------- -------------------------------------------------- 
root            95344          0          0     00 [--------]
testuser            0       3072       6144     00 [--------]

8、切换至testuser用户,向/boot目录写入测试文件

[root@PC1linuxprobe dev]# su - testuser 
[testuser@PC1linuxprobe ~]$ dd if=/dev/zero bs=5M count=1 of=/boot/test.file
1+0 records in
1+0 records out
5242880 bytes (5.2 MB) copied, 0.00481423 s, 1.1 GB/s
[testuser@PC1linuxprobe ~]$ dd if=/dev/zero bs=10M count=1 of=/boot/test.file
dd: error writing ‘/boot/test.file’: Disk quota exceeded
1+0 records in
0+0 records out
6291456 bytes (6.3 MB) copied, 0.0118407 s, 531 MB/s

9、切换至root用户,使用edquota -u user 命令编辑磁盘容量配额

[root@PC1linuxprobe ~]# edquota -u testuser
[root@PC1linuxprobe ~]# xfs_quota -x -c report /boot
User quota on /boot (/dev/sda1)
                               Blocks                     
User ID          Used       Soft       Hard    Warn/Grace     
---------- -------------------------------------------------- 
root            95344          0          0     00 [--------]
testuser         6144       3072      16144     00  [6 days]

10、切换至testuser用户,向/boot目录中写入测试文件

[root@PC1linuxprobe ~]# su - testuser
[testuser@PC1linuxprobe ~]$ dd if=/dev/zero bs=10M count=1 of=/boot/test.file
1+0 records in
1+0 records out
10485760 bytes (10 MB) copied, 0.0144249 s, 727 MB/s
[testuser@PC1linuxprobe ~]$ dd if=/dev/zero bs=20M count=1 of=/boot/test.file
dd: error writing ‘/boot/test.file’: Disk quota exceeded
1+0 records in
0+0 records out
16531456 bytes (17 MB) copied, 0.0766514 s, 216 MB/s

总结磁盘容量配额:

  • 修改配置文件,使硬盘(磁盘分区)挂载点支持磁盘容量配额技术
  • 使用xfs_quota命令设置磁盘容量配额,示例:xfs_quota -x -c  'limit bsoft=3m bhard=6m isoft=3 ihard=6 testuser' /boot
  • 使用xfs_quota命令查看磁盘容量配额的磁盘(非文件数目),示例:xfs_quota -x -c report /boot
  • 使用edquota 调整磁盘容量配额,同时可查看磁盘配额,示例:edquota -u usertest
原文地址:https://www.cnblogs.com/liujiaxin2018/p/13951715.html