FreeBSD uses QUOTA (disk quota) to limit user space

Time:2019-8-24

The size of user space and the number of files are often limited in virtual hosts. These restrictions are implemented with QUOTA in Linux and FreeBSD. Here I talk about how to implement it under FreeBSD.

Turn on QUOTA support
First, you need to modify the kernel to add support for quota
machine i386
cpu I686_CPU
#ident GENERIC
ident CNOSvhost
maxusers 0
Options QUOTA # That’s it.
After modification, recompile the kernel.
Then add in / etc / rc. conf:
enable_quotas=”YES”
check_quotas=”YES”
So your system will use QUOTA. You should add QUOTA support by editing the attributes of a file system in / etc / fstab.
The following fstab file sets user quotas and group quotas on the / pub file system
# See the fstab(5) manual page for important information on automatic mounts
# of network filesystems before modifying this file.
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad0s1b             none            swap    sw              0       0
/dev/ad0s1a             /               ufs     rw              1       1
/dev/ad0s1h             /pub            ufs     rw,userquota,groupquota        2  2
/dev/ad0s1e             /tmp            ufs     rw              2       2
/dev/ad0s1g             /usr            ufs     rw              2       2
/dev/ad0s1f             /var            ufs     rw              2       2
/dev/acd0c              /cdrom          cd9660  ro,noauto       0       0
proc                    /proc           procfs  rw              0       0

After setting up the fstab file, execute the following command to open quota
# quotacheck -av
# repquota -a
Basically, all the previous work has been done, and all that remains is to edit user quotas.

Editing user quotas
# Edquota c4st sets the quota for editing user c4st. A text editor interface appears:
Quotas for user c4st:
/pub: kbytes in use: 3438, limits (soft = 100000, hard = 100020)
inodes in use: 25, limits (soft = 25, hard = 26)
We see that the settings are divided into two lines.
Kbyters in use: 3438 indicates that 3438 KB limits have been used (soft = 100000 soft limit 100M, hard = 100020 hard limit)
Soft indicates a warning when this value is reached, and hard indicates the actual size that users can use.
Indes in use: 25, limits (soft = 25, hard = 26) This behavior can have the “number of files” limit, of course, the example gives the value is not practical, the above settings,
Users can only create 26 files. In practical applications, inodes can be adjusted as needed. For example, you need to install a text-based program, such as lb5000 (a webbbs).
Some CGI article management systems, you need to adjust inode’s hard settings appropriately ___________?

Common quota commands
# Edquota-t can set the time before quota users use the soft limit. days, hours, minutes or seconds can be the unit of this setting, as long as the value is reasonable.
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/pub: block grace period: 1 day, file grace period: 1 day
# Repquota-a reports information about quota in the filesystem.
                                Block  limits                    File  limits
User                   used     soft     hard  grace     used    soft    hard  grace
wheel           —        2        0        0      –        1       0       0      –
operator        —      128        0        0      –        2       0       0      –
mysql           —       18        0        0      –        9       0       0      –
vhostuser       —    36164   100000   100050      –      342    1000    1005      –

                                Block  limits                    File  limits
User                   used     soft     hard  grace     used    soft    hard  grace
root            —     9136        0        0      –       12       0       0      –
mysql           —       18        0        0      –        9       0       0      –
testmin         —       18     1000     1050      –        9    1000    1005      –
web             —    22152        0        0      –      122       0       0      –
coms_cn         —     1550        0        0      –      177       0       0      –
c4st            -+     3438   100000   100020      –       25      25      26  22:56

# Quota: Displays the user’s disk usage and upper limit.
– G Display the group quota for the user’s group
– L does not display quotas on NFS systems
– u Display user quotas
– Q Show brief information on usage exceeding quota
– V Check user quota settings

# edquota -p test c4st c4st1 c4st2…..
The user test quota settings will be copied to user c4st c4st1 c4st2…..

# The quotacheck-a command can be executed periodically to check that all settings are normal (it can be executed in crontab).

Note: For any reprints or excerpts, please indicate the source of the article (Chinese FreeBSD user group http://www.cnfug.org)

Recommended Today

Build HTTP service with C + + Mongoose

Mongoose source code address:https://github.com/cesanta/mo… Mongoose user manual:https://www.cesanta.com/devel… Mngoose set up HTTP service #include <string> #include “mongoose.h” using namespace std; static const char *s_http_port = “8000”; static void ev_handler(mg_connection *nc, int ev, void *ev_data) { struct http_message *hm = (struct http_message *) ev_data; if (ev == MG_EV_HTTP_REQUEST) { std::string uri; if (hm->uri.p && hm->uri.p[0] == ‘/’) […]