summaryrefslogtreecommitdiff
path: root/sag-0.6.1-www/Invisible/sag-0.6/node46.html
blob: 04e96e11cb8112190c4c83250b6ff287ef29b202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<!--Converted with LaTeX2HTML 96.1-h (September 30, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->
<HTML>
<HEAD>
<TITLE>Mounting and unmounting</TITLE>
<META NAME="description" CONTENT="Mounting and unmounting">
<META NAME="keywords" CONTENT="sag">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<LINK REL=STYLESHEET HREF="sag.css">
</HEAD>
<BODY LANG="EN" >
 <A NAME="tex2html897" HREF="node47.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html895" HREF="node41.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html889" HREF="node45.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html899" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html900" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html898" HREF="node47.html">Checking filesystem integrity with </A>
<B>Up:</B> <A NAME="tex2html896" HREF="node41.html">Filesystems</A>
<B> Previous:</B> <A NAME="tex2html890" HREF="node45.html">Creating a filesystem</A>
<BR> <P>
<H2><A NAME="SECTION00585000000000000000">Mounting and unmounting</A></H2>
<A NAME="subsecmount">&#160;</A>
<P>
	Before one can use a filesystem, it has to be <b>mounted</b>.
	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>
	For example, figure&nbsp;<A HREF="node46.html#fighdmountroot">4.3</A> shows three
	separate filesystems, each with their own root directory.
	When the last two filesystems are mounted below <tt>/home</tt><A NAME="1582">&#160;</A>
	and <tt>/usr</tt><A NAME="1584">&#160;</A>, respectively, on the first filesystem, we
	can get a single directory tree, as in
	figure&nbsp;<A HREF="node46.html#fighdmountall">4.4</A>.
<P>
		<P><A NAME="1230">&#160;</A><A NAME="fighdmountroot">&#160;</A><IMG WIDTH=680 HEIGHT=99 ALIGN=BOTTOM ALT="figure1226" SRC="img7.gif"><BR>
<STRONG>Figure 4.3:</STRONG> Three separate filesystems.<BR>
<P>
<P>
		<P><A NAME="1430">&#160;</A><A NAME="fighdmountall">&#160;</A><IMG WIDTH=371 HEIGHT=185 ALIGN=BOTTOM ALT="figure1233" SRC="img8.gif"><BR>
<STRONG>Figure 4.4:</STRONG> <tt>/home</tt><A NAME="1586">&#160;</A> and <tt>/usr</tt><A NAME="1588">&#160;</A> have been mounted.<BR>
<P>
<P>
	The mounts could be done as in the following example:
		<BLOCKQUOTE> <TT>
<code>$ </code> <I>mount /dev/hda2 /home</I> <BR> 
<code>$ </code> <I>mount /dev/hda3 /usr</I> <BR> 
<code>$ </code>
		</TT></BLOCKQUOTE>
	The <tt>mount</tt><A NAME="1590">&#160;</A> 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>/home</tt><A NAME="1592">&#160;</A>
	and <tt>/usr</tt><A NAME="1594">&#160;</A> directories, respectively.  One would then say that
	``<tt>/dev/hda2</tt><A NAME="1596">&#160;</A> <b>is mounted on</b> <tt>/home</tt><A NAME="1599">&#160;</A>'', and similarly
	for <tt>/usr</tt><A NAME="1601">&#160;</A>.  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>/dev/hda2</tt><A NAME="1603">&#160;</A>, and the
	mounted-on directory, <tt>/home</tt><A NAME="1605">&#160;</A>.  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 <b>mount point</b>.
<P>
	Linux supports many filesystem types.  <tt>mount</tt><A NAME="1608">&#160;</A> tries to
	guess the type of the filesystem.  You can also use the
	<TT>-t <I>fstype</TT></I> option to specify the type directly;
	this is sometimes necessary, since the heuristics <tt>mount</tt><A NAME="1610">&#160;</A>
	uses do not always work.  For example, to mount an MS-DOS
	floppy, you could use the following command:
		<BLOCKQUOTE> <TT>
<code>$ </code> <I>mount -t msdos /dev/fd0 /floppy</I> <BR> 
<code>$ </code>
		</TT></BLOCKQUOTE>
	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>/tmp</tt><A NAME="1612">&#160;</A> and <tt>/var/tmp</tt><A NAME="1614">&#160;</A>
	synonymous, and make <tt>/tmp</tt><A NAME="1616">&#160;</A> be a symbolic link to <tt>/var/tmp</tt><A NAME="1618">&#160;</A>.
	When the system is booted, before the <tt>/usr</tt><A NAME="1620">&#160;</A> filesystem is
	mounted, a <tt>/var/tmp</tt><A NAME="1622">&#160;</A> directory residing on the root filesystem
	is used instead.  When <tt>/usr</tt><A NAME="1624">&#160;</A> is mounted, it will make the
	<tt>/var/tmp</tt><A NAME="1626">&#160;</A> directory on the root filesystem inaccessible.
	If <tt>/var/tmp</tt><A NAME="1628">&#160;</A> didn't exist on the root filesystem, it would
	be impossible to use temporary files before mounting <tt>/var</tt><A NAME="1630">&#160;</A>.
<P>
	If you don't intend to write anything to the filesystem, use
	the <TT>-r</TT> switch for <tt>mount</tt><A NAME="1632">&#160;</A> to do a <b>readonly
	mount</b>.  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-ROM's.
<P>
	The alert reader has already noticed a slight
	logistical problem.  How is the first filesystem (called the <b>root
	filesystem</b>, 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.<A NAME="tex2html22" HREF="footnode.html#1275"><IMG  ALIGN=BOTTOM ALT="gif" SRC="./foot_motif.gif"></A>  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 <tt>rdev</tt><A NAME="1636">&#160;</A>.
<P>
	The root filesystem is usually first mounted readonly.  The
	startup scripts will then run <tt>fsck</tt><A NAME="1638">&#160;</A> to verify its
	validity, and if there are no problems, they will <b>re-mount</b>
	it so that writes will also be allowed.  <tt>fsck</tt><A NAME="1641">&#160;</A> must not
	be run on a mounted filesystem, since any changes to the
	filesystem while <tt>fsck</tt><A NAME="1643">&#160;</A> is running <EM>will</EM> cause
	trouble.  Since the root filesystem
	is mounted readonly while it is being checked, <tt>fsck</tt><A NAME="1645">&#160;</A>
	can fix any problems without worry, since the remount operation
	will flush any metadata that the filesystem keeps in memory.
<P>
	On many systems there are other filesystems that should also
	be mounted automatically at boot time.  These are specified
	in the <tt>/etc/fstab</tt><A NAME="1647">&#160;</A> file; see the <em>fstab</em><A NAME="1649">&#160;</A> 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.  When the chapter on booting
	is finished, you may read all about it there.
<P>
	When a filesystem no longer needs to be mounted, it can be
	unmounted with <tt>umount</tt><A NAME="1651">&#160;</A><A NAME="tex2html23" HREF="footnode.html#1431"><IMG  ALIGN=BOTTOM ALT="gif" SRC="./foot_motif.gif"></A>.  <tt>umount</tt><A NAME="1655">&#160;</A> 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
		<BLOCKQUOTE> <TT>
<code>$ </code> <I>umount /dev/hda2 </I> <BR> 
<code>$ </code> <I>umount /usr</I> <BR> 
<code>$ </code>
		</TT></BLOCKQUOTE>
	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>
	Mounting and unmounting requires super user privileges, i.e.,
	only <tt>root</tt><A NAME="1657">&#160;</A> 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>/bin/sh</tt><A NAME="1659">&#160;</A>, 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:
	<UL>
<LI> Give the users the <tt>root</tt><A NAME="1661">&#160;</A> 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.
<LI> Use a program such as <tt>sudo</tt><A NAME="1663">&#160;</A> to allow users to
		use mount.  This is still bad security, but doesn't
		directly give super user privileges to
		everyone.<A NAME="tex2html21" HREF="footnode.html#1299"><IMG  ALIGN=BOTTOM ALT="gif" SRC="./foot_motif.gif"></A>
<LI> Make the users use <tt>mtools</tt><A NAME="1665">&#160;</A>, 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.
<LI> List the floppy devices and their allowable mount points
		together with the suitable options in <tt>/etc/fstab</tt><A NAME="1667">&#160;</A>.
	</UL>
	The last alternative can be implemented by adding a line like
	the following to the <tt>/etc/fstab</tt><A NAME="1669">&#160;</A> file:
		<BLOCKQUOTE> <TT>
/dev/fd0            /floppy      msdos   user,noauto      0     0
		</TT></BLOCKQUOTE>
	The columns are: device file to mount, directory to mount on,
	filesystem type, options, backup frequency (used by <tt>dump</tt><A NAME="1671">&#160;</A>),
	and <tt>fsck</tt><A NAME="1673">&#160;</A> pass number (to specify the order in which 
	filesystems should be checked upon boot; 0 means no check).
<P>
	The <tt>noauto</tt> option stops this mount to be done
	automatically when the system is started (i.e., it stops
	<tt>mount -a</tt><A NAME="1675">&#160;</A> from mounting it).  The <tt>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 <tt>msdos</tt>
	filesystem with the following command:
		<BLOCKQUOTE> <TT>
<code>$ </code> <I>mount /floppy</I> <BR> 
<code>$ </code>
		</TT></BLOCKQUOTE>
	The floppy can (and needs to, of course) be unmounted with
	the corresponding <tt>umount</tt><A NAME="1677">&#160;</A> command.
<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>/etc/fstab</tt><A NAME="1679">&#160;</A>:
		<BLOCKQUOTE> 
		<PRE>/dev/fd0    /dosfloppy    msdos   user,noauto  0  0
/dev/fd0    /ext2floppy   ext2    user,noauto  0  0</PRE>
		</BLOCKQUOTE>
	For MS-DOS filesystems (not just floppies), you probably want to
	restrict access to it by using the <tt>uid</tt>, <tt>gid</tt>,
	and <tt>umask</tt><A NAME="1681">&#160;</A> filesystem options, described in detail on the
	<em>mount</em><A NAME="1683">&#160;</A> 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>
<HR><A NAME="tex2html897" HREF="node47.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html895" HREF="node41.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html889" HREF="node45.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html899" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html900" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html898" HREF="node47.html">Checking filesystem integrity with </A>
<B>Up:</B> <A NAME="tex2html896" HREF="node41.html">Filesystems</A>
<B> Previous:</B> <A NAME="tex2html890" HREF="node45.html">Creating a filesystem</A>
<P><ADDRESS>
<I>Lars Wirzenius <BR>
Sat Nov 15 02:32:11 EET 1997</I>
</ADDRESS>
</BODY>
</HTML>