Linux Ext4 磁盘配额限制

发布时间: 更新时间: 总字数:452 阅读时间:1m 作者: IP上海 分享 网址

Linux 系统使用磁盘时,有需要对磁盘容量和 inode 限制的需求,本文介绍如何对Linux Ext4做磁盘配额限制

命令

配额管理命令 quotacheckedquotaquota 包提供,安装命令如下:

yum install -y quota

配置

磁盘初始化

  • 格式化
$ umount /dev/sdb
$ mkfs.ext4 /dev/sdb
  • 修改 /etc/fstab
/dev/sdb /home    ext4    defaults,usrquota,grpquota        0 0
  • 重启或重新挂载
$ mount -a
$ mount -l | grep home
/dev/sdb on /home type ext4 (rw,relatime,quota,usrquota,grpquota,data=ordered)
$ df -lh
...
/dev/sdb                  20G   45M   19G   1% /home

$ quotacheck -ugcv /home/
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb [/home] done
quotacheck: Cannot stat old user quota file /home/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /home/aquota.group: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old user quota file /home/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /home/aquota.group: No such file or directory. Usage will not be subtracted.
quotacheck: Checked 3 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
$ ls /home/
aquota.group  aquota.user  lost+found
  • 启用配额
$ quotaon -ugv /home/
/dev/sdb [/home]: group quotas turned on
/dev/sdb [/home]: user quotas turned on
  • 修改用户配额
$ edquota -u user1
Disk quotas for user user1 (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdb                          0         80        100          0      100      200

block 单位为 KB

测试配额

# 写 80M,功能正常
$ su - user1
$ dd if=/dev/zero of=data bs=1M count=80
sdb: warning, user block quota exceeded.
sdb: write failed, user block limit reached.
dd: error writing ‘data’: Disk quota exceeded
1+0 records in
0+0 records out
98304 bytes (98 kB) copied, 0.000705112 s, 139 MB/s
$ ls -hl
total 96K
-rw-r--r-- 1 user1 tg 96K Oct  4 09:42 data

其他命令

# 查看配额限制
$ quota -u user1
Disk quotas for user user1 (uid 1000):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
       /dev/sdb     100*     80     100   6days       3     100     200
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数