对用户的磁盘配额

使用虚拟机 添加一块20G硬盘

[root@localhost ~]# fdisk -l

[root@localhost ~]# fdisk /dev/sdb (创建一个主分区sdb1,ext3)

[root@localhost ~]# partprobe /dev/sdb

[root@localhost ~]# mkfs.ext3 /dev/sdb1

[root@localhost ~]# mkdir /mail //建立挂载点


[root@localhost ~]# echo '/dev/sdb1 /mail ext3 defaults,usrquota 0 0' >> /etc/fstab //配置分区/dev/sdb1支持配额

[root@localhost ~]# mount -a // 挂载/etc/fstab 中默认的挂载项或reboot

[root@localhost ~]# mount | grep sdb1

/dev/sdb1 on /mail type ext3 (rw,usrquota)


[root@localhost ~]# ls /mail/

lost+found

[root@localhost ~]# quotacheck -uc /dev/sdb1 //生成配额文件

[root@localhost ~]# ls /mailbox/

aquota.user lost+found


[root@localhost ~]# edquota -u tom //配置对tom的配额信息


Disk quotas for user tom (uid 500):

Filesystem blocks soft hard inodes soft hard

/dev/sdb1 0 80000 100000 0 4 6

[root@localhost ~]# ls -ld /mail/

drwxr-xr-x 3 root root 4096 10-16 22:24 /mail/

[root@localhost ~]# quota -u /dev/sdb1

[root@localhost ~]# chown tom /mail/ //将tom改为/mail/目录的所有者

[root@localhost ~]# ls -ld /mail/

drwxr-xr-x 3 tom root 4096 10-16 22:24 /mail/

[root@localhost ~]# su - tom //切换到tom验证

[tom@localhost ~]$ dd if=/dev/zero of=/mail/test.db bs=1M count=60

60+0 records in

60+0 records out

62914560 bytes (63 MB) copied, 0.367778 seconds, 171 MB/s

[tom@localhost ~]$ dd if=/dev/zero of=/mail/test.db bs=1M count=90

sdb1: warning, user block quota exceeded.

90+0 records in

90+0 records out

94371840 bytes (94 MB) copied, 0.298712 seconds, 316 MB/s

[tom@localhost ~]$ dd if=/dev/zero of=/mail/test.db bs=1M count=120

sdb1: warning, user block quota exceeded.

sdb1: write failed, user block limit reached.

dd: 写入 “/mail/test.db”: 超出磁盘限额

98+0 records in

97+0 records out

102289408 bytes (102 MB) copied, 0.267445 seconds, 382 MB/s

[tom@localhost ~]$ touch /mail/test.txt

[tom@localhost ~]$ touch /mail/test1.txt

[tom@localhost ~]$ touch /mail/test2.txt

sdb1: warning, user file quota exceeded.

[tom@localhost ~]$ touch /mail/test3.txt

[tom@localhost ~]$ touch /mail/test4.txt

sdb1: write failed, user file limit reached.

touch: 无法触碰 “/mail/test4.txt”: 超出磁盘限额

[tom@localhost ~]$ ls /mail/

aquota.user lost+found test1.txt test2.txt test3.txt test.db test.txt

[tom@localhost ~]$ ls -l /mail/

总计 100020

-rw------- 1 root root 7168 10-16 22:34 aquota.user

drwx------ 2 root root 16384 10-16 22:12 lost+found

-rw-rw-r-- 1 tom tom 0 10-16 22:37 test1.txt

-rw-rw-r-- 1 tom tom 0 10-16 22:37 test2.txt

-rw-rw-r-- 1 tom tom 0 10-16 22:37 test3.txt

-rw-rw-r-- 1 tom tom 102289408 10-16 22:35 test.db

-rw-rw-r-- 1 tom tom 0 10-16 22:37 test.txt