📄 mount-unmount.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>Mounting and Unmounting File Systems</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="UNIX Basics" href="basics.html" /><link rel="PREVIOUS" title="Disk Organization" href="x4045.html" /><link rel="NEXT" title="Processes" href="basics-processes.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></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 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="x4045.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 3. UNIX Basics</td><td width="10%" align="right" valign="bottom"><a href="basics-processes.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="MOUNT-UNMOUNT" name="MOUNT-UNMOUNT">3.6. Mounting and UnmountingFile Systems</a></h1><p>The file system is best visualized as a tree, rooted, as it were, at <ttclass="FILENAME">/</tt>. <tt class="FILENAME">/dev</tt>, <tt class="FILENAME">/usr</tt>,and the other directories in the root directory are branches, which may have their ownbranches, such as <tt class="FILENAME">/usr/local</tt>, and so on.</p><p>There are various reasons to house some of these directories on separate file systems.<tt class="FILENAME">/var</tt> contains the directories <tt class="FILENAME">log/</tt>,<tt class="FILENAME">spool/</tt>, and various types of temporary files, and as such, mayget filled up. Filling up the root file system is not a good idea, so splitting <ttclass="FILENAME">/var</tt> from <tt class="FILENAME">/</tt> is often favorable.</p><p>Another common reason to contain certain directory trees on other file systems is ifthey are to be housed on separate physical disks, or are separate virtual disks, such as<a href="network-nfs.html">Network File System</a> mounts, or CDROM drives.</p><div class="SECT2"><h2 class="SECT2"><a id="DISKS-FSTAB" name="DISKS-FSTAB">3.6.1. The <ttclass="FILENAME">fstab</tt> File</a></h2><p>During the <a href="boot.html">boot process</a>, file systems listed in <ttclass="FILENAME">/etc/fstab</tt> are automatically mounted (unless they are listed withthe <var class="OPTION">noauto</var> option).</p><p>The <tt class="FILENAME">/etc/fstab</tt> file contains a list of lines of thefollowing format:</p><pre class="PROGRAMLISTING"><var class="REPLACEABLE">device</var> <varclass="REPLACEABLE">/mount-point</var> <var class="REPLACEABLE">fstype</var> <varclass="REPLACEABLE">options</var> <var class="REPLACEABLE">dumpfreq</var> <varclass="REPLACEABLE">passno</var></pre><div class="VARIABLELIST"><dl><dt><var class="LITERAL">device</var></dt><dd><p>A device name (which should exist), as explained in <ahref="disks-naming.html">Section 12.2</a>.</p></dd><dt><var class="LITERAL">mount-point</var></dt><dd><p>A directory (which should exist), on which to mount the file system.</p></dd><dt><var class="LITERAL">fstype</var></dt><dd><p>The file system type to pass to <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">mount</span>(8)</span>. The default FreeBSD file system is <varclass="LITERAL">ufs</var>.</p></dd><dt><var class="LITERAL">options</var></dt><dd><p>Either <var class="OPTION">rw</var> for read-write file systems, or <varclass="OPTION">ro</var> for read-only file systems, followed by any other options thatmay be needed. A common option is <var class="OPTION">noauto</var> for file systems notnormally mounted during the boot sequence. Other options are listed in the <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span> manual page.</p></dd><dt><var class="LITERAL">dumpfreq</var></dt><dd><p>This is used by <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">dump</span>(8)</span> to determine which file systems requiredumping. If the field is missing, a value of zero is assumed.</p></dd><dt><var class="LITERAL">passno</var></dt><dd><p>This determines the order in which file systems should be checked. File systems thatshould be skipped should have their <var class="LITERAL">passno</var> set to zero. Theroot file system (which needs to be checked before everything else) should have it's <varclass="LITERAL">passno</var> set to one, and other file systems' <varclass="LITERAL">passno</var> should be set to values greater than one. If more than onefile systems have the same <var class="LITERAL">passno</var> then <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">fsck</span>(8)</span> will attempt tocheck file systems in parallel if possible.</p></dd></dl></div></div><div class="SECT2"><h2 class="SECT2"><a id="DISKS-MOUNT" name="DISKS-MOUNT">3.6.2. The <ttclass="COMMAND">mount</tt> Command</a></h2><p>The <span class="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span>command is what is ultimately used to mount file systems.</p><p>In its most basic form, you use:</p><div class="INFORMALEXAMPLE"><a id="AEN4405" name="AEN4405"></a><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mount <varclass="REPLACEABLE">device</var> <var class="REPLACEABLE">mountpoint</var></kbd></pre></div><p>There are plenty of options, as mentioned in the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">mount</span>(8)</span> manual page, but the most common are:</p><div class="VARIABLELIST"><p><b>Mount Options</b></p><dl><dt><var class="OPTION">-a</var></dt><dd><p>Mount all the file systems listed in <tt class="FILENAME">/etc/fstab</tt>. Exceptthose marked as ``noauto'', excluded by the <var class="OPTION">-t</var> flag, or thosethat are already mounted.</p></dd><dt><var class="OPTION">-d</var></dt><dd><p>Do everything except for the actual mount system call. This option is useful inconjunction with the <var class="OPTION">-v</var> flag to determine what <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span> is actuallytrying to do.</p></dd><dt><var class="OPTION">-f</var></dt><dd><p>Force the mount of an unclean file system (dangerous), or forces the revocation ofwrite access when downgrading a file system's mount status from read-write toread-only.</p></dd><dt><var class="OPTION">-r</var></dt><dd><p>Mount the file system read-only. This is identical to using the <varclass="OPTION">rdonly</var> argument to the <var class="OPTION">-o</var> option.</p></dd><dt><var class="OPTION">-t</var> <var class="REPLACEABLE">fstype</var></dt><dd><p>Mount the given file system as the given file system type, or mount only file systemsof the given type, if given the <var class="OPTION">-a</var> option.</p><p>``ufs'' is the default file system type.</p></dd><dt><var class="OPTION">-u</var></dt><dd><p>Update mount options on the file system.</p></dd><dt><var class="OPTION">-v</var></dt><dd><p>Be verbose.</p></dd><dt><var class="OPTION">-w</var></dt><dd><p>Mount the file system read-write.</p></dd></dl></div><p>The <var class="OPTION">-o</var> option takes a comma-separated list of the options,including the following:</p><div class="VARIABLELIST"><dl><dt>nodev</dt><dd><p>Do not interpret special devices on the file system. This is a useful securityoption.</p></dd><dt>noexec</dt><dd><p>Do not allow execution of binaries on this file system. This is also a useful securityoption.</p></dd><dt>nosuid</dt><dd><p>Do not interpret setuid or setgid flags on the file system. This is also a usefulsecurity option.</p></dd></dl></div></div><div class="SECT2"><h2 class="SECT2"><a id="DISKS-UMOUNT" name="DISKS-UMOUNT">3.6.3. The <ttclass="COMMAND">umount</tt> Command</a></h2><p>The <span class="CITEREFENTRY"><span class="REFENTRYTITLE">umount</span>(8)</span>command takes, as a parameter, one of a mountpoint, a device name, or the <varclass="OPTION">-a</var> or <var class="OPTION">-A</var> option.</p><p>All forms take <var class="OPTION">-f</var> to force unmounting, and <varclass="OPTION">-v</var> for verbosity. Be warned that <var class="OPTION">-f</var> is notgenerally a good idea. Forcibly unmounting file systems might crash the computer ordamage data on the file system.</p><p><var class="OPTION">-a</var> and <var class="OPTION">-A</var> are used to unmount allmounted file systems, possibly modified by the file system types listed after <varclass="OPTION">-t</var>. <var class="OPTION">-A</var>, however, does not attempt tounmount the root file system.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="x4045.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="basics-processes.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Disk Organization</td><td width="34%" align="center" valign="top"><a href="basics.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Processes</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -