Create quota for user alice and /home/alice, least/soft limit is 40K, when exceeding 80K, the system will display the exceeded the user quota.
1, check the kernel support the quota function,
[root@server4 home]# grep CONFIG_QUOTA /boot/config-2.6.32-358.6.1.el6.x86_64
CONFIG_QUOTA=y
CONFIG_QUOTA_NETLINK_INTERFACE=y
# CONFIG_QUOTA_DEBUG is not set
CONFIG_QUOTA_TREE=y
CONFIG_QUOTACTL=y
[root@server4 home]#
2, modify the /etc/fstab to activate the quota support for the /home folder,
[root@server4 home]# vim /etc/fstab
add 'usrquota' and 'grpquota'
/dev/mapper/vgsrv-home /home ext4 defaults,usrquota,grpquota 1 2
3, remount the file system, make the quota effective,
mount -o remount,usrquota,grpquota /home
4, use quotacheck command to generate the basic quota configuration file,
5, activate the quota limitation,
6, use edquota command to configure the quota limit to specific user,
[root@server4 home]# edquota -u alice
modify the content to:
Disk quotas for user alice (uid 1004):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/vgsrv-home 80 40 80 12 0 0
here 40K as soft limit, 80K as hard limit.
7, use repquota to check the quota status,
[root@server4 home]# repquota /home
*** Report for user quotas on device /dev/mapper/vgsrv-home
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 37945 0 0 5 0 0
lucy -- 16 0 0 8 0 0
student -- 38337 0 0 226 0 0
mary -- 20 0 0 10 0 0
alice +- 80 40 80 7days 12 0 0
bobby -- 16 0 0 8 0 0
aclan -- 16 0 0 8 0 0
8, test the result,
[root@server4 home]# su - alice
[alice@server4 ~]$ dd if=/dev/zero of=file1 bs=1k count=50
dm-3: warning, user block quota exceeded.
50+0 records in
50+0 records out
51200 bytes (51 kB) copied, 0.00173795 s, 29.5 MB/s
here the file1 created successful, however there is a warning, if continue to create file, it will fail,
[alice@server4 ~]$ dd if=/dev/zero of=file2 bs=1k count=30
dm-3: write failed, user block limit reached.
dd: writing `file2': Disk quota exceeded
9+0 records in
8+0 records out
8192 bytes (8.2 kB) copied, 0.00401174 s, 2.0 MB/s
file2 still created successful, but already reached 80K, if create another 1K file file3,
[alice@server4 ~]$ dd if=/dev/zero of=file3 bs=1k count=1
dd: opening `file3': Disk quota exceeded