[Pkg-sysvinit-devel] Processed: Re: Bug#494001: debian-installer: /etc/mtab must be a symlink to /proc/mounts with linux >= 2.6.26

Roger Leigh rleigh at codelibre.net
Wed Mar 18 22:44:12 UTC 2009


On Wed, Mar 18, 2009 at 05:38:38PM -0300, Henrique de Moraes Holschuh wrote:
> Are there other parts of Squeeze that would malfunction with Linux kernels
> older than 2.6.26 ?
> 
> The version check is pretty much a good idea for safety reasons, I think it
> would be better to just leave it in, and we can get rid of it for Squeeze+1.

Agreed.  I've attached a new patch with a version check.  I've now
tested the patch by installing the package, and it correctly updates
the symlink, and also preserves it if already a symlink.  The only
corner case we have here is if the admin already deliberately
symlinked it somewhere else--we won't link it to /proc/mounts in
this case (do we want to trample on the admins changes in this
case?).

I used dpkg --compare-versions, which I hope is OK for kernel revisions.

I haven't explicitly removed /etc/init.d/mtab.sh.  This does not appear
to get removed automatically on upgrade due to being a conffile and dpkg
not removing it automatically.  It probably wants removing in the
postinst as well.


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.
-------------- next part --------------
diff -urN sysvinit-2.86.ds1.original/debian/changelog sysvinit-2.86.ds1/debian/changelog
--- sysvinit-2.86.ds1.original/debian/changelog	2009-03-18 21:51:20.000000000 +0000
+++ sysvinit-2.86.ds1/debian/changelog	2009-03-18 21:52:26.546647443 +0000
@@ -1,3 +1,12 @@
+sysvinit (2.86.ds1-62) unstable; urgency=low
+
+  [ Roger Leigh ]
+  * /etc/init.d/mtab.sh: Remove.
+  * initscripts postinst: Remove mtab.sh.  Symlink /etc/mtab to
+    /proc/mounts on Linux systems (Closes: #494001).
+
+ -- Roger Leigh <rleigh at debian.org>  Wed, 18 Mar 2009 20:01:47 +0000
+
 sysvinit (2.86.ds1-61) unstable; urgency=low
 
   * Fix typo in rcS(5), proberly->properly (Closes: #484233).  Thanks to
diff -urN sysvinit-2.86.ds1.original/debian/initscripts/conffiles sysvinit-2.86.ds1/debian/initscripts/conffiles
--- sysvinit-2.86.ds1.original/debian/initscripts/conffiles	2009-03-18 21:51:20.000000000 +0000
+++ sysvinit-2.86.ds1/debian/initscripts/conffiles	2009-03-18 21:52:26.546647443 +0000
@@ -14,7 +14,6 @@
 /etc/init.d/mountoverflowtmp
 /etc/init.d/mountdevsubfs.sh
 /etc/init.d/mountkernfs.sh
-/etc/init.d/mtab.sh
 /etc/init.d/rc.local
 /etc/init.d/reboot
 /etc/init.d/rmnologin
diff -urN sysvinit-2.86.ds1.original/debian/initscripts/doc/README.Debian sysvinit-2.86.ds1/debian/initscripts/doc/README.Debian
--- sysvinit-2.86.ds1.original/debian/initscripts/doc/README.Debian	2009-03-18 21:51:20.000000000 +0000
+++ sysvinit-2.86.ds1/debian/initscripts/doc/README.Debian	2009-03-18 21:52:26.546647443 +0000
@@ -46,8 +46,8 @@
   sysfs /sys sysfs rw,nosuid,nodev,noexec 0 0
 
 The reason is that the entry in fstab needs to match the entry
-generated by the mountkernfs.sh and mtab.sh scripts.  If it does not,
-the system will complain with this message during boot:
+generated by the mountkernfs.sh script.  If it does not, the system
+will complain with this message during boot:
 
   Will now mount local filesystems:mount: /sys already mounted or /sys busy
   mount: according to mtab, sysfs is already mounted on /sys
diff -urN sysvinit-2.86.ds1.original/debian/initscripts/etc/init.d/mtab.sh sysvinit-2.86.ds1/debian/initscripts/etc/init.d/mtab.sh
--- sysvinit-2.86.ds1.original/debian/initscripts/etc/init.d/mtab.sh	2009-03-18 21:51:20.000000000 +0000
+++ sysvinit-2.86.ds1/debian/initscripts/etc/init.d/mtab.sh	1970-01-01 01:00:00.000000000 +0100
@@ -1,180 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          mtab
-# Required-Start:    checkroot
-# Required-Stop:
-# Default-Start:     S
-# Default-Stop:
-# Short-Description: Update mtab file.
-# Description:       Update the mount program's mtab file after
-#                    all local filesystems have been mounted.
-### END INIT INFO
-
-#
-# The main purpose of this script is to update the mtab file to reflect
-# the fact that virtual filesystems were mounted early on, before mtab
-# was writable.
-#
-
-PATH=/lib/init:/sbin:/bin
-. /lib/init/vars.sh
-
-TTYGRP=5
-TTYMODE=620
-[ -f /etc/default/devpts ] && . /etc/default/devpts
-
-TMPFS_SIZE=
-[ -f /etc/default/tmpfs ] && . /etc/default/tmpfs
-
-KERNEL="$(uname -s)"
-
-. /lib/lsb/init-functions
-. /lib/init/mount-functions.sh
-
-# $1 - fstype
-# $2 - mount point
-# $3 - mount name/device
-# $4 - mount options
-domtab ()
-{
-	# Directory present?
-	if [ ! -d $2 ]
-	then
-		return
-	fi
-
-	# Not mounted?
-	if ! mountpoint -q $2 < /dev/null
-	then
-		return
-	fi
-
-	if [ -n "$3" ]
-	then
-		NAME="$3"
-	else
-		NAME="$1"
-	fi
-
-	# Already recorded?
-	if ! grep -E -sq "^([^ ]+) +$2 +" /etc/mtab < /dev/null
-	then
-		mount -f -t $1 $OPTS $4 $NAME $2 < /dev/null
-	fi
-}
-
-do_start () {
-	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 && which restorecon >/dev/null 2>&1 && [ -r /etc/mtab ]
-	then
-		restorecon /etc/mtab
-	fi
-
-	# S02mountkernfs.sh
-	RW_OPT=
-	[ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE"
-	domtab tmpfs /lib/init/rw tmpfs -omode=0755,nosuid$RW_OPT
-
-	domtab proc /proc "proc" -onodev,noexec,nosuid
-	if grep -E -qs "sysfs\$" /proc/filesystems
-	then
-		domtab sysfs /sys sysfs -onodev,noexec,nosuid
-	fi
-	if [ yes = "$RAMRUN" ] ; then
-		RUN_OPT=
-		[ "${RUN_SIZE:=$TMPFS_SIZE}" ] && RUN_OPT=",size=$RUN_SIZE"
-		domtab tmpfs /var/run "varrun" -omode=0755,nosuid$RUN_OPT
-	fi
-	if [ yes = "$RAMLOCK" ] ; then
-		LOCK_OPT=
-		[ "${LOCK_SIZE:=$TMPFS_SIZE}" ] && LOCK_OPT=",size=$LOCK_SIZE"
-		domtab tmpfs /var/lock "varlock" -omode=1777,nodev,noexec,nosuid$LOCK_OPT
-	fi
-	if [ -d /proc/bus/usb ]
-	then
-		domtab usbfs /proc/bus/usb "procbususb"
-	fi
-
-	# S03udev
-	domtab tmpfs /dev "udev" -omode=0755
-
-	# S04mountdevsubfs
-	SHM_OPT=
-	[ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE"
-	domtab tmpfs /dev/shm tmpfs -onosuid,nodev$SHM_OPT
-	domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
-
-	# Add everything else in /proc/mounts into /etc/mtab, with
-	# special exceptions.
-	exec 9<&0 0</proc/mounts
-	while read FDEV FDIR FTYPE FOPTS REST
-	do
-		case "$FDIR" in
-			/lib/modules/*/volatile)
-				FDEV="lrm"
-				;;
-			/dev/.static/dev)
-				# Not really useful to show in 'df',
-				# and it isn't accessible for non-root
-				# users.
-				continue
-				;;
-		esac
-		domtab "$FTYPE" "$FDIR" "$FDEV" "-o$FOPTS"
-	done
-	exec 0<&9 9<&-
-}
-
-case "$1" in
-  start|"")
-	do_start
-	;;
-  restart|reload|force-reload)
-	echo "Error: argument '$1' not supported" >&2
-	exit 3
-	;;
-  stop)
-	# No-op
-	;;
-  *)
-	echo "Usage: mountall-mtab.sh [start|stop]" >&2
-	exit 3
-	;;
-esac
-
-:
diff -urN sysvinit-2.86.ds1.original/debian/initscripts/postinst sysvinit-2.86.ds1/debian/initscripts/postinst
--- sysvinit-2.86.ds1.original/debian/initscripts/postinst	2009-03-18 21:51:20.000000000 +0000
+++ sysvinit-2.86.ds1/debian/initscripts/postinst	2009-03-18 22:29:50.967071300 +0000
@@ -107,6 +107,15 @@
 	update-rc.d -f sendsigs remove >/dev/null 2>&1 || :
 fi
 
+# In 2.86.ds1-62, the mtab.sh script was removed and /etc/mtab was
+# replaced with a symbolic link to /proc/mounts on Linux.
+if dpkg --compare-versions "$PREV_VER" lt "2.86.ds1-62"
+then
+	update-rc.d -f mtab.sh remove >/dev/null 2>&1 || :
+	update-rc.d -f hostname.sh remove >/dev/null 2>&1 || :
+fi
+
+
 #
 # Okay, we could do this with update-rc.d, but that would probably
 # be pretty slow. This way we win some speed.
@@ -119,7 +128,6 @@
 updatercd mountdevsubfs.sh       start 4 S .
 updatercd bootlogd               start 5 S .
 updatercd checkroot.sh           start 10 S .
-updatercd mtab.sh                start 12 S .
 updatercd checkfs.sh             start 30 S .
 updatercd mountall.sh            start 35 S .
 updatercd mountall-bootclean.sh  start 36 S .
@@ -161,6 +169,24 @@
 done
 
 #
+# In 2.86.ds1-62 the mtab.sh script was removed and /etc/mtab
+# replaced with a symbolic link to /proc/mounts on Linux.
+#
+# The reason for this is that /etc/mtab requires a writable root
+# filesystem, and does not support per-process namespaces.  Since
+# Linux 2.6.26, /proc/mounts contains all the information that
+# /etc/mtab provided (such as extra mount options), and it is a
+# symlink to /proc/self/mounts to support per-process namespaces.
+#
+if [ "$(uname -s)" = "Linux" ] && dpkg --compare-versions "$(uname -r)" ge "2.6.26"
+then
+	if [ -f /etc/mtab ] && [ ! -L /etc/mtab ] && [ -f /proc/mounts ]
+	then
+		rm /etc/mtab && ln -s /proc/mounts /etc/mtab
+	fi
+fi
+
+#
 # Create /var/run and /var/lock on the root partition to make sure
 # they are available when RAMRUN or RAMLOCK is enabled.
 # If mount fail (like in a vserver environment), just clean up and ignore


More information about the Pkg-sysvinit-devel mailing list