Experimental environment
Environment: CentOS 7.3, a disk SDB is divided into a partition sdb1.
Install disk quota support software
yum install quota
Make a file system and mount it in a way that supports quota functions
mkfs.ext4 /dev/sdb1 mount /dev/sdb1 /tmp mount -o remount,usrquota,grpquota /dev/sdb1
Check whether disk quota technology is enabled when disk is mounted
mount To mount permanently (add usrquota,grpquota to the configuration file) vim /etc/fstab /dev/sdb1 /tmp ext4 defaults,usrquota,grpquota 0 0
Detect disk quotas and generate quota files (close se if error occurs) linux)
quotacheck -cugv /tmp #This command generates two files under / tmp #Interpretation: - c Create quota file, - u (- g) scan disk space, calculate the number of directories and files occupied by each user (group) identification code, - a scan in / etc/fstab file, there are partitions added quota settings, - d shows the instruction execution process in detail, so as to facilitate error removal. - R. Exclude the partition where the root directory is located
Quota Settings for User and Group Accounts
useradd wsfnk #Create a user first, and if you have one, you don't need to create one. edquota -u wsfnk #- g Represents the wsfnk group, where editing limits are limited in a vim-like interface. Disk quotas for user wsfnk (uid 1000): Filesystem blocks soft hard inodes soft hard /dev/sdb1 0 20 50 1 0 0 #The fields are explained as follows: #Filesystem displays partitions that implement disk quotas. #blocks for the size of the current use, do not need to modify; #Soft is a soft limit, which will give a warning when exceeded, and the excess part will be saved for 7 days by default. #Hard is a hard restriction, which can not be exceeded (the default units of hard and soft restrictions are KB); #The latter two identical soft and hard represent the soft and hard limits on the number of files that the user can create in the partition. #In this example, qingsword can use the soft limit size of / dev/sdb1 partition 10KB, hard limit 20KB, the number of files can be created soft limit is 3, hard limit 5; edquota parameter -u : Setting up user's quta,This is the preset parameter. -g : Set group's quota -p Source User Name : The source user's quota Settings apply to other users or groups -t : Setting grace period
Activate disk quotas
quotaon -ugv /tmp
Note: Blocks in disk quotas are not blocks seen in fdisk, but represent 1k
Test whether restrictions will take effect
Writing data mkdir /tmp/test chmod 777 /tmp/test //Handover user wsfnk su wsfnk cd /tmp/test dd if=/dev/zero of=wss.test bs=1k count=500
Close disk quotas
#Close disk quotas for individual disks quotaoff /sdb1 #Close all open disk quotas quotaoff -a #Conversely, open all disk quotas quotaon -a #If you no longer use disk quotas, you can delete the configuration files as well. rm -rf /sdb1/aquota.* #Finally, delete the automatic mount in / etc/fstab