CentOS中对ext4文件系统做磁盘配额

1.修改/etc/fstab文件,使ext4文件系统支持磁盘配额。

UUID="9e6dc1e8-4fc1-4984-be38-524573572d41" /mnt/ext ext4 defaults,usrquota 0 0

2.重新加载fstab文件 mount -o remount /dev/sdb1

3.查看mount挂载详细 mount ,可以看到其中有一条

/dev/sdb1 on /mnt/ext type ext4 (rw,relatime,seclabel,quota,usrquota,data=ordered)

4.生成统计信息表,记录用户磁盘使用状况    quotacheck -cuf /dev/sdb1

5.激活分区配额功能  quotaon /dev/sdb1

6.编辑用户admin使用的磁盘额度       edquota -u admin

Disk quotas for user admin (uid 1000):
     Filesystem         blocks       soft       hard     inodes     soft     hard
  /dev/sdb1            0           60        100          0        0        0

7.blocks为块大小限制,inodes为文件个数限制,这里做块大小限制,限定软限制为60K,硬限制为100,两种限制谁先到谁生效。

8.为/mnt/ext的其他用户分配写权限    chmod o+w /mnt/ext/

9.使用admin用户,在ext分区中使用磁盘空间。这里使用测试命令,对磁盘进行零填充。

 dd if=/dev/zero of=aaa bs=1K count=80

sdb1: warning, user block quota exceeded.
80+0 records in
80+0 records out
81920 bytes (82 kB) copied, 0.000728813 s, 112 MB/s

ll -h

total 101K
-rw-rw-r--. 1 admin admin  80K Aug  3 19:31 aaa

-rw-------. 1 root  root  7.0K Aug  3 19:25 aquota.user
drwx------. 2 root  root   12K Aug  3 18:31 lost+found

10.可以看到超过60K,系统会对用户进行警告,但仍可以继续使用磁盘。

11.继续填充更多数据。

dd if=/dev/zero of=aaa bs=1K count=120

sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: error writing ‘aaa’: Disk quota exceeded
100+0 records in
99+0 records out
101376 bytes (101 kB) copied, 0.00223623 s, 45.3 MB/s

ll -h

total 120K
-rw-rw-r--. 1 admin admin  99K Aug  3 19:34 aaa

-rw-------. 1 root  root  7.0K Aug  3 19:25 aquota.user
drwx------. 2 root  root   12K Aug  3 18:31 lost+found

12.可以看到用户使用的磁盘大小最对不能超过100K的限制。

原文地址:https://www.cnblogs.com/cq146637/p/7806531.html