📄 quotas.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>File System Quotas</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Storage" href="disks.html" /><link rel="PREVIOUS" title="File System Snapshots" href="snapshots.html" /><link rel="NEXT" title="Encrypting Disk Partitions" href="disks-encrypting.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="snapshots.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 16 Storage</td><td width="10%" align="right" valign="bottom"><a href="disks-encrypting.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="QUOTAS" name="QUOTAS">16.14 File System Quotas</a></h1><p>Quotas are an optional feature of the operating system that allow you to limit theamount of disk space and/or the number of files a user or members of a group may allocateon a per-file system basis. This is used most often on timesharing systems where it isdesirable to limit the amount of resources any one user or group of users may allocate.This will prevent one user or group of users from consuming all of the available diskspace.</p><div class="SECT2"><h2 class="SECT2"><a id="AEN25557" name="AEN25557">16.14.1 Configuring Your System toEnable Disk Quotas</a></h2><p>Before attempting to use disk quotas, it is necessary to make sure that quotas areconfigured in your kernel. This is done by adding the following line to your kernelconfiguration file:</p><pre class="PROGRAMLISTING">options QUOTA</pre><p>The stock <tt class="FILENAME">GENERIC</tt> kernel does not have this enabled bydefault, so you will have to configure, build and install a custom kernel in order to usedisk quotas. Please refer to <a href="kernelconfig.html">Chapter 8</a> for moreinformation on kernel configuration.</p><p>Next you will need to enable disk quotas in <tt class="FILENAME">/etc/rc.conf</tt>.This is done by adding the line:</p><pre class="PROGRAMLISTING">enable_quotas="YES"</pre><p>For finer control over your quota startup, there is an additional configurationvariable available. Normally on bootup, the quota integrity of each file system ischecked by the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=quotacheck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">quotacheck</span>(8)</span></a> program.The <a href="http://www.FreeBSD.org/cgi/man.cgi?query=quotacheck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">quotacheck</span>(8)</span></a> facilityinsures that the data in the quota database properly reflects the data on the filesystem. This is a very time consuming process that will significantly affect the timeyour system takes to boot. If you would like to skip this step, a variable in <ttclass="FILENAME">/etc/rc.conf</tt> is made available for the purpose:</p><pre class="PROGRAMLISTING">check_quotas="NO"</pre><p>If you are running FreeBSD prior to 3.2-RELEASE, the configuration is simpler, andconsists of only one variable. Set the following in your <ttclass="FILENAME">/etc/rc.conf</tt>:</p><pre class="PROGRAMLISTING">check_quotas="YES"</pre><p>Finally you will need to edit <tt class="FILENAME">/etc/fstab</tt> to enable diskquotas on a per-file system basis. This is where you can either enable user or groupquotas or both for all of your file systems.</p><p>To enable per-user quotas on a file system, add the <varclass="OPTION">userquota</var> option to the options field in the <ttclass="FILENAME">/etc/fstab</tt> entry for the file system you want to enable quotas on.For example:</p><pre class="PROGRAMLISTING">/dev/da1s2g /home ufs rw,userquota 1 2</pre><p>Similarly, to enable group quotas, use the <var class="OPTION">groupquota</var> optioninstead of <var class="OPTION">userquota</var>. To enable both user and group quotas,change the entry as follows:</p><pre class="PROGRAMLISTING">/dev/da1s2g /home ufs rw,userquota,groupquota 1 2</pre><p>By default, the quota files are stored in the root directory of the file system withthe names <tt class="FILENAME">quota.user</tt> and <tt class="FILENAME">quota.group</tt>for user and group quotas respectively. See <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fstab&sektion=5"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fstab</span>(5)</span></a> for moreinformation. Even though the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=fstab&sektion=5"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fstab</span>(5)</span></a> manual pagesays that you can specify an alternate location for the quota files, this is notrecommended because the various quota utilities do not seem to handle this properly.</p><p>At this point you should reboot your system with your new kernel. <ttclass="FILENAME">/etc/rc</tt> will automatically run the appropriate commands to createthe initial quota files for all of the quotas you enabled in <ttclass="FILENAME">/etc/fstab</tt>, so there is no need to manually create any zero lengthquota files.</p><p>In the normal course of operations you should not be required to run the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=quotacheck&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">quotacheck</span>(8)</span></a>, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=quotaon&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">quotaon</span>(8)</span></a>, or <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=quotaoff&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">quotaoff</span>(8)</span></a> commandsmanually. However, you may want to read their manual pages just to be familiar with theiroperation.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN25614" name="AEN25614">16.14.2 Setting Quota Limits</a></h2><p>Once you have configured your system to enable quotas, verify that they really areenabled. An easy way to do this is to run:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">quota -v</kbd></pre><p>You should see a one line summary of disk usage and current quota limits for each filesystem that quotas are enabled on.</p><p>You are now ready to start assigning quota limits with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=edquota&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">edquota</span>(8)</span></a>command.</p><p>You have several options on how to enforce limits on the amount of disk space a useror group may allocate, and how many files they may create. You may limit allocationsbased on disk space (block quotas) or number of files (inode quotas) or a combination ofboth. Each of these limits are further broken down into two categories: hard and softlimits.</p><p>A hard limit may not be exceeded. Once a user reaches his hard limit he may not makeany further allocations on the file system in question. For example, if the user has ahard limit of 500 blocks on a file system and is currently using 490 blocks, the user canonly allocate an additional 10 blocks. Attempting to allocate an additional 11 blockswill fail.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -