Linux user disk space restrictions Brief description

  

Regardless of how large the disk space, disk space is not enough to use seems to be a permanent fact. Linux provides a means of limiting user disk space in order to encourage each user to use the space allocated to him reasonably and efficiently. The limit of user disk space is in the file system (partition), regardless of which directory in the file system the user file is placed in.

1. Modify the /etc/fstab file. Add the quota option to the appropriate mount command line of the file system (example below).

/dev/hda7 /home ext3 defaults,usrquota,grpquota 1 2

2. Reload the Linux partition, for example:

[root@fileserver root]# mount - o remount /home

Continue.

3. Create aquota.user and aquota.group files in the mount point directory of the file system to which you want to add disk quota:

[root@fileserver root]# cd /home (/home is Single partition /dev/hda7 mount point)

[root@fileserver home]# touch aquota.user (set disk quota for user)

[root@fileserver home]# touch aquota. Group (set disk quota for user groups)

The aquota.user and aquota.group generated at this time are empty and do not meet the requirements of the system.

Please see the next step.

4. Generate aquota.user and aquota.group

[root@fileserver home]# quotacheck /home that meets the system requirements (generate aquota.user that meets system requirements)

[root@fileserver home]# quotacheck -g /home (generate aquota.group that meets system requirements)

When generating, there is an error message. It doesn't matter. Because the previous touch generated an empty file, the format is definitely wrong.

This is the correct aquota.user and aquota.group generated.

Continue to the 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 to set the quota for the disk space and number of i nodes for the user. The soft limit is a temporary limit. The ;hard limit is a permanent limit (soft limit can be slightly larger than the hard limit), the editing method is exactly the same as vi, and the ZZ or :wq command is used to exit. To give several users user1, user2, user3 the same disk quota, available The following command gives 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:

Grace period before enforcing soft limits for users:

Time units may be: days, hours, minutes, or seconds< Br>

Filesystem Block grace period Inode grace period

/dev/hda7 7days 7days

Modify to your own needs and save the exit to set this time.

You may need to reboot after this to make the disk quota take effect.

You can, but pay attention to some problems, please continue to read.

6. Check the consistency of the disk space limit, the system will automatically perform ( /etc/rc.sysinit) after checking the hard disk every time you restart, you do not need to do it yourself.

If the partition has been hanged in "read-write" mode, you should 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 some need, or in a certain In this case, "have to" run this command:

[root@fileserver home]# quotacheck -mf [-u] /dev/hda7

[root@fileserver home]# quotacheck - Mf -g /dev/hda7

Parameter-m[M] Means: Forcing the quota of the hard disk in the "read, write" mode (there is a certain "writing" data loss, it should be ensured No process is writing this partition. It is recommended to do it in single-user mode.).

For example: (check in usual)

[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.< Br>

[root@fileserver root]# quotacheck /var/spool/-mf

[root@fileserver root]#

7. If you want to cancel disk space and i later The limit on the number of nodes can be found in the following command:

[root@fileserver root]# quotaoff /home (cancel disk space limit.)

[root@fileserver root]# quotaon /Home (now boot disk space limit.)

[root@fileserver root]# quotaon /home (The disk space limit has been started, so the following error occurred:)

quotaon: using /home /aquota.gr Oup on /dev/hda7: Device or resource busy

quotaon: using /home/aquota.user on /dev/hda7: Device or resource busy

Copyright © Windows knowledge All Rights Reserved