mtab hint

Oliver Brakmann obrakmann at gmx.net
Mon Jul 29 10:36:25 PDT 2002


Hi,

I wrote a hint about dealing with the mtab problems that
came up quite often on the mailings lists in the past few
weeks.

Seth W. Klein told me a month ago that he wanted to do so,
but since as of now he hasn't I decided to give it a go.
I hope it's alright with you, Seth.

Seth, I'd like you to please review this hint for any blatant
errors I may have made. Thanks.

I'd also like to thank you, Seth, for the help you gave me
with this stuff. I wouldn't have known how to do this
without you.

Bye,
Oliver
-- 
/"\   ASCII Ribbon   | Reg. Linux User #198843            http://counter.li.org
\ /    Campaign -    | Reg.  LFS  User  #3082   http://www.linuxfromscratch.org
 x    Against HTML   |
/ \ in mail and news | NP: End of Green - Myra
-------------- next part --------------
TITLE:		mtab
LFS VERSION:	Any
AUTHOR:		Oliver Brakmann <obrakmann at gmx.net>

SYNOPSIS:
	A default LFS install sets up mtab as a symlink to /proc/mounnts,
	which breaks (u)mount's behaviour. This hints tells you how to
	solve this problem elegantly.

HINT:
	If /etc/mtab is a link to /proc/mounts, the following issues with
the mount/umount programs show up:

	- the fstab user option doesn't work
	- loop devices aren't freed properly when umounting
	- there was some talk about a wrong root device listed in /etc/mtab,
	  though I never noticed that. Maybe someone would like to shed
	  some light on this for me.

The reasons one might want to have /etc/mtab as a link to /proc/mounts are
the following:

	- if, for some reason, the system should crash and you have to do
	  a hard reboot, /etc/mtab contains inconsistent data upon the
	  the next boot.
	- you can mount your root partition read-only.

However, those two points can be dealt with without the need for the symlink.



The goal is to have a read-only root partition and an mtab file that isn't
a symlink to somewhere. To achieve this, do the following steps:


	1. switch to single-user mode

		$ telinit 1

	2. re-mount / read-write

		$ mount / -o remount,rw

	3. rebuild glibc with the following patch applied:
	   (or just do the change by hand, which is probably faster *g*)


--- glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h.orig    Sun Jul  7 12:22:31 2002
+++ glibc-2.2.5/sysdeps/unix/sysv/linux/paths.h Sun Jul  7 12:22:53 2002
@@ -51,7 +51,7 @@
#define        _PATH_MAN       "/usr/share/man"
#define        _PATH_MEM       "/dev/mem"
#define        _PATH_MNTTAB    "/etc/fstab"
-#define        _PATH_MOUNTED   "/etc/mtab"
+#define        _PATH_MOUNTED   "/var/lib/misc/mtab"
#define        _PATH_NOLOGIN   "/etc/nologin"
#define        _PATH_PRESERVE  "/var/lib"
#define        _PATH_RWHODIR   "/var/spool/rwho"


	Look up the installation instructions for glibc in the LFS Book.

	This patch makes freshly compiled programs look for the mtab file
	in /var/lib/misc/mtab.

	4. now umount /var

		$ umount /var

	5. create /var/lib/misc/mtab. This file should contain only
	   one line that lists your root partition mounted read-only.
	   On my system, using devfs, it looked like this:

		$ mkdir -p /var/lib/misc
		$ echo "/dev/discs/disc0/part2 / ext3 ro 0 0" > /var/lib/misc/mtab
		$ chown root:root /var/lib/misc/mtab
		$ chmod 644 /var/lib/misc/mtab

	   Substitute your root device and file system according to your setup.

	6. to prevent scripts and broken code from failing, create
	   /etc/mtab as a link to /var/lib/misc/mtab

		$ ln -sf ../var/lib/misc/mtab /etc/mtab

	   Be careful: from this point on, you lose all information about the
	   currently mounted partitions! If you have anything mounted that is
	   not mounted at boot-time (ie. by the /etc/rc.d/init.d/mountfs
	   script), umount it _before_ this step!

	7. at this point you can mount /var again

		$ mount -n /var

	8. create an empty /var/lib/misc/mtab

		$ touch /var/lib/misc/mtab
		$ chown root:root /var/lib/misc/mtab
		$ chmod 644 /var/lib/misc/mtab

	9. now you have to modify your init scripts so that they basically
	   do this:

		1. fsck
		2. mount -n /var	# so that /var/lib/misc/mtab shows up
		3. > /var/lib/misc/mtab # clear /var/lib/misc/mtab
		4. mount -f /		# update mtab with the already
		5. mount -f /var	# mounted partitions.
		6. mount -a		# mount all remaining partitions

	When you're done, it should look like this:

#!/bin/bash
# Begin $rc_base/init.d/mountfs - File System Mount Script

# Based on mountfs script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard at linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
        start)
                mount -n /var
                echo "Clearing /var/lib/misc/mtab..."
                > /var/lib/misc/mtab
                evaluate_retval
                mount -f /
                mount -f /var

                # The following mount command will mount all file systems. If
                # you have other (network based) file system that should not
                # be or cannot be mounted at this time, add them to the NO_FS
                # variable below. All file systems that are added to the
		# variable in the form of no<filesystem> will be skipped.

                NO_FS="nonfs,nosmbfs,noproc"
                echo "Mounting remaining file systems..."
                mount -a -t $NO_FS
                evaluate_retval
                ;;

[...remainder of the script omitted...]


	10. modify your /etc/fstab so that /var doesn't get mounted by
	    mount -a:

		/dev/discs/disc0/part7  /var  xfs  defaults,noauto  0 0

	    The important part here is the 'noauto' keyword.
	    This is, again, what it looks like on my system. Change that
	    line so that it fits your system.

	11. rebuild util-linux so that mount, umount and friends are
	    aware of mtab's new location. There are no patches required,
	    just look up the instructions in the LFS Book.

	12. remount / read-only now, since we're not changing any more files.

		$ mount -n / -o remount,ro

	13. if you haven't umounted any other parititions during the process,
	    all those listed in /etc/fstab should still be mounted.
	    Your system doesn't know that anymore, so we have to tell it
	    about that:

		$ mount -f /
		$ mount -f /var
		$ mount -af


	Finally done! You can telinit back to your favourite run-level now.

OK, as a final note: keep in mind that I take no responsibility whatsoever for
any damage done to your computer. Be careful doing this, you might badly screw
your system. This hint has 13 steps for a reason!


Credits are due to Seth W. Klein for teaching me through the process
in the first place.

If you have any questions, comments or suggestions regarding this hint, write
to me at <obrakmann at gmx.net> or to the blfs-support mailing list.

I hope this helps some people out there.

Oliver Brakmann


More information about the hints mailing list