📄 0311-0312.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Basic System Administration</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311623 //-->
<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->
<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=20 //-->
<!-- PAGES=0291-0312 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0308-0310.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch21/0313-0316.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-311"><P>Page 311</P></A>
<P>want them to play a game.
</P>
<P>There are other restrictions you can put in place. The next section shows you how you
can limit how much of your system's hard drive can be used.
</P>
<H4><A NAME="ch20_ 23">
Setting Disk Quotas
</A></H4>
<P>On large, multiuser systems, disk quotas are not only a way of life, but a necessity.
You can impose disk quotas on your Linux system, and you should, especially if you worry
about your disk space, or if you're afraid the users will create huge files and overrun your
hard drive. You can also use disk quotas as a warning device (and maybe justification for a
new hard drive?). This section explains how to start, set, and stop disk quotas.
</P>
<B>
Quota Manipulation with the quota, quotaon, and
quotaoff Commands</B><BR>
Disk quotas limit the amount of hard drive space in several ways. You can set quotas
for a group of users, by using the GID, or impose limits on individual users. To manage
disk quotas, you'll use some or all of these commands:
</P>
<TABLE>
<TR><TD>
quota
</TD><TD>
To report on disk quotas
</TD></TR><TR><TD>
quotaon
</TD><TD>
To turn on and set disk quotas for users
</TD></TR><TR><TD>
quotaoff
</TD><TD>
To turn off disk quotas for users
</TD></TR><TR><TD>
repquot
</TD><TD>
Also reports on quotas
</TD></TR><TR><TD>
edquota
</TD><TD>
Edits user quotas
</TD></TR><TR><TD>
quotacheck
</TD><TD>
Checks filesystem on quota usage
</TD></TR></TABLE>
<P>This book won't go into all the details of these programs (read the manual pages), but
this section shows you how to set a disk quota for the new user
you created. The first thing you must do is to enable quotas for your Linux filesystem. This involves editing the
filesystem table, fstab, in the /etc/ directory. Be careful! You must make sure you don't make any
other changes, or you could cause boot problems. You have been warned!
</P>
<P>Make sure you're logged in as root, then use your favorite text editor to open the
fstab file, and edit the line containing the entry for your Linux partition, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# <device> <mountpoint> <filesystemtype> <options> <dump> <fsckorder>
/dev/hda3 / ext2 defaults 1 1
</PRE>
<!-- END CODE SNIP //-->
<P>Now add a command and the word usrquota to the word default, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
/dev/hda3 / ext2 defaults,usrquota 1 1
</PRE>
<!-- END CODE SNIP //-->
<P>Save the /etc/fstab file. Next, use the touch command to create a file called
quota.user, and make the file read-write enabled, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# touch /quota.user
# chmod 600 /quota.user
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-312"><P>Page 312</P></A>
<P>After you have done this, reboot your computer by using the
shutdown command with the -r, or restart, option. Log back in as root, and use the
edquota command, found under the /usr/sbin directory, along with the
-u option, to edit quotas for your new user, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# edquota -u cloobie
</PRE>
<!-- END CODE SNIP //-->
<P>The edquota command will read in the user.quota file under your
root, or /, directory. This file is normally a binary file, but
edquota will open the file using the text editor defined in
your EDITOR environment variable. If you don't like the default editor, you can first specify
your own temporarily as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
# EDITOR=/usr/bin/pico;export EDITOR
</PRE>
<!-- END CODE SNIP //-->
<P>This will make the edquota command use the pico text editor. When
edquota runs, you'll end up in your editor with the following text:
</P>
<!-- CODE SNIP //-->
<PRE>
Quotas for user cloobie:
/dev/hda3: blocks in use: 58, limits (soft = 0, hard = 0)
inodes in use: 41, limits (soft = 0, hard = 0)
</PRE>
<!-- END CODE SNIP //-->
<P>Although it is not important to understand all the information here (see Albert M.C.
Tam's mini-HOWTO, Quota, under the
/usr/doc/HOWTO/mini for details), you can easily set both
the maximum number of files and the maximum size of your user's directory. To set limits
to 3_5MB for disk space, and between 500 and 1000 files, use
</P>
<!-- CODE SNIP //-->
<PRE>
Quotas for user cloobie:
/dev/hda3: blocks in use: 58, limits (soft = 3000, hard = 5000)
inodes in use: 41, limits (soft = 500, hard = 1000
</PRE>
<!-- END CODE SNIP //-->
<P>Save the file. Then, as a last step, you must set a grace period using
edquota again, but this time with the -t option. Your new user will be warned if the lower, or "soft," limit
is exceeded, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# edquota -t cloobie
</PRE>
<!-- END CODE SNIP //-->
<P>You can then set the grace-period warnings for either exceeding the number of files or
disk use, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/hda3: block grace period: 1 days, file grace period: 1 days
</PRE>
<!-- END CODE SNIP //-->
<P>If you want to warn your user right away, use a grace period of one day (you can also
use minutes or seconds). Finally, you can use the
quota command to check the new quota, for example:
</P>
<!-- CODE //-->
<PRE>
# quota cloobie
Disk quotas for user cloobie (uid 502):
Filesystem blocks quota limit grace files quota limit grace
/dev/hda3 58 3000 5000 41 500 1000
</PRE>
<!-- END CODE //-->
<P>Using disk quotas may sometimes be necessary. If your disk space is at a premium,
this could be one way to manage your hard drive resources.
</P>
<P><CENTER>
<a href="0308-0310.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="../ch21/0313-0316.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -