tags 494001 + patch
thanks

On Tue, May 12, 2009 at 05:43:28AM +1000, Kel Modderman wrote:
> > Does checkroot.sh need to change at all with respect to what it does to
> > /etc/mtab?
[patch]

I've attached a new patch against the current sources to implement
this.  Note that it only handles migration in one direction, that
it, it will not switch /back/ from a symlink in the absence of
/proc/mounts.  While this could be added, is this a situation we
really need to cater for?

There are no OS checks--this permits kfreebsd support and future
Hurd support.  The logic is in the shell function mtab_migrate
to permit the clean addition of special casing for e.g. Hurd.

This patch, like /dev/shm → /run/shm and /etc/network/ifstate →
/run/network/ifstate, does not preserve symlinks to places other
than /proc/* (the assumption being that symlinks to other files
were hacks to permit read-only root but still being static files).
Such hacks are no longer needed.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
>From 36e073fbd1cd02bbc4756c0d4eedda7cd05c745d Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@debian.org>
Date: Sun, 23 Oct 2011 14:45:51 +0100
Subject: [PATCH 1/2] Migrate /etc/mtab to symlink to /proc/mounts when
 possible

---
 debian/src/initscripts/etc/init.d/checkroot.sh     |   15 +++++++
 debian/src/initscripts/etc/init.d/mtab.sh          |   45 +-------------------
 debian/src/initscripts/lib/init/mount-functions.sh |   24 ++++++++++
 3 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/debian/src/initscripts/etc/init.d/checkroot.sh b/debian/src/initscripts/etc/init.d/checkroot.sh
index 2ce59f8..beef8cf 100755
--- a/debian/src/initscripts/etc/init.d/checkroot.sh
+++ b/debian/src/initscripts/etc/init.d/checkroot.sh
@@ -286,6 +286,13 @@ but requested that the system be restarted."
 		mount -n -o remount,$rootopts,$rootmode /
 	fi
 
+	# If possible, migrate /etc/mtab to be a symlink to
+	# /proc/mounts.  Note that not all systems e.g. Hurd currently
+	# support this.
+	if [ "$rootmode" != "ro" ]; then
+		mtab_migrate
+	fi
+
 	#
 	# We only create/modify /etc/mtab if the location where it is
 	# stored is writable. If /etc/mtab is a symlink into /proc/
@@ -295,11 +302,14 @@ but requested that the system be restarted."
 	MTAB_PATH="$(readlink -f /etc/mtab || :)"
 	case "$MTAB_PATH" in
 	  /proc/*)
+		# Assume that /proc/ is not writable (do nothing)
 		;;
 	  /*)
+		# Common case for file or symlink (initialise)
 		if touch "$MTAB_PATH" >/dev/null 2>&1
 		then
 			:> "$MTAB_PATH"
+			chmod 644 /etc/mtab
 			rm -f ${MTAB_PATH}~
 			INIT_MTAB_FILE=yes
 		fi
@@ -318,6 +328,11 @@ but requested that the system be restarted."
 		;;
 	esac
 
+	if selinux_enabled && [ -x /sbin/restorecon ] && [ -r /etc/mtab ]
+	then
+		restorecon /etc/mtab
+	fi
+
 	if [ "$INIT_MTAB_FILE" = yes ]
 	then
 		[ "$roottype" != none ] &&
diff --git a/debian/src/initscripts/etc/init.d/mtab.sh b/debian/src/initscripts/etc/init.d/mtab.sh
index 65ad2d2..0be7f96 100644
--- a/debian/src/initscripts/etc/init.d/mtab.sh
+++ b/debian/src/initscripts/etc/init.d/mtab.sh
@@ -30,49 +30,8 @@ KERNEL="$(uname -s)"
 . /lib/init/mount-functions.sh
 
 do_start () {
-	# Needed to determine if root is being mounted read-only.
-	read_fstab
-
-	DO_MTAB=""
-	MTAB_PATH="$(readlink -f /etc/mtab || :)"
-	case "$MTAB_PATH" in
-	  /proc/*)
-		# Assume that /proc/ is not writable
-		;;
-	  /*)
-		# Only update mtab if it is known to be writable
-		# Note that the touch program is in /usr/bin
-		#if ! touch "$MTAB_PATH" >/dev/null 2>&1
-		#then
-		#	return
-		#fi
-		;;
-	  "")
-		[ -L /etc/mtab ] && MTAB_PATH="$(readlink /etc/mtab)"
-		if [ "$MTAB_PATH" ]
-		then
-			log_failure_msg "Cannot initialize ${MTAB_PATH}."
-		else
-			log_failure_msg "Cannot initialize /etc/mtab."
-		fi
-		;;
-	  *)
-		log_failure_msg "Illegal mtab location '${MTAB_PATH}'."
-		;;
-	esac
-
-	#
-	# Initialize mtab file if necessary
-	#
-	if [ ! -f /etc/mtab ]
-	then
-		:> /etc/mtab
-		chmod 644 /etc/mtab
-	fi
-	if selinux_enabled && [ -x /sbin/restorecon ] && [ -r /etc/mtab ]
-	then
-		restorecon /etc/mtab
-	fi
+	# Note that mtab should have been previously initialised by
+	# checkroot.sh.
 
 	# Add entries for mounts created in early boot
 	# S01mountkernfs.sh
diff --git a/debian/src/initscripts/lib/init/mount-functions.sh b/debian/src/initscripts/lib/init/mount-functions.sh
index 3c97ed5..019b9de 100644
--- a/debian/src/initscripts/lib/init/mount-functions.sh
+++ b/debian/src/initscripts/lib/init/mount-functions.sh
@@ -336,6 +336,30 @@ run_migrate ()
 }
 
 #
+# Migrate /etc/mtab to a compatibility symlink
+#
+mtab_migrate ()
+{
+	# Don't symlink if /proc/mounts does not exist.
+	if [ ! -r "/proc/mounts" ]; then
+		return 1
+	fi
+
+	# Create symlink if not already present.
+	if [ -L "/etc/mtab" ] && [ "$(readlink "/etc/mtab")" = "/proc/mounts" ]; then
+		:
+	else
+		log_warning_msg "Creating compatibility symlink from /etc/mtab to /proc/mounts."
+
+		rm -f "/etc/mtab" || return 1
+		ln -fs "/proc/mounts" "/etc/mtab" || return 1
+		[ -x /sbin/restorecon ] && /sbin/restorecon "/etc/mtab"
+	fi
+
+	return 0
+}
+
+#
 # For compatibility, create /var/run and /var/lock symlinks to /run
 # and /run/lock, respectively.
 #
-- 
1.7.7

>From 27bd8d918e68f8a1ef5d480613e16c92f3973c3d Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@debian.org>
Date: Sun, 23 Oct 2011 15:15:51 +0100
Subject: [PATCH 2/2] Close #494001

---
 debian/changelog |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index fee3db6..7b08ddf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,14 @@
 sysvinit (2.88dsf-14) UNRELEASED; urgency=low
 
+  [ Kel Modderman ]
   * Add support for s390x, thanks to Aurelien Jarno <aure...@debian.org>.
     (Closes: #641107) 
 
+  [ Roger Leigh ]
+  * Make /etc/mtab a symlink to /proc/mounts. (Closes: #494001)
+    Note that this is only done when the root filesystem is writable
+    and /proc/mount is readable.
+
  -- Kel Modderman <k...@otaku42.de>  Sun, 11 Sep 2011 09:39:40 +1000
 
 sysvinit (2.88dsf-13.11) unstable; urgency=low
-- 
1.7.7

Reply via email to