Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 磁盤配額實戰:從分區掛載到用戶限額的完整配置流程

編輯:Linux 教學

Linux 磁盤配額 限制用戶或用戶組在特定文件系統上的磁盤使用量(空間與文件數),配置分七步:

1. 分區掛載選項啟用 Quota

編輯 /etc/fstab,在目標分區掛載選項添加:

  • 用戶配額:usrquota
  • 組配額:grpquota
/dev/mapper/vg_muban-lv_home /home ext4 usrquota 1 2

或臨時掛載:mount -o usrquota /dev/sdb2 /mnt/homebak

2. 重新掛載分區使選項生效

mount -o remount /home

3. 掃描文件系統生成配額索引文件

quotacheck -cum /home

-c 創建新索引文件,-u 掃描用戶,-m 不重新掛載只讀(允許寫入)。生成 aquota.user、aquota.group。

4. 啟用磁盤配額

quotaon /home

5. 編輯用戶具體限額

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),無文件數限制。

6. 測試驗證

[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,配額生效。

7. 常用查詢命令

  • quota -u barlow:查看用戶配額使用情況
  • repquota -a:報告所有文件系統配額摘要
Copyright © Windows教程網 All Rights Reserved