Article Title: Linux User disk space restrictions. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
No matter how large the disk space is, insufficient disk space seems to be a permanent fact. Linux provides a method to restrict the disk space of a user, so that each user can reasonably and effectively use the space allocated to him. The user's disk space is limited by the File System (partition), regardless of the directory in which the user's file is stored.
1. Modify the/etc/fstab file. Add the limit option to the mount command line of the file system (example below ).
/Dev/hda7/home ext3 defaults, usrquota, kgquota 1 2
2. Reload Linux partitions, for example:
[Root @ fileserver root] # mount-o remount/home
Continue.
3. Create the aquota. user and aquota. group files in the installation directory of the file system to add the disk quota:
[Root @ fileserver root] # cd/home (/home is the mount point of a single partition/dev/hda7)
[Root @ fileserver home] # touch aquota. user (sets the disk quota for Users)
[Root @ fileserver home] # touch aquota. group (set the disk quota for the user group)
The generated aquota. user and aquota. group are empty and do not meet the system requirements.
Please refer to the next step.
4. Generate aquota. user and aquota. group that meet System Requirements
[Root @ fileserver home] # quotacheck/home (generate aquota. user compliant with system requirements)
[Root @ fileserver home] # quotacheck-g/home (generate aquota. group that meets system requirements)
An error message is prompted during generation. This does not matter. Because touch previously generated an empty file, the format must be incorrect.
In this case, aquota. user and aquota. group are generated correctly.
Next step:
5. Set the disk space limit for the user:
[Root @ fileserver home] # edquota [-u] user_name
[Root @ fileserver home] # edquota-g group_name (for user groups)
This command opens a vi window and sets the disk space and the number of I nodes for the user. the soft quota is a temporary quota. The hard quota is a permanent quota (the soft quota can be slightly larger than the hard quota). The editing method is the same as that of vi and exit with the ZZ or: wq command. to specify the same disk quota for several users, such as user1, user2, and user3, use the following command to grant these users the same quota as protuser:
[Root @ fileserver home] # edquota [-u]-p protuser user1 user2 user3
[Root @ fileserver home] # edquota-g-p protgroup group1 group2 group3
Set the time between soft quota and hard quota:
[Root @ fileserver home] # edquota-t
A vi window appears:
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/Dev/hda7 7 days 7 days
Modify it to what you need and save and exit to set the time.
After that, you may need to restart to make the disk quota take effect.
You can, but pay attention to some issues. Please continue.
6. Check the consistency of disk space restrictions. The system automatically checks the hard disk (/etc/rc. sysinit) every time you restart the system.
If the partition has been attached in the "read/write" mode, be careful, for example:
[Root @ fileserver root] # quotacheck/home
Quotacheck: Quota for users is enabled on mountpoint/home so quotacheck might damage the file.
Please turn quotas off or use-f to force checking.
At this time, due to a certain need, or in some circumstances, "have to" run this command:
[Root @ fileserver home] # quotacheck-mf [-u]/dev/hda7
[Root @ fileserver home] # quotacheck-mf-g/dev/hda7
The-m [M] parameter indicates that the quota of the hard disk is forced to be checked in "read and write" mode (there is a certain possibility of "writing" data loss, ensure that no process is writing this partition. We recommend that you do this in single-user mode .).
Example: (check at ordinary times)
[Root @ fileserver root] # quotacheck/var/spool/-f
Quotacheck: Cannot remount filesystem mounted on/var/spool read-only so counted values might not be right.
Please stop all programs writing to filesystem or use-m flag to force checking.
[Root @ fileserver root] # quotacheck/var/spool/-m
Quotacheck: Quota for users is enabled on mountpoint/var/spool so quotacheck might damage the file.
Please turn quotas off or use-f to force checking.
[Root @ fileserver root] # quotacheck/var/spool/-mf
[Root @ fileserver root] #
7. If you want to cancel the disk space and the number of I nodes in the future, you can run the following command:
[Root @ fileserver root] # quotaoff/home (cancel the disk space limit .)
[Root @ fileserver root] # quotaon/home (disk space limit is now enabled .)
[Root @ fileserver root] # quotaon/home (the disk space limit has been enabled, so the following error occurs :)
Quotaon: using/home/aquota. group on/dev/hda7: Device or resource busy
Quotaon: using/home/aquota. user on/dev/hda7: Device or resource busy