574-576.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 117 行

HTML
117
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:System Administration Basics</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=32//-->

<!--PAGES=574-576//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="571-573.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="576-579.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Mounting File Systems</FONT></H3>

<P>File systems are not available until they are mounted onto the Linux main file system. Even hard drives must be mounted, because only the <TT>root</TT> file system is available in the <TT>/</TT> directory until the rest are mounted. The <TT>mount</TT> command is used to mount a file system.</P>

<P>During the boot process, the <TT>mount</TT> command is used from the startup files (such as the <TT>/etc/rc</TT> file or files under the <TT>/etc/rc.d</TT> directory) to mount all the file systems maintained in the file <TT>/etc/fstab</TT>. You can look at the file to see the type of information maintained there. Every file system that is mounted during the boot process has an entry giving its device name, its mount directory (called the mount point), the type of file system it is, and any options that apply.</P>

<P>You can add a new file system from a hard disk, a CD-ROM, a floppy, or any other type of device that provides a file system supported by Linux, using the <TT>mount</TT> command. The format is as follows:</P>

<!-- CODE SNIP //-->

<PRE>

mount <I>filesystem mountpoint</I>

</PRE>

<!-- END CODE SNIP //-->

<P><TT><I>filesystem</I></TT> is the name of the device and <I>mountpoint</I> is where in the Linux file system it should be mounted. For example, if you want to mount a SCSI CD-ROM to the file system as <TT>/usr/cdrom</TT>, issue the following command:</P>

<!-- CODE SNIP //-->

<PRE>

mount /dev/cd0 /usr/cdrom

</PRE>

<!-- END CODE SNIP //-->

<P>The directory <TT>/usr/cdrom</TT> must be created before the command is given, or the <TT>mount</TT> command generates an ambiguous error. You should replace <TT>/dev/cd0</TT> with the name of your CD-ROM device driver (<TT>/dev/cd0</TT> for most non-SCSI CD-ROM drives and <TT>/dev/cd0</TT> for SCSI CD-ROM drives). When the file system is mounted properly, changing to <TT>/usr/cdrom</TT> lets you access all the files on the CD-ROM as if they were part of the normal file system.</P>

<P>If your <TT>/etc/fstab</TT> file doesn&#146;t have any entries in it already, you have to mount the file system with a slightly different syntax:</P>

<!-- CODE SNIP //-->

<PRE>

mount -t fstypefilesystem mountpoint

</PRE>

<!-- END CODE SNIP //-->

<P><TT>fstype</TT> is the type of file system (such as ISO9660, MSDOS, and so on). The rest of the arguments are the same as the example above. The <TT>-t</TT> option is used when the file system to be mounted doesn&#146;t already have an entry in the <TT>/etc/fstab</TT> file.</P>

<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">Mounting a Floppy</FONT></H4>

<P>You can mount a floppy disk with a command similar to the one in the CD-ROM example just discussed. To mount a floppy in the first floppy drive on the directory <TT>/mnt</TT>, issue the following command:</P>

<!-- CODE SNIP //-->

<PRE>

mount /dev/fd0 /mnt

</PRE>

<!-- END CODE SNIP //-->

<P>Most floppy drive device names start with <TT>fd</TT> to make it clear which kind of device they are (just like most hard disks start with <TT>hd</TT>). If the file system is not the default value used by Linux, the type of file system must be specified. For example, to mount a floppy using the <TT>ext2</TT> file system, use the <TT>-t</TT> option of the <TT>mount</TT> command:</P>

<!-- CODE SNIP //-->

<PRE>

mount -t ext2 /dev/fd0 /mnt

</PRE>

<!-- END CODE SNIP //-->

<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Creating a New File System</FONT></H4>

<P>To create a file system on a floppy (so it can be mounted), you should use the utility <TT>mke2fs</TT> or the command <TT>mkdev fs</TT>, depending on the version of Linux. To use <TT>mke2fs</TT>, for example, issue the following command to create a floppy file system on a 1.44MB 3.5-inch disk:</P>

<!-- CODE SNIP //-->

<PRE>

mke2fs /dev/fd0 1440

</PRE>

<!-- END CODE SNIP //-->

<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Unmounting File Systems</FONT></H4>

<P>To detach a mounted file system from your Linux file system, use the <TT>umount</TT> command with the name of the device. For example, to unmount a floppy in <TT>/dev/fd0</TT>, issue the following command:</P>

<!-- CODE SNIP //-->

<PRE>

umount /dev/fd0

</PRE>

<!-- END CODE SNIP //-->

<P>The floppy is removed from the mounted point. Be sure to type <TT>umount</TT> instead of <TT>unmount</TT>!</P>

<P>If you want to remove the current floppy and replace it with another, you can&#146;t simply swap them. The current floppy must be unmounted and then the new one must be mounted. Failure to follow this process can result in corruption or erroneous directory listings.</P>

<H4 ALIGN="LEFT"><A NAME="Heading11"></A><FONT COLOR="#000077">Checking File Systems</FONT></H4>

<P>Every now and again a file might get corrupted or a file system&#146;s inode table might get out of sync with the disk&#146;s contents. For these reasons, it is a good idea to check the file system at regular intervals. Several utilities can check file systems, depending on the version of Linux. The utility <TT>fsck</TT> is available for some systems, while the utility <TT>e2fsck</TT> is designed for Linux&#146;s <TT>ext2fs</TT> file system. Many Linux versions include other utilities such as <TT>xfsck</TT> and <TT>efsfck</TT> for different file systems. In many cases, the <TT>fsck</TT> command is linked to the individual file system versions.</P>

<P>To use <TT>e2fsck</TT> to check a file system, issue the command with the device name and the options <TT>a</TT> (automatically correct errors) and <TT>v</TT> (verbose output):</P>

<!-- CODE SNIP //-->

<PRE>

e2fsck -av /dev/hda1

</PRE>

<!-- END CODE SNIP //-->

<P>This command checks and repairs any problems on the <TT>/dev/hda1</TT> (or whatever device driver you specify) partition. If any corrections are made to a partition, you should reboot the machine as soon as possible to allow the system to resync its tables.</P>

<P>Whenever possible, it is a good idea to unmount the file system before checking it, because this can prevent problems with open files. Of course, you can&#146;t unmount the primary <TT>root</TT> partition while running from it, but you can boot from a boot floppy which contains the check utilities and start them from the floppy.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="571-573.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="576-579.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?