0284-0286.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 387 行
HTML
387 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:TCP/IP Network Management</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=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=13 //-->
<!-- PAGES=0243-0298 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0281-0283.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0287-0290.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-284"><P>Page 284</P></A>
<P>continued</P>
<TABLE BGCOLOR=#FFFF99><TR><TD></TD></TR><TR><TD><BLOCKQUOTE>
/export, thereby creating /export/usr/local. Because the server itself will need access
to the /export/usr/local directory, a symbolic link from
/usr/local should be created pointing to the real location,
/export/usr/local.
</BLOCKQUOTE></TD></TR></TABLE>
<H4><A NAME="ch13_ 41">
Using mount to Mount an Exported Filesystem
</A></H4>
<P>
To mount a filesystem, use the mount command
</P>
<!-- CODE SNIP //-->
<PRE>
mount servername:/exported/dir /dir/to/mount
</PRE>
<!-- END CODE SNIP //-->
<P>where servername is the name of the server from which you want to mount a filesystem,
/exported/dir is the directory listed in its
/etc/exports file, and /dir/to/mount is the
location on your local machine where you want to mount the filesystem. For example, to
mount /export/home from the NFS server denon to the directory
/home, you would use
</P>
<!-- CODE SNIP //-->
<PRE>
mount denon:/export/home /home
</PRE>
<!-- END CODE SNIP //-->
<P>Remember that the directory must exist in your local filesystem before anything can be
mounted there.
</P>
<P>There are options that can be passed to the
mount command. The most important characteristics are specified in the
-o options. These characteristics are as follows:
</P>
<TABLE WIDTH="360">
<TR><TD>
rw
</TD><TD>
Read/write.
</TD></TR>
<TR><TR>
ro
</TD><TD>
Read-only.
</TD></TR>
<TR><TR>
bg
</TD><TD>
Background mount. Should the mount initially fail (the server
is down, for instance), the mount process will background itself
and continue trying until it is successful. This is useful for
filesystems mounted at boot time because it keeps the system from hanging
at that mount should the server be down.
</TD></TR>
<TR><TR>
intr
</TD><TD>
Interruptible mount. If a process is pending I/O on a
mounted partition, it will allow the process to be interrupted and the I/O
call to be dropped.
</TD></TR>
<TR><TR>
soft
</TD><TD>
By default, NFS operations are "hard," meaning that they
require the server to acknowledge completion before returning to the
calling process. The soft option allows the NFS client to return a failure
to the calling process after retrans number of retries.
</TD></TR>
<TR><TR>
retrans
</TD><TD>
Specifies the maximum number of retried transmissions to a
soft-mounted filesystem.
</TD></TR>
</TABLE>
<P>Here's an example of these parameters in use:
</P>
<!-- CODE SNIP //-->
<PRE>
mount -o rw,bg,intr,soft,retrans=6 denon:/export/home /home
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-285"><P>Page 285</P></A>
<P>To unmount the filesystem, use the umount command—for example,
</P>
<!-- CODE SNIP //-->
<PRE>
umount /home
</PRE>
<!-- END CODE SNIP //-->
<P>This will unmount the /home filesystem.
</P>
<P>There is, of course, a caveat. If users are using files on a mounted filesystem, you
cannot unmount it. All files must be closed before this can happen, which on a large system can be tricky, to
say the least. There are three ways to handle this:
</P>
<UL>
<LI> Use the
lsof program (available at
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof) to list the users and their open files on a given filesystem. Then either wait until they
are done, beg and plead for them to leave, or kill their processes off. Then unmount
the filesystem. Often, this isn't very desirable.
<LI> Use
umount with the -f option to force the filesystem to unmount. This
is often a bad idea as it will leave the programs (and users) accessing the filesystem confused.
Files that are in memory that have not been committed to disk might be lost.
<LI> Bring the system to single-user mode and then unmount the filesystem. Although
this is the largest inconvenience, it is the safest way because no one loses any
work.
</UL>
<H4><A NAME="ch13_ 42">
Configuring the /etc/fstab File to Mount Filesystems Automatically
</A></H4>
<P>At boot time, the system will automatically mount the root filesystem with read-only
privileges. This will allow it to load the kernel and read critical startup files. However, after the
system has bootstrapped itself, it will need guidance. Although it is possible for you to jump
in and mount all the filesystems, it isn't realistic because you would then have to
finish bootstrapping the machine yourself and worse, the system could not come back online by
itself. (Of course, if you enjoy coming into work at 2 a.m. to bring a system back up…)
</P>
<P>To get around this, Linux uses a special file called
/etc/fstab. This file lists all the partitions that need to be mounted at boot time and the directory where they need to be mounted.
Along with that information, you can pass parameters to the
mount command.
</P>
<P>
<P>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
NOTE
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
NFS servers can also be NFS clients. For example, a Web server that exports part of
its archive to, say, an FTP server, can NFS mount from the server containing home
directories at the same time.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>Each filesystem to be mounted is listed in the
fstab file in the following format:
</P>
<!-- CODE SNIP //-->
<PRE>
/dev/device /dir/to/mount ftype parameters fs_freq fs_passno<BR>
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-286"><P>Page 286</P></A>
<P>The following make up this line:</P>
<TABLE WIDTH="360">
<TR><TD>
/dev/device
</TD><TD>
The device to be mounted. In the case of mounting
NFS filesystems, this comes in the form of
servername:/dir/exported, where servername is the name of the NFS
server, and /dir/exported is the directory that is exported from
the NFS server—for example,
denon:/export/home, where denon is the hostname of your NFS server and
/export/home is the directory that it specified in the
/etc/exports directory as being shared.
</TD></TR>
<TR><TR>
/dir/to/mount
</TD><TD>
The location at which the filesystem should be mounted
on your directory tree.
</TD></TR>
<TR><TR>
ftype
</TD><TD>
ext2 for your local filesystems; however, NFS mounts should use the
nfs filesystem type.
</TD></TR>
<TR><TR>
parameters
</TD><TD>
These are the parameters you passed to
mount by using the
-o option. They follow the same comma-delimited
format. An example entry would look like
rw,intr,bg.
</TD></TR>
<TR><TR>
fs_freq
</TD><TD>
This is used by dump to determine whether a
filesystem needs to be dumped.
</TD></TR>
<TR><TR>
fs_passno
</TD><TD>
This is used by the fsck program to determine the order
to check disks at boot time.
</TD></TR>
</TABLE>
<P>Any lines in the fstab file that start with the pound symbol
(#) are considered comments.
</P>
<P>If you need to mount a new filesystem while the machine is live, you will need to perform
the mount by hand. If you want to have this mount automatically active the next time the
system is rebooted, you should be sure to add it to the
fstab file.
</P>
<P>There are two notable partitions that don't follow the same set of rules as normal
partitions. They are the swap partition and /proc, which use filesystem types
swap and proc, respectively.
</P>
<P>Mounting the swap partition is not done using the
mount command. It is instead managed by the swapon command. In order for a swap partition to be mounted, it needs to be listed in
the fstab file. Once there, use swapon with the -a parameter, followed by the partition on
which you've allocated swap space.
</P>
<P>The /proc filesystem is even stranger because it really isn't a filesystem. It is an interface to
the kernel abstracted into a filesystem format.
</P>
<P><CENTER>
<a href="0281-0283.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0287-0290.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?