0198-0200.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 333 行
HTML
333 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Filesystems, Disks, and Other Devices</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=11 //-->
<!-- PAGES=0195-0228 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0195-0197.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0201-0203.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-198"><P>Page 198</P></A>
<P>Many different filesystems are supported by Linux;
the ext2 filesystem is used most because it is designed for Linux and is very efficient. Other filesystems are used for compatibility
with other systems; for example, it's common to use the
msdos and vfat filesystems on floppies. (These are the native filesystems of MS-DOS and Windows 95.) Under Red Hat Linux 4.2,
some filesystems are built into the kernel:
</P>
<!-- CODE SNIP //-->
<PRE>
$ cat /proc/filesystems
ext2
msdos
nodev proc
</PRE>
<!-- END CODE SNIP //-->
<P>And some filesystems are available as loadable modules:
</P>
<!-- CODE SNIP //-->
<PRE>
$ ls /lib/modules/`uname -r`/fs
ext.o isofs.o ncpfs.o smbfs.o ufs.o vfat.o
hpfs.o minix.o nfs.o sysv.o umsdos.o xiafs.o
</PRE>
<!-- END CODE SNIP //-->
<P>Some of these (nfs, ncpfs, and smbfs) are network filesystems that don't depend on block
devices. Network filesystems are covered in Chapter 13, "TCP/IP Network Management."
There are more filesystems that are supported by Linux but not provided by the standard kernel
(for example, NTFS).
</P>
<H3><A NAME="ch11_ 5">
The mount Command
</A></H3>
<P>To mount a block device into the filesystem, use the
mount command. You need to specify what device contains the filesystem, what type it is, and where in the directory hierarchy
to mount it.
</P>
<P>A mount command looks like this:
</P>
<!-- CODE SNIP //-->
<PRE>
mount [-t type] [-o options] device mount-point
</PRE>
<!-- END CODE SNIP //-->
<P>device must be a block device, or, if it contains a colon, it can be the name of another
machine from which to mount a filesystem (see Chapter 13).
mount-point should be an existing directory; the filesystem will appear at this position. (Anything previously in that directory will be
hidden.) The filesystem type and options are optional, and the variety and meaning of options
depend on the type of filesystem being mounted. If the filesystem you want to mount is specified
in the /etc/fstab file, you need to specify only the mount point or the device name; the
other details will be read from /etc/fstab by
mount. Here is an example of the mount command
being used:
</P>
<!-- CODE //-->
<PRE>
# mount /dev/fd1 -t vfat /mnt/floppy
mount: block device /dev/fd1 is write-protected, mounting read-only
# ls /mnt/floppy
grub-0.4.tar.gz
# umount /mnt/floppy
# ls /mnt/floppy
filesystem not mounted
</PRE>
<!-- END CODE //-->
<P>In this example, I mounted a floppy containing a
vfat filesystem at the mount point /mnt/floppy (and got an informational message). The directory
/mnt/floppy already existed. I used
</P>
<A NAME="PAGENUM-199"><P>Page 199</P></A>
<P>
ls to see what was on the disk and unmounted it again. I then ran
ls again and the response I got was simply the name of a file that I leave in the directory
/mnt/floppy on my hard disk to remind me that there currently is nothing mounted there. This enables me to distinguish
this from having an empty floppy mounted.
</P>
<P>Mounting a vfat floppy like this caused the Linux kernel to
automatically load the vfat driver into the kernel while it was needed. These drivers are loaded by the system daemon
kerneld, and when they become unused after the filesystem is unmounted, they are unloaded to
recover the memory that they occupied. See Chapter 5, "Configuring and Building Kernels," for
more information about kernel modules.
</P>
<P>Any one of several things can cause the mount command to fail. It is possible to specify an
incorrect device name (that is, a device file that does not exist or one for which a driver is
not available in the kernel or for which the hardware is not present). Other error conditions
include unreadable devices (for example, empty floppy drives or bad media) and
insufficient permissions (mount commands other than those sanctioned by the administrator by listing
them with the option user in /etc/fstab are forbidden to ordinary users). Trying to mount a
device at a mount point that does not already exist will also not work. Still more error conditions
are possible but unlikely (for example, exceeding the compiled-in limit to the number of
mounted filesystems) or self-explanatory (for example, most usage errors for the
mount command itself). There are some more unlikely error messages that chiefly relate to the loopback devices.
</P>
<P>In order to mount a filesystem, the point at which it is to be mounted (that is, the mount
point) must be a directory. This directory doesn't have to be empty, but after the filesystem is
mounted, anything "underneath" it will be inaccessible. Linux provides a
singly rooted filesystem, in contrast to those operating systems that give each filesystem a separate drive letter. Although
this might seem less flexible, it is more flexible, because the size of each block device (that is,
hard disk or whatever) is hidden from programs, and things can be moved around. For example,
if you have some software that expects to be installed in
/opt/umsp, you can install it in
/big-disk/stuff/umsp and make /opt/umsp a symbolic link. There is also no need to edit
a myriad of configuration files that are now using the wrong drive letter after you install a
new disk drive, for example.
</P>
<P>There are many options governing how a mounted filesystem behaves; for example, it can
be mounted read-only. There are options for filesystems such as
msdos that don't have any concept of users. The filesystems enable you to give each file a particular file mode (for security
or to allow access by everyone). When you mount an
nfs filesystem, there is so much flexibility available that the options have a separate manual page
(man nfs), although the defaults are perfectly reasonable. The
nfs filesystem is explained in more detail in Chapter 13.
</P>
<P>Table 11.1 contains options useful for mount, given in alphabetical order. Unless
otherwise indicated, these options are valid for all filesystem types, although asking for asynchronous
writes to a CD-ROM is no use! Options applicable only to NFS filesystems are not listed here;
refer to the nfs manual page for those.
</P>
<A NAME="PAGENUM-200"><P>Page 200</P></A>
<P>Table 11.1. mount options.</P>
<TABLE WIDTH="360">
<TR><TD>
mount <B>Option</B>
</TD><TD>
<B>Description</B>
</TD></TR>
<TR><TD>
async
</TD><TD>
Write requests for the filesystem normally should wait until
the data has reached the hardware; with this option, the
program continues immediately instead. This does mean that the system
is slightly more prone to data loss in the event of a system
crash, but, on the other hand, crashes are very rare with Linux.
This option speeds up NFS filesystems by a startling extent.
The opposite of this option is sync.
</TD></TR>
<TR><TD>
auto
</TD><TD>
Indicates to mount that it should mount the device when given
the -a flag. This flag is used by the startup scripts to make sure
that all the required filesystems are mounted at boot time.
The opposite of this option is noauto.
</TD></TR>
<TR><TD>
defaults
</TD><TD>
Turns on the options rw, suid, dev,
exec, auto, nouser, and async.
</TD></TR>
<TR><TD>
dev
</TD><TD>
Allows device nodes on the system to be used. Access to devices
is completely determined by access rights to the on-disk
device node. Hence, if you mount an ext2 filesystem on a floppy
and you have previously placed a writable
/dev/kmem device file on the disk, then you've just gained read/write access to kernel
memory. System administrators generally prevent this from happening
by mounting removable filesystems with the nodev
mount option.
</TD></TR>
<TR><TD>
exec
</TD><TD>
Indicates to the kernel that it should allow the execution
of programs on the filesystem. This option is more frequently
seen as noexec, which indicates to the kernel that execution of
programs on this filesystem shouldn't be allowed. This is
generally used as a security precaution or for NFS filesystems
mounted from another machine that contain executable files of a
format unsuitable for this machine (for example, being intended for
a different CPU).
</TD></TR>
<TR><TD>
noauto
</TD><TD>
Opposite of auto; see above.
</TD></TR>
<TR><TD>
nodev
</TD><TD>
Opposite of dev; see above.
</TD></TR>
<TR><TD>
noexec
</TD><TD>
Opposite of exec; see above.
</TD></TR>
<TR><TD>
nosuid
</TD><TD>
Opposite of suid; see below.
</TD></TR>
<TR><TD>
nouser
</TD><TD>
Opposite of user; see below.
</TD></TR>
</TABLE>
<P><CENTER>
<a href="0195-0197.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0201-0203.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?