Disk quota, Disk quota
Disk Quota
1. Enable Disk Quota
First, create a new partition/dev/sd5 and create a file system.
[Root @ local ~] # Mkfs. ext4/dev/sda5
Because xfs does not have a disk quota, ext4.
Mount the/dev/sda5 partition to/home.
[Root @ local ~] # Mount/dev/sda5/home
[Root @ local ~] # Blkid/dev/sda5
/Dev/sda5: UUID = "8879cf63-99a5-43bb-9bfe-de303afb0799" TYPE = "ext4"
Modify the/etc/fstab file
[Root @ local ~] # Vim/etc/fstab
UUID = dddd23d1-1012-4bac-9717-56b9b469e0c2/ext4 ults 1 1
UUID = 109d8677-25b8-49af-b4eb-54daa20b6595/boot ext4 ults 1 2
UUID = dacd6ddd-d765-4646-b98c-0579f2732749 swap defaults 0 0
UUID = 8879cf63-99a5-43bb-9bfe-de303afb0799/home ext4 defaults, usrquota, kgquota 0 0
Usrquota is used to enable the user Disk Quota function of the disk.
[Root @ centos7 ~] # Mount-a/home/
Check whether the mounting is successful
[Root @ local ~] # Mount
Sysfs on/sys type sysfs (rw, nosuid, nodev, noexec, relatime, seclabel)
Proc on/proc type proc (rw, nosuid, nodev, noexec, relatime)
[……]
/Dev/sda5 on/home type ext4 (rw, relatime, seclabel, quota, usrquota, kgquota, data = ordered)
You can see that/dev/sda5 has been correctly mounted.
2. Create a quota database
[Root @ centos7 ~] # Quotacheck-cug/home
Because the/etc/fstab file has usrquota and kgquota set, it must be-cug, u corresponds to usrquota, and g corresponds to kgquota.
View the/home directory. Two more files are displayed, indicating that the disk quota database is successfully created.
[Root @ local ~] # Ll/home/
Total 36
-Rw -------. 1 root 7168 Apr 25 :03 aquota. group
-Rw -------. 1 root 7168 Apr 25 :03 aquota. user
Drwx ------. 3 centos 4096 Apr 16 centos
Drwx ------. 2 root 16384 Apr 25 10: 55 lost + found
3. Enable the database
[Root @ local ~] # Quotaon/home/
[Root @ local ~] #
You can see and enable it successfully.
[Root @ local ~] # Quotaon-p/home/
Group quota on/home (/dev/sda5) is on
User quota on/home (/dev/sda5) is on
4. Disk Quota settings
Set the disk quota of user1 to 100 MB, and issue a warning when 80 mb
[Root @ local ~] # Edquota user1
Disk quotas for user user1 (uid 1001 ):
Filesystem blocks soft hard inodes soft hard
/Dev/sda5 52 80000 100000 13 0 0
The default unit is block, and 1 block is 1 K. Soft is the warning value, and hard is the maximum value,
Check whether the configuration is successful.
[Root @ local ~] # Quota user1 # view user's Disk quota Disk quotas for user user1 (uid 1001): Filesystem blocks quota limit grace files quota limit grace/dev/sda5 52 80000 100000 13 0 0
5 Test
(1) create user user1 for testing
[root@local ~]# useradd uesr1
Switch to user1 user
[root@local ~]# su - user1
Last login: Tue Apr 25 11:08:41 CST 2017 on pts/1
(2) File Creation Test
First create a 50 M file testquota.
[user1@local ~]$ dd if=/dev/zero of=testquota bs=1M count=5050+0 records in50+0 records out52428800 bytes (52 MB) copied, 0.562963 s, 93.1 MB/s
Everything is normal.
Create a 35 M file testquota2.
[user1@local ~]$ dd if=/dev/zero of=testquota2 bs=1M count=35sda5: warning, user block quota exceeded.35+0 records in35+0 records out36700160 bytes (37 MB) copied, 0.348267 s, 105 MB/s
Because 50 M + 35 M = 85 M is greater than 80 M
The operation was successful even though the warning was issued this time.
Create another 20 m file testquota3.
[user1@local ~]$ dd if=/dev/zero of=testquota3 bs=1M count=20sda5: write failed, user block limit reached.dd: error writing 'testquota3': Disk quota exceeded13+0 records in12+0 records out13217792 bytes (13 MB) copied, 0.165029 s, 80.1 MB/s
Creation failed because the maximum value is 100 MB!
The test is complete. The experiment is complete!