1 usage limits for disk quotas
For the entire partition only: When the disk quota is actually running, it is limited for the entire partition, for example, if/DEV/HDA5 is loaded under/home, then all directories under/home are restricted. Valid only for general identity users: Not all accounts on Linux can set disk quotas, for example, root cannot set disk quotas because he owns all of the system's data.
2 Steps for disk quotas
(1) Start partition quota function
(2) Generate quota information file
(3) Set user and group quotas
(4) Start disk quota service
3 Specific implementation of disk quotas
First verify that the package is installed
[Email protected] ~]# Rpm-q Quota
Quota-3.13-1.2.5.el5
Confirm that the kernel supports quota disk quotas.
[[email protected] ~]# grep config_quota/boot/config-' uname-r '
Config_quota=y
Config_quotactl=y
Plug in a new hard drive for 5G size and then enter the system
Fdisk–l View hard disk information, because it is the second hard disk, so the/DEV/SDB is marked as 5G
Fdisk–cu/dev/sdb Edit the second hard disk to create a partition for it
Command (M for help): M if it's the first time, click M to view the full menu details
The details of which are not explained in this one by one, followed by a separate document explaining the use of the disk
Command (M for help): N Partitioning
Commandaction
E Extended
P partition (1-4)
P select p for partition selection
PartitionNumber (1-4): 1 Select the partition number, if it is the first time the new hard disk is created select 1, if the old hard disk before partitioning a few times in turn backward push, not more than 4, double-click Enter
Lastsector, +sectors or +size{k,m,g}: +g How much space is added to the partition G must be capitalized
Command (M for help):p print the previous configuration information
Command (M for help): W Save previously configured information
Partx–a/dev/sdb Reload the disk
MKFS.EXT4/DEV/SDB1 Select the appropriate partition number to format the words, if not format, can not be mounted
Df–h using commands to view the Mount status in the system
Mkdir/mnt/quota my side. Create a file as a mount location
Mount/dev/sdb1/mnt/quota
Df–h Use the command again to view the Mount situation
Mount View mount information The last line can be seen/dev/sdb1 On/mnt/quota type EXT4 (rw)
Vim/etc/fstab writes mount information to it, automatically mounts it on boot, writes to the last line
/dev/sdb1/mnt/quota EXT4 Defaults,usrquota,grpquota 1 2
Mount–o Remount/mnt/quota do not use the re-mount partition without restarting the server
Mount to see if the last line of information changes/dev/sdb1 On/mnt/quota type EXT4 (Rw,usrquota,grpquota) The information appears to indicate that the mount was successful
Quotacheck–cumg/mnt/quota The primary purpose of this command is to scan a disk's quota space, which is scanned for the partition, and because the disk continues to line up, the file may increase during the scan, causing a disk quota scan error, so When using Quotacheck, the disk will be "automatically set to read-only sector"; When the scan is complete, the resulting disk space results are written to the top of the zone (Aquota.user and Aquota.group)
-C Represents the creation
-M represents mandatory execution
-U scans files and directories for users and establishes Aquota.user
-G scan files and directories for groups, will establish aquota.group
Note If there is a
Quotacheck:cannot Create new Quotafile/mnt/quota/aquota.user.new:permission denied
Quotacheck:cannot Initialize IO on new quotafile:permission denied
Quotacheck:cannot Create New Quotafile/mnt/quota/aquota.group.new:permissiondenied
Quotacheck:cannot Initialize IO on new quotafile:permission denied
The above problem is your insufficient permissions, the reason is that SELinux recommends that you close, use the following command to close
Setenforce0
Quotaon–a all disk partitions are turned on
USERADDLWH Creating a user Lwh
PASSWDLWH creating a password for LWH
Edquota–u LWH will lwh this user for disk quotas
Disk quotas for user LWH (UID 501):
Filesystem blocks soft hard inodes soft tough (for it to create 10M rigid settings, 3 files soft limit and 4 files hard limit)
/DEV/SDB1 5 0 10240 3 4
Soft is its soft limit if it exceeds the soft limit there will be a hint that if the space is not reduced to soft limit within 7 days, it is not allowed to use the following
Hard is its rigid limit and cannot continue to be used if the hard limit is reached
Edquota–t Change Prompt days
Filesystem Block grace period Inode grace period
/DEV/SDB1 7days 7days
Inode and block usage instructions
There are two ways to use disk quotas to limit space, namely, inode and block respectively. Disk quotas can limit the amount of space a user can use in a partition (blocks), or you can limit the number of files (inodes) that users are able to create in a partition, as long as the user creates more files than they can use, even if the files are empty. His behavior of creating files again will also be limited.
Here is a description of the inode concept. When a file is created in Linux, a unique inode is assigned to the file, and the inode of the file is used to access the properties of the file. That is, each file in the Linux system must correspond to an inode, the popular point is that the Linux kernel does not know the letter, so the user should have UID, user group to have GID, process to have the PID ..., file to have inode, once the inode lost files will not be accessible.
The test must be carried out on the seat where it is mounted during testing.
Test block now
Cd/mnt/quota
Chmod757/mnt/quota Add other user-written permissions to quota files, or you can switch to their users after you do not write to the file
Sulwh
Touchluowenhao
The DDIF=/DEV/SDB1 Of=luowenhao bs=1024kcount=20480 command generates a fixed-size file. where "if" means input, pseudo-device/dev/zero constantly generate the string "0", initialize the file; "of" represents the output, this example generates the file "Quotatest" in the user's current directory, "BS" specifies the block size for "block size", and the unit is set to " 1024k "is 1MB;" Count "is the size of the file (" Quotatest ") generated for the total, and if" BS "is 1MB," 10240000 "is 10000GB.
The following prompt will appear
Sdb1:write Failed,user block limitreached.
Dd: Writing "Luowenhao": exceeding disk quota
Test Inode Now
Cd/mnt/quota
Sulwh
Touch 1
Touch2
Touch3
TOUCH4 When you are finished creating the 4 file system prompt sdb1:warning, UserFile quota exceeded.
Touch5 prompt sdb1:write Failed,user file limit reached when creating 5 files. Touch: "Unable to create 5" exceeded disk limit
A workaround for some of the following problems occurs during the restart of the server
Give root password for maintenance when the Linux system is forcibly shut down or restarted, the computer's file system may be damaged, the system will automatically check and repair the file system, when the file system does not automatically repair, the screen will appear the above message.
In the process of server startup, the above error message appears, see failed that line of error prompts I have appeared before, in the construction of quota in/etc/fstab added lable=/dev/ SDB1 Automatic mount command causes the system not to load automatically during server startup.
General methods of repair
Giveroot Password for maintenance
(Ortype control-d to continue): After entering the password, it appears:
(Repairfilesystem) 1 #
E2FSCK–Y/DEVSDB1 Select the previous error partition to fix
The system will automatically repair and display the repair progress on the screen
Press exit after completion and restart the system at reboot
The ultimate Violence method
Giveroot Password for maintenance
(Ortype control-d to continue): After entering the password, it appears:
(Repairfilesystem) 1 #
Enter/etc/fstab will lable a row to delete, but at this time you enter the/etc/fstab when the file will prompt you only read-only (Read permission) so that you delete after the use of wq! force Save is also not possible, only q! after exit. Use the ultimate kill trick below
Mount–w–o remount/
Mount/dev/sdb1/mnt/quota here must remember which partition was used before the quota was built and mounted under that path I'm/mnt/quota.
Vim/etc/fstab can now enter the lable this line to delete save exit
Reboot can be restarted.
Llinux disk quota setup and general FAQ