756 lines
15 KiB
HTML
756 lines
15 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>/mnt</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Linux Filesystem Hierarchy"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="Linux Filesystem Hierarchy"
|
|
HREF="c23.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="/media"
|
|
HREF="media.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="/opt"
|
|
HREF="opt.html"></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"
|
|
>Linux Filesystem Hierarchy: </TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="media.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 1. Linux Filesystem Hierarchy</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="opt.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="mnt"
|
|
></A
|
|
>1.12. /mnt</H1
|
|
><P
|
|
>This is a generic mount point under which you mount your filesystems
|
|
or devices. Mounting is the process by which you make a filesystem available
|
|
to the system. After mounting your files will be accessible under the
|
|
mount-point. This directory usually contains mount points or sub-directories
|
|
where you mount your floppy and your CD. You can also create additional
|
|
mount-points here if you wish. Standard mount points would include
|
|
/mnt/cdrom and /mnt/floppy. There is no limitation to creating a mount-point
|
|
anywhere on your system but by convention and for sheer practicality do not
|
|
litter your file system with mount-points. It should be noted that some
|
|
distributions like Debian allocate /floppy and /cdrom as mount points while
|
|
Redhat and Mandrake puts them in /mnt/floppy and /mnt/cdrom respectively.</P
|
|
><P
|
|
> However, it should be noted that as of FSSTND version 2.3 the purpose of this
|
|
directory has changed.
|
|
</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> This directory is provided so that the system administrator may temporarily
|
|
mount a filesystem as needed. The content of this directory is a local issue
|
|
and should not affect the manner in which any program is run.
|
|
|
|
This directory must not be used by installation programs: a suitable temporary
|
|
directory not in use by the system must be used instead.
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="mount-and-umount"
|
|
></A
|
|
>1.12.1. Mounting and unmounting</H2
|
|
><P
|
|
>Before one can use a filesystem, it has to be <I
|
|
CLASS="glossterm"
|
|
>mounted</I
|
|
>.
|
|
The operating system then does various bookkeeping things to make sure that
|
|
everything works. Since all files in UNIX are in a single directory tree,
|
|
the mount operation will make it look like the contents of the new
|
|
filesystem are the contents of an existing subdirectory in some already
|
|
mounted filesystem.</P
|
|
><P
|
|
>The mounts could be done as in the
|
|
following example:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>mount /dev/hda2 /home</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>mount /dev/hda3 /usr</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
>
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
The <B
|
|
CLASS="command"
|
|
>mount</B
|
|
> command takes two
|
|
arguments. The first one is the device file corresponding to the disk or
|
|
partition containing the filesystem. The second one is the directory below
|
|
which it will be mounted. After these commands the contents of the two
|
|
filesystems look just like the contents of the <TT
|
|
CLASS="filename"
|
|
>/home</TT
|
|
>
|
|
and <TT
|
|
CLASS="filename"
|
|
>/usr</TT
|
|
> directories, respectively. One would then say
|
|
that ``<TT
|
|
CLASS="filename"
|
|
>/dev/hda2</TT
|
|
> <I
|
|
CLASS="glossterm"
|
|
>is mounted on</I
|
|
>
|
|
<TT
|
|
CLASS="filename"
|
|
>/home</TT
|
|
>'', and similarly for
|
|
<TT
|
|
CLASS="filename"
|
|
>/usr</TT
|
|
>. To look at either filesystem, one would look at
|
|
the contents of the directory on which it has been mounted, just as if it
|
|
were any other directory. Note the difference between the device file,
|
|
<TT
|
|
CLASS="filename"
|
|
>/dev/hda2</TT
|
|
>, and the mounted-on directory,
|
|
<TT
|
|
CLASS="filename"
|
|
>/home</TT
|
|
>. The device file gives access to the raw contents
|
|
of the disk, the mounted-on directory gives access to the files on the disk.
|
|
The mounted-on directory is called the <I
|
|
CLASS="glossterm"
|
|
>mount point</I
|
|
>.</P
|
|
><P
|
|
>Linux supports many filesystem types. <B
|
|
CLASS="command"
|
|
>mount</B
|
|
> tries
|
|
to guess the type of the filesystem. You can also use the <TT
|
|
CLASS="option"
|
|
>-t fstype</TT
|
|
>
|
|
option to specify the type directly; this is sometimes necessary, since the
|
|
heuristics <B
|
|
CLASS="command"
|
|
>mount</B
|
|
> uses do not always work. For example, to
|
|
mount an MS-DOS floppy, you could use the following command: </P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> <TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>mount -t msdos /dev/fd0 /floppy</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
> $</TT
|
|
>
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><P
|
|
>The mounted-on directory need not be empty,
|
|
although it must exist. Any files in it, however, will be inaccessible by
|
|
name while the filesystem is mounted. (Any files that have already been
|
|
opened will still be accessible. Files that have hard links from other
|
|
directories can be accessed using those names.) There is no harm done with
|
|
this, and it can even be useful. For instance, some people like to have
|
|
<TT
|
|
CLASS="filename"
|
|
>/tmp</TT
|
|
> and <TT
|
|
CLASS="filename"
|
|
>/var/tmp</TT
|
|
> synonymous, and
|
|
make <TT
|
|
CLASS="filename"
|
|
>/tmp</TT
|
|
> be a symbolic link to <TT
|
|
CLASS="filename"
|
|
>/var/tmp</TT
|
|
>.
|
|
When the system is booted, before the <TT
|
|
CLASS="filename"
|
|
>/var</TT
|
|
> filesystem
|
|
is mounted, a <TT
|
|
CLASS="filename"
|
|
>/var/tmp</TT
|
|
> directory residing on the root
|
|
filesystem is used instead. When <TT
|
|
CLASS="filename"
|
|
>/var</TT
|
|
> is mounted, it
|
|
will make the <TT
|
|
CLASS="filename"
|
|
>/var/tmp</TT
|
|
> directory on the root filesystem
|
|
inaccessible. If <TT
|
|
CLASS="filename"
|
|
>/var/tmp</TT
|
|
> didn't exist on the root
|
|
filesystem, it would be impossible to use temporary files before mounting
|
|
<TT
|
|
CLASS="filename"
|
|
>/var</TT
|
|
>.</P
|
|
><P
|
|
>If you don't intend to write
|
|
anything to the filesystem, use the <TT
|
|
CLASS="option"
|
|
>-r</TT
|
|
> switch for
|
|
<B
|
|
CLASS="command"
|
|
>mount</B
|
|
> to do a <I
|
|
CLASS="glossterm"
|
|
>read-only mount</I
|
|
>.
|
|
This will make the kernel stop any attempts at writing to the filesystem,
|
|
and will also stop the kernel from updating file access times in the inodes.
|
|
Read-only mounts are necessary for unwritable media, e.g., CD-ROMs.</P
|
|
><P
|
|
>The alert reader has already noticed a slight logistical problem. How
|
|
is the first filesystem (called the <I
|
|
CLASS="glossterm"
|
|
>root filesystem</I
|
|
>,
|
|
because it contains the root directory) mounted, since it obviously
|
|
can't be mounted on another filesystem? Well, the answer is that it is
|
|
done by magic.</P
|
|
><P
|
|
>For more information, see the kernel source or
|
|
the Kernel Hackers' Guide. </P
|
|
><P
|
|
>The root filesystem is
|
|
magically mounted at boot time, and one can rely on it to always be mounted.
|
|
If the root filesystem can't be mounted, the system does not boot. The
|
|
name of the filesystem that is magically mounted as root is either compiled
|
|
into the kernel, or set using LILO or <B
|
|
CLASS="command"
|
|
>rdev</B
|
|
>.</P
|
|
><P
|
|
>The root filesystem is usually first mounted read-only. The startup
|
|
scripts will then run <B
|
|
CLASS="command"
|
|
>fsck</B
|
|
> to verify its validity, and if
|
|
there are no problems, they will <I
|
|
CLASS="glossterm"
|
|
>re-mount</I
|
|
> it so that
|
|
writes will also be allowed. <B
|
|
CLASS="command"
|
|
>fsck</B
|
|
> must not be run on a
|
|
mounted filesystem, since any changes to the filesystem while
|
|
<B
|
|
CLASS="command"
|
|
>fsck</B
|
|
> is running <EM
|
|
>will</EM
|
|
> cause trouble.
|
|
Since the root filesystem is mounted read-only while it is being checked,
|
|
<B
|
|
CLASS="command"
|
|
>fsck</B
|
|
> can fix any problems without worry, since the
|
|
remount operation will flush any metadata that the filesystem keeps in
|
|
memory.</P
|
|
><P
|
|
>On many systems there are other filesystems that should
|
|
also be mounted automatically at boot time. These are specified in the
|
|
<TT
|
|
CLASS="filename"
|
|
>/etc/fstab</TT
|
|
> file; see the fstab man page for details on
|
|
the format. The details of exactly when the extra filesystems are mounted
|
|
depend on many factors, and can be configured by each administrator if need
|
|
be.</P
|
|
><P
|
|
>When a filesystem no longer needs to be mounted, it can be
|
|
unmounted with <B
|
|
CLASS="command"
|
|
>umount</B
|
|
>.</P
|
|
><P
|
|
>It should of course
|
|
be <B
|
|
CLASS="command"
|
|
>unmount</B
|
|
>, but the n mysteriously disappeared in the
|
|
70s, and hasn't been seen since. Please return it to Bell Labs, NJ, if
|
|
you find it.</P
|
|
><P
|
|
><B
|
|
CLASS="command"
|
|
>umount</B
|
|
> takes one argument:
|
|
either the device file or the mount point. For example, to unmount the
|
|
directories of the previous example, one could use the commands</P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> <TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>umount /dev/hda2</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>umount /usr</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
>
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><P
|
|
>See the man page for further instructions on how to use the command.
|
|
It is imperative that you always unmount a mounted floppy.
|
|
<EM
|
|
>Don't just pop the floppy out of the drive!</EM
|
|
> Because
|
|
of disk caching, the data is not necessarily written to the floppy until you
|
|
unmount it, so removing the floppy from the drive too early might cause the
|
|
contents to become garbled. If you only read from the floppy, this is not
|
|
very likely, but if you write, even accidentally, the result may be
|
|
catastrophic.</P
|
|
><P
|
|
>Mounting and unmounting requires super user
|
|
privileges, i.e., only root can do it. The reason for this is that if any
|
|
user can mount a floppy on any directory, then it is rather easy to create a
|
|
floppy with, say, a Trojan horse disguised as <TT
|
|
CLASS="filename"
|
|
>/bin/sh</TT
|
|
>,
|
|
or any other often used program. However, it is often necessary to allow
|
|
users to use floppies, and there are several ways to do this:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>Give the users the root password. This is
|
|
obviously bad security, but is the easiest solution. It works well if there
|
|
is no need for security anyway, which is the case on many non-networked,
|
|
personal systems.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Use a program such as
|
|
<B
|
|
CLASS="command"
|
|
>sudo</B
|
|
> to allow users to use mount. This is still bad
|
|
security, but doesn't directly give super user privileges to everyone.
|
|
<A
|
|
NAME="AEN1131"
|
|
HREF="#FTN.AEN1131"
|
|
><SPAN
|
|
CLASS="footnote"
|
|
>[1]</SPAN
|
|
></A
|
|
> </P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Make the users use <B
|
|
CLASS="command"
|
|
>mtools</B
|
|
>, a package for
|
|
manipulating MS-DOS filesystems, without mounting them. This works well if
|
|
MS-DOS floppies are all that is needed, but is rather awkward otherwise.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>List the floppy devices and their
|
|
allowable mount points together with the suitable options in
|
|
<TT
|
|
CLASS="filename"
|
|
>/etc/fstab</TT
|
|
>.</P
|
|
></LI
|
|
></UL
|
|
>The last
|
|
alternative can be implemented by adding a line like the following to the
|
|
<TT
|
|
CLASS="filename"
|
|
>/etc/fstab</TT
|
|
> file: </P
|
|
><P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> /dev/fd0 /floppy
|
|
msdos user,noauto 0 0
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
></P
|
|
><P
|
|
>The columns are: device file to
|
|
mount, directory to mount on, filesystem type, options, backup frequency
|
|
(used by <B
|
|
CLASS="command"
|
|
>dump</B
|
|
>), and <B
|
|
CLASS="command"
|
|
>fsck</B
|
|
> pass number
|
|
(to specify the order in which filesystems should be checked upon boot; 0
|
|
means no check).</P
|
|
><P
|
|
>The <TT
|
|
CLASS="option"
|
|
>noauto</TT
|
|
> option stops this
|
|
mount to be done automatically when the system is started (i.e., it stops
|
|
<B
|
|
CLASS="command"
|
|
>mount -a</B
|
|
> from mounting it). The <TT
|
|
CLASS="option"
|
|
>user</TT
|
|
>
|
|
option allows any user to mount the filesystem, and, because of security
|
|
reasons, disallows execution of programs (normal or setuid) and
|
|
interpretation of device files from the mounted filesystem. After this, any
|
|
user can mount a floppy with an msdos filesystem with the following command:
|
|
</P
|
|
><P
|
|
> <TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
> <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>mount /floppy</B
|
|
></TT
|
|
>
|
|
<TT
|
|
CLASS="prompt"
|
|
>$</TT
|
|
>
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>The floppy can (and needs to, of course) be
|
|
unmounted with the corresponding <B
|
|
CLASS="command"
|
|
>umount</B
|
|
> command.</P
|
|
><P
|
|
>If you want to provide access to several types of floppies, you need
|
|
to give several mount points. The settings can be different for each mount
|
|
point. For example, to give access to both MS-DOS and ext2 floppies, you
|
|
could have the following to lines in <TT
|
|
CLASS="filename"
|
|
>/etc/fstab</TT
|
|
>:
|
|
</P
|
|
><P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
> /dev/fd0 /dosfloppy msdos user,noauto 0 0 /dev/fd0
|
|
/ext2floppy ext2 user,noauto 0 0
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
></P
|
|
><P
|
|
>For MS-DOS
|
|
filesystems (not just floppies), you probably want to restrict access to it
|
|
by using the <TT
|
|
CLASS="option"
|
|
>uid</TT
|
|
>, <TT
|
|
CLASS="option"
|
|
>gid</TT
|
|
>, and
|
|
<TT
|
|
CLASS="option"
|
|
>umask</TT
|
|
> filesystem options, described in detail on the
|
|
<B
|
|
CLASS="command"
|
|
>mount</B
|
|
> manual page. If you aren't careful, mounting an
|
|
MS-DOS filesystem gives everyone at least read access to the files in it,
|
|
which is not a good idea.</P
|
|
></DIV
|
|
></DIV
|
|
><H3
|
|
CLASS="FOOTNOTES"
|
|
>Notes</H3
|
|
><TABLE
|
|
BORDER="0"
|
|
CLASS="FOOTNOTES"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
ALIGN="LEFT"
|
|
VALIGN="TOP"
|
|
WIDTH="5%"
|
|
><A
|
|
NAME="FTN.AEN1131"
|
|
HREF="mnt.html#AEN1131"
|
|
><SPAN
|
|
CLASS="footnote"
|
|
>[1]</SPAN
|
|
></A
|
|
></TD
|
|
><TD
|
|
ALIGN="LEFT"
|
|
VALIGN="TOP"
|
|
WIDTH="95%"
|
|
><P
|
|
>It requires several seconds of hard thinking on the
|
|
users' behalf. Furthermore <B
|
|
CLASS="command"
|
|
>sudo</B
|
|
> can be configured to
|
|
only allow users to execute certain commands. See the sudo(8), sudoers(5),
|
|
and visudo(8) manual pages. </P
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><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="media.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="opt.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>/media</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c23.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>/opt</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |