1 TITLE: How to get rid of the /etc/mtab -> /proc/mounts symlink
2 LFS VERSION: LFS-3.2-RC1 to LFS CVS 2003-02-02 (pre LFS 4.1)
3 AUTHOR: Oliver Brakmann <obrakmann@gmx.net>
5 LAST CHANGES: 2003-02-27: Moved to old/
6 2003-01-02: Minor stylistic changes
7 2003-01-02: Added a note for glibc 2.3.1 users
8 2002-11-14: Minor stylistic changes (thanks to DJ Lucas)
9 2002-08-06: Restructured the whole hint
10 2002-08-04: Corrected a few technical details
11 2002-08-04: Minor stylistic changes
12 2002-07-30: Added a note for those who do not want to
14 2002-07-30: rephrased some parts to prevent misunderstanding
15 2002-07-29: fixed a couple of typos
18 A default LFS install sets up /etc/mtab as a symlink to /proc/mounts,
19 which breaks (u)mount's behaviour. This hints tells you how to
20 solve this problem elegantly, even on a read-only root partition.
24 !! Important note: Since 2003-02-03, the LFS Book uses a real /etc/mtab
25 file again. The first public release including that change will be
26 LFS 4.1. Because of that, this hint has become obsolete in parts.
27 For an mtab hint that applies to recent LFS versions, take a look at
28 the new hint at <http://hints.linuxfromscratch.org>.
44 This hint really covers two issues:
45 1. getting rid of that annoying symlink
46 2. doing so on a read-only root partition.
48 Because the instructions to achieve the second goal (discussed in chapter 4)
49 include those from chapter 3, albeit in slightly modified form, you will find
50 that a lot of information is more or less duplicated in this hint. I did not
51 know how to solve this any other way without this hint becoming way too
54 OK, as a final note before we begin: keep in mind that I take no responsibility
55 whatsoever for any damage done to your computer. Be careful doing this, you
56 might badly screw your system.
62 If /etc/mtab is a link to /proc/mounts, the following issues with the
63 mount/umount programs show up:
65 - the fstab `user' option does not work
66 (you have to specify `users' as a workaround)
67 - loop devices are not freed properly when unmounting
68 (you have to use `umount -d' or run `losetup -d' manually)
69 - certain kernel versions under certain circumstances list /dev/root
70 instead of the real root device in /proc/mounts.
72 The reasons one might want to have /etc/mtab as a link to /proc/mounts
75 - if, for some reason, the system crashes and you have to do
76 a hard reboot, /etc/mtab will not contain inconsistent data upon
78 - you can mount your root partition read-only.
80 However, those two points can also be dealt with without the need for
87 Follow these instructions if your / and /var directories are on the same
88 partition. If they are not, but your / is writeable nevertheless, go to
89 chapter 4 anyway. If you want to have a read-only / one day, you do not
90 need to start all over again with this.
93 1. Switch to single-user mode
101 Be careful: from this point on, you lose all information about the
102 currently mounted filesystems (that umount can work with, at least)!
103 If you have any filesystems mounted that do not get mounted at boot-
104 time (ie. by the /etc/rc.d/init.d/mountfs script), unmount them
105 _before_ this step! If you are not sure what you have mounted, you
106 can still take a look at /proc/mounts.
108 3. Create an empty /etc/mtab
111 # chown root:root /etc/mtab
112 # chmod 644 /etc/mtab
114 4. Now you have to modify your init scripts so that they basically
117 1. mount -n /proc # this is in /etc/rc.d/init.d/mountproc
118 2. fsck # this is in /etc/rc.d/init.d/checkfs
119 3. remount -n / rw # so that we can write to /
120 4. > /etc/mtab # clear /etc/mtab
121 5. mount -f / # update mtab with the already
122 6. mount -f /proc # mounted partitions.
123 7. mount -a # mount all remaining partitions
126 The first step requires a change in /etc/rc.d/init.d/mountproc,
127 whereas the second one does not require any changes.
128 The remainder is handled in /etc/rc.d/init.d/mountfs:
130 ,---[ /etc/rc.d/init.d/mountfs ]------->8--------------------------------------
132 # Begin $rc_base/init.d/mountfs - File System Mount Script
134 # Based on mountfs script from LFS-3.1 and earlier.
135 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
137 source /etc/sysconfig/rc
142 echo "Remounting root file system in read-write mode..."
143 mount -n -o remount,rw /
146 echo "Cleaning /etc/mtab..."
148 mount -f -o remount,rw / &&
152 # The following mount command will mount all file systems. If
153 # you have other (network based) file system that should not
154 # be or cannot be mounted at this time, add them to the NO_FS
155 # variable below. All file systems that are added to the
156 # variable in the form of no<filesystem> will be skipped.
158 NO_FS="nonfs,nosmbfs,noproc"
159 echo "Mounting remaining file systems..."
164 [...remainder of the script omitted...]
165 `-------------------------------------->8--------------------------------------
167 If you use another set of init scripts, you are surely competent
168 enough to know how to implement these changes in your scripts.
170 5. Modify your /etc/fstab so that /proc does not get mounted by
173 proc /proc proc noauto 0 0
175 The important part here is the `noauto' keyword.
176 While this has nothing to do with the task at hand and is not
177 really necessary with the lfs-bootscripts, it is good to have
178 though, in case you ever run `mount -a' from outside of any
179 bootscripts (like in the following step :-).
181 6. If you have not unmounted any other partitions during the process,
182 all those listed in /etc/fstab should still be mounted. Check out
183 /proc/mounts to be sure. The userland tools do not know all this
184 anymore, so we have to tell them:
190 Be sure that /etc/mtab and /proc/mounts contain consistent data
193 7. You can telinit back to your favourite runlevel now. Enjoy!
200 Follow these instructions if you have your / and /var directories on
204 1. Switch to single-user mode
208 2. Remount / read-write
210 # mount -o remount,rw /
212 3. Rebuild glibc with the following patch applied:
213 (or just do the change by hand, which is probably faster *g*)
215 Please note that this patch works with both glibc 2.2.5 and 2.3.1.
217 ,---[ glibc.mtab-patch ]--------------->8--------------------------------------
218 diff -Naur glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h.orig glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h
219 --- glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h.orig 2000-11-16 00:06:47.000000000 +0100
220 +++ glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h 2003-01-02 13:37:12.000000000 +0100
222 #define _PATH_MAN "/usr/share/man"
223 #define _PATH_MEM "/dev/mem"
224 #define _PATH_MNTTAB "/etc/fstab"
225 -#define _PATH_MOUNTED "/etc/mtab"
226 +#define _PATH_MOUNTED "/var/lib/misc/mtab"
227 #define _PATH_NOLOGIN "/etc/nologin"
228 #define _PATH_PRESERVE "/var/lib"
229 #define _PATH_RWHODIR "/var/spool/rwho"
230 `-------------------------------------->8--------------------------------------
232 Look up the installation instructions for glibc in the LFS Book.
234 This patch makes newly compiled programs look for the mtab file
235 in /var/lib/misc/mtab.
241 5. Create /var/lib/misc/mtab. This file should contain only
242 one line that lists your root partition mounted read-only.
243 On my system, using devfs, it looked like this:
245 # mkdir -p /var/lib/misc
246 # echo "/dev/discs/disc0/part2 / ext3 ro 0 0" > /var/lib/misc/mtab
247 # chown root:root /var/lib/misc/mtab
248 # chmod 644 /var/lib/misc/mtab
250 Substitute your root device and file system according to your setup.
252 6. To prevent scripts and broken code from failing, create
253 /etc/mtab as a link to /var/lib/misc/mtab
255 # ln -sf ../var/lib/misc/mtab /etc/mtab
257 Be careful: from this point on, you lose all information about the
258 currently mounted filesystems (that umount can work with, at least)!
259 If you have any filesystems mounted that do not get mounted at boot-
260 time (ie. by the /etc/rc.d/init.d/mountfs script), unmount them
261 _before_ this step! If you are not sure what you have mounted, you
262 can still take a look at /proc/mounts.
264 7. At this point you have to mount /var again
268 8. Create an empty /var/lib/misc/mtab
270 # touch /var/lib/misc/mtab
271 # chown root:root /var/lib/misc/mtab
272 # chmod 644 /var/lib/misc/mtab
274 9. Now you have to modify your init scripts so that they basically
277 1. mount -n /proc # this is in /etc/rc.d/init.d/mountproc
278 2. fsck # this is in /etc/rc.d/init.d/checkfs
279 3. mount -n /var # so that /var/lib/misc/mtab shows up
280 4. > /var/lib/misc/mtab # clear /var/lib/misc/mtab
281 5. mount -f / # update mtab with the already
282 6. mount -f /proc # mounted partitions.
284 8. mount -a # mount all remaining partitions
286 The first step requires a change in /etc/rc.d/init.d/mountproc,
287 whereas the second one does not require any changes.
288 The remainder is handled in /etc/rc.d/init.d/mountfs:
290 ,---[ /etc/rc.d/init.d/mountfs ]------->8--------------------------------------
292 # Begin $rc_base/init.d/mountfs - File System Mount Script
294 # Based on mountfs script from LFS-3.1 and earlier.
295 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
297 source /etc/sysconfig/rc
302 # Uncomment the following three lines if you do not have
303 # a read only root filesystem.
305 # echo "Remounting root file system in read-write mode..."
306 # mount -n -o remount,rw /
309 echo "Cleaning /var/lib/misc/mtab..."
311 > /var/lib/misc/mtab &&
317 # The following mount command will mount all file systems. If
318 # you have other (network based) file system that should not
319 # be or cannot be mounted at this time, add them to the NO_FS
320 # variable below. All file systems that are added to the
321 # variable in the form of no<filesystem> will be skipped.
323 NO_FS="nonfs,nosmbfs,noproc"
324 echo "Mounting remaining file systems..."
329 [...remainder of the script omitted...]
330 `-------------------------------------->8--------------------------------------
332 If you use another set of init scripts, you are surely competent
333 enough to know how to implement these changes in your scripts.
335 10. Modify your /etc/fstab so that /proc and /var do not get mounted by
338 /dev/discs/disc0/part7 /var xfs noauto 0 0
339 proc /proc proc noauto 0 0
341 The important part here is the `noauto' keyword.
342 This is, again, what it looks like on my system. Change it
343 so that it fits your system.
344 Note that with the lfs-bootscripts, /proc does not really need
345 the `noauto' option. It is good to have it though, in case you
346 ever run `mount -a' from outside of any bootscripts (like in
347 step 13 :-). So while you are at it...
349 11. Rebuild util-linux so that mount, umount and friends are
350 aware of mtab's new location. There are no patches required,
351 just look up the instructions in the LFS Book.
353 Other packages you might want to rebuild are the GNU fileutils
354 (df) and other programs that might access /etc/mtab.
355 As long as these programs do not write to that file, it is not
356 absolutely required, though. That is why we set up that symlink.
358 12. If you have a read-only root, remount / read-only now, since
359 we are not changing any more files.
361 # mount -n -o remount,ro /
363 13. If you have not unmounted any other partitions during the process,
364 all those listed in /etc/fstab should still be mounted. Check out
365 /proc/mounts to be sure. The userland tools do not know all this
366 anymore, so we have to tell them:
373 Be sure that /etc/mtab and /proc/mounts contain consistent data
376 14. Finally done! You can telinit back to your favourite run-level now.
383 Credits are due to Seth W. Klein for teaching me through the process in the
384 first place and further corrections and suggestions. Also thanks to DJ Lucas,
385 Jesse Tie-Ten-Quee, Richard Lightman and Wouter Vanwalleghem for additional
388 If you have any questions, comments or suggestions regarding this hint, write
389 to me at <obrakmann@gmx.net> or to the blfs-support mailing list.
391 I hope this helps some people out there.