Linux 磁盤配額 限制用戶或用戶組在特定文件系統上的磁盤使用量(空間與文件數),配置分七步:
編輯 /etc/fstab,在目標分區掛載選項添加:
usrquotagrpquota/dev/mapper/vg_muban-lv_home /home ext4 usrquota 1 2
或臨時掛載:mount -o usrquota /dev/sdb2 /mnt/homebak
mount -o remount /home
quotacheck -cum /home
-c 創建新索引文件,-u 掃描用戶,-m 不重新掛載只讀(允許寫入)。生成 aquota.user、aquota.group。
quotaon /home
edquota barlow -f /home
進入編輯器,設置 blocks(空間,單位 KB) 和 inodes(文件數) 的 soft(警告)與 hard(硬限制)值。例如:
Filesystem blocks soft hard inodes soft hard
/dev/mapper/vg_muban-lv_home 4144 0 102400 15 0 0
上例限制用戶 barlow 最大使用 100MB(102400 KB),無文件數限制。
[barlow@update ~]$ dd if=/dev/zero of=testfile bs=1M count=50 # 寫 50MB,成功
[barlow@update ~]$ dd if=/dev/zero of=testfile bs=1M count=120 # 寫 120MB,失敗
dm-3: write failed, user block limit reached.
dd: 正在寫入 "testfile": 超出磁盤限額
實際寫入約 100MB 後被阻斷,ls -lh 確認文件大小約 101MB,配額生效。
quota -u barlow:查看用戶配額使用情況repquota -a:報告所有文件系統配額摘要