OK. Steve stayed up very late last night checking that this worked OK
on x86 and adding some useful logging (allowing for the fact that it
needs to work before syslog is actually started).

We've checked some more stuff today, including testing the matching
finish-install functionality on full installs, and reverting my fancy
inittab seddery to go back to simply appending which is more reliable
and easier to understand. We are now confident that the 'use init'
version is the superior (cleaner and more reliable) approach. 

That's all merged in the attached patches which we reckon are now
ready for general use.

I will do some more testing (to check I've not broken hurd - bsd
doesn't seem to be built at the moment so there is nothing to break),
and of course we are ready to prod it some more if we find this does
actually cause unhelpful behaviour for anyone. I also need to check
the docs which no doubt need a few updates.

I've found a couple of other things whilst poking about in the D-I
entrails. There is plenty of cruft from older ways of doing things,
which of course tends to get ignored if it's not actually breaking
things, largely due to chronic undermanning in D-I land. I'll file
some bugs and patches. None of it is urgent, but worth noting before I
forget.

Wookey
-- 
Principal hats:  Linaro, Debian, Wookware, ARM
http://wookware.org/
diff --git b/debian/changelog a/debian/changelog
index a7c80c3..e23b91e 100644
--- b/debian/changelog
+++ a/debian/changelog
@@ -7,7 +7,11 @@ rootskel (1.127) UNRELEASED; urgency=medium
   [ Holger Wansing ]
   * Remove trailing whitespaces from changelog file, to fix lintian tag.
 
- -- Samuel Thibault <sthiba...@debian.org>  Fri, 08 Feb 2019 01:50:37 +0200
+  [ Wookey ]
+  * Support multiple consoles - Run D-I on all enabled consoles
+  * Rename reopen-console to choose-consoles
+
+ -- Wookey <woo...@debian.org>  Fri, 22 Feb 2019 15:57:39 +0000
 
 rootskel (1.126) unstable; urgency=medium
 
diff --git b/src/etc/inittab-hurd a/src/etc/inittab-hurd
index a7b8a23..eeff7e2 100644
--- b/src/etc/inittab-hurd
+++ a/src/etc/inittab-hurd
@@ -2,10 +2,9 @@
 # busybox init configuration for debian-installer
 
 # main rc script
-::sysinit:/sbin/reopen-console /sbin/debian-installer-startup
+::sysinit:/sbin/choose-consoles /sbin/debian-installer-startup
 
 # main setup program
-::respawn:/sbin/reopen-console /sbin/debian-installer
 
 # convenience shells
 tty2::askfirst:-/bin/sh
diff --git b/src/etc/inittab-kfreebsd a/src/etc/inittab-kfreebsd
index 748f19b..c328548 100644
--- b/src/etc/inittab-kfreebsd
+++ a/src/etc/inittab-kfreebsd
@@ -2,10 +2,9 @@
 # busybox init configuration for debian-installer
 
 # main rc script
-::sysinit:/sbin/reopen-console /sbin/debian-installer-startup
+::sysinit:/sbin/choose-consoles /sbin/debian-installer-startup
 
 # main setup program
-::respawn:/sbin/reopen-console /sbin/debian-installer
 
 # convenience shells
 ttyv1::askfirst:-/bin/sh
diff --git b/src/etc/inittab-linux a/src/etc/inittab-linux
index a7b8a23..d7136e2 100644
--- b/src/etc/inittab-linux
+++ a/src/etc/inittab-linux
@@ -2,10 +2,7 @@
 # busybox init configuration for debian-installer
 
 # main rc script
-::sysinit:/sbin/reopen-console /sbin/debian-installer-startup
-
-# main setup program
-::respawn:/sbin/reopen-console /sbin/debian-installer
+::sysinit:/sbin/choose-consoles /sbin/debian-installer-startup
 
 # convenience shells
 tty2::askfirst:-/bin/sh
@@ -19,3 +16,6 @@ tty4::respawn:/usr/bin/tail -f /var/log/syslog
 
 # re-exec init on receipt of SIGHUP/SIGUSR1
 ::restart:/sbin/init
+
+# main setup program
+# Entries will be added here as the system starts up
diff --git b/src/sbin/Makefile a/src/sbin/Makefile
index dec554e..f1a4f5f 100644
--- b/src/sbin/Makefile
+++ a/src/sbin/Makefile
@@ -8,7 +8,7 @@ files_exec = \
 	debian-installer-startup \
 	shutdown \
 	init:init-$(DEB_HOST_ARCH_OS) \
-	reopen-console:reopen-console-$(DEB_HOST_ARCH_OS) \
+	choose-consoles:choose-consoles-$(DEB_HOST_ARCH_OS) \
 	steal-ctty
 
 ifeq ($(DEB_HOST_ARCH_OS),linux)
diff --git b/src/sbin/reopen-console-hurd a/src/sbin/choose-consoles-hurd
similarity index 61%
rename from src/sbin/reopen-console-hurd
rename to src/sbin/choose-consoles-hurd
index 7f9b54e..bef2b73 100755
--- b/src/sbin/reopen-console-hurd
+++ a/src/sbin/choose-consoles-hurd
@@ -4,9 +4,9 @@
 # corresponding to the console we are actually using.
 
 console=
-if ! [ -f /var/run/console-device ]; then
-	tty > /var/run/console-device
+if ! [ -f /var/run/console-devices ]; then
+	tty > /var/run/console-devices
 fi
 
 # Some other session may have it as ctty. Steal it from them
-exec /sbin/steal-ctty $(cat /var/run/console-device) "$@"
+exec /sbin/steal-ctty $(cat /var/run/console-devices) "$@"
diff --git b/src/sbin/reopen-console-kfreebsd a/src/sbin/choose-consoles-kfreebsd
similarity index 87%
rename from src/sbin/reopen-console-kfreebsd
rename to src/sbin/choose-consoles-kfreebsd
index 6dec149..2dd292a 100755
--- b/src/sbin/reopen-console-kfreebsd
+++ a/src/sbin/choose-consoles-kfreebsd
@@ -4,7 +4,7 @@
 # corresponding to the console we are actually using.
 
 console=
-if ! [ -f /var/run/console-device ]; then
+if ! [ -f /var/run/console-devices ]; then
 	# Get the configure consoles using sysctl
 	#   's#^.*: ##'   : remove the prompt
 	#   's#/.*$##'    : remove unconfigured devices
@@ -41,8 +41,8 @@ if ! [ -f /var/run/console-device ]; then
 		# Still nothing? Default to /dev/console.
 		console="console"
 	fi
-	echo /dev/$console > /var/run/console-device
+	echo /dev/$console > /var/run/console-devices
 fi
 
 # Some other session may have it as ctty. Steal it from them
-exec /sbin/steal-ctty $(cat /var/run/console-device) "$@"
+exec /sbin/steal-ctty $(cat /var/run/console-devices) "$@"
diff --git b/src/sbin/choose-consoles-linux a/src/sbin/choose-consoles-linux
new file mode 100755
index 0000000..a601866
--- /dev/null
+++ a/src/sbin/choose-consoles-linux
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+# First find the enabled consoles from the kernel, noting if one is 'preferred'
+# Record these.
+# Run the startup scripts on the preferred console
+
+# In order to have D-I appear on all consoles, edit the inittab to add one entry
+# for each console, running debian-installer.
+# Finally HUP init so that it runs those installers
+# (but doesn't rerun the sysinit startup stuff, including this script) 
+
+
+NL="
+"
+
+LOGGERUP=0
+LOG_FILE=/var/log/choose-consoles
+
+log() {
+	# In very early startup we don't have syslog. Log to file that
+	# we can flush out later so we can at least see what happened
+	# at early startup
+	if [ $LOGGERUP -eq 1 ]; then
+	        logger -t choose-consoles "$@"
+	else
+		echo "$@" >> $LOG_FILE
+	fi
+}
+
+flush_logger () {
+	cat $LOG_FILE | logger -t choose-consoles
+	rm $LOG_FILE
+}
+
+consoles=
+preferred=
+# Retrieve all enabled consoles from kernel; ignore those
+# for which no device file exists
+
+kernelconsoles="$(cat /proc/consoles)"
+for cons in $(echo "$kernelconsoles" | sed -n -r -e 's/(^.*)  .*\((.*)\).*$/\1/p' )
+do
+	log "Looking at console $cons from /proc/consoles"
+	status=$(echo "$kernelconsoles" | grep $cons | sed -n -r -e 's/(^.*) *.*\((.*)\).*$/\2/p' )
+	if [ -e "/dev/$cons" ] && [ $(echo "$status" | grep -o 'E') ]; then
+		consoles="${consoles:+$consoles$NL}$cons"
+		log "   Adding $cons to consoles list"
+	fi
+	# 'C' console is 'most prefered'.
+	if [ $(echo "$status" | grep -o 'C') ]; then
+		preferred="$cons"
+		log "   $cons is preferred"
+	fi
+done
+
+if [ -z "$consoles" ]; then
+	# Nothing found? Default to /dev/console.
+	log "Found no consoles! Defaulting to /dev/console"
+	consoles=console
+fi
+if [ -z "$preferred" ]; then
+	#None marked preferred? Use the first one
+	preferred=$(echo "$consoles" | head -n 1) 
+	log "Found no preferred console. Picking $preferred"
+fi
+
+for cons in $consoles
+do
+	echo "/dev/$cons " >> /var/run/console-devices
+done
+echo "/dev/$preferred " > /var/run/console-preferred
+
+
+#Add debian-installer lines into inittab - one per console
+inittab=
+for cons in $consoles
+do
+	log "Adding inittab entry for $cons"
+	DIline="${cons}::respawn:/sbin/debian-installer"
+	echo $DIline >> /etc/inittab
+done
+
+#Run the startup scripts
+cons=$(cat /var/run/console-preferred)
+# Some other session may have console as ctty. Steal it from them
+/sbin/steal-ctty $cons "$@"  
+
+# Now we should have the system ready to run
+LOGGERUP=1
+flush_logger
+
+#Finally restart init to run debian-installer on discovered consoles
+log "Restarting init to start d-i on the consoles we found"
+kill -HUP 1
diff --git b/src/sbin/reopen-console-linux a/src/sbin/reopen-console-linux
deleted file mode 100755
index 3287dd0..0000000
--- b/src/sbin/reopen-console-linux
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/sh
-
-# In order to give proper access to the tty, we need to locate the device
-# corresponding to the console we are actually using.
-
-NL="
-"
-
-console=
-if ! [ -f /var/run/console-device ]; then
-	# If the kernel emitted a "handover" message, then it's the one
-	case $(uname -r) in
-	    2.6.2*|2.6.3[01]*)
-		console="$(dmesg -s 262143 |
-			sed -n -r -e 's/(.*\])? *console handover: boot \[.*\] -> real \[(.*)\]$/\2/p')"
-		;;
-	    2.6.3[234567]*)
-		console="$(dmesg -s 262143 |
-			sed -n -r -e 's/(.*\])? *console \[(.*)\] enabled, bootconsole disabled$/\2/p')"
-		;;
-	    *) # >= 2.6.38
-		console_major_minor="$(get-real-console-linux)"
-		console_raw="$(readlink "/sys/dev/char/${console_major_minor}")"
-		console="${console_raw##*/}"
-		;;
-	esac
-
-	# Except if it is the wrong type...
-	if [ "$console" ] && [ "$(console-type)" = serial ] && \
-	   expr "$console" : "tty[0-9]" >/dev/null; then
-		console=
-	fi
-
-	consoles=
-	if [ -z "$console" ]; then
-		# Retrieve all enabled consoles from boot log; ignore those
-		# for which no device file exists
-		for cons in $(dmesg -s 262143 |
-			sed -n -r -e 's/(.*\])? *console \[(.*)\] enabled/\2/p')
-		do
-			if [ -e "/dev/$cons" ]; then
-				consoles="${consoles:+$consoles$NL}$cons"
-			fi
-		done
-		# Only one console? Then we are good.
-		if [ $(echo "$consoles" | wc -l) -eq 1 ]; then
-			console="$consoles"
-		fi
-	fi
-
-	if [ -z "$console" ]; then
-		# Locate the last enabled console present on the command line
-		for arg in $(cat /proc/cmdline); do
-			case $arg in
-			    console=*)
-				arg=${arg#console=}
-				cons=${arg%%,*}
-				if echo "$consoles" | grep -q "^$cons$"; then
-					console=$cons
-				fi
-				;;
-			esac
-		done
-	fi
-
-	if [ -z "$console" ]; then
-		# Still nothing? Default to /dev/console.
-		console=console
-	fi
-	echo /dev/$console > /var/run/console-device
-fi
-
-# Some other session may have it as ctty. Steal it from them
-exec /sbin/steal-ctty $(cat /var/run/console-device) "$@"
diff --git b/src/sbin/steal-ctty.c a/src/sbin/steal-ctty.c
index 0f3b14f..b99c1bb 100644
--- b/src/sbin/steal-ctty.c
+++ a/src/sbin/steal-ctty.c
@@ -28,8 +28,14 @@ int main(int argc, char ** argv)
     while (fd > 2) {
         close(fd--);
     }
-    ioctl(0, TIOCSCTTY, (char *) 1);
-    execvp(argv[2], &argv[2]);
+    /* make controlling tty if possible - can't be done if D-I is 
+       run on multiple consoles so just quietly move on */
+    if (-1 == ioctl(0, TIOCSCTTY, (char *) 1)) {
+      }
+    if (-1 == execvp(argv[2], &argv[2])) {
+        perror("execvp");
+        return 1;
+    }
     /* never reached. */
     return 0;
 }
diff --git b/debian/changelog a/debian/changelog
index 92b7989..f0bef69 100644
--- b/debian/changelog
+++ a/debian/changelog
@@ -1,3 +1,9 @@
+finish-install (2.99) UNRELEASED; urgency=medium
+
+  * Make compatible with rootskel_1.127 multiple console support (90consoles)
+
+ -- Wookey <woo...@debian.org>  Fri, 22 Feb 2019 17:49:16 +0000
+
 finish-install (2.98) unstable; urgency=medium
   * Team upload
 
diff --git b/finish-install.d/90console a/finish-install.d/90console
index bd2f528..5807502 100755
--- b/finish-install.d/90console
+++ a/finish-install.d/90console
@@ -38,11 +38,10 @@ case "$(udpkg --print-os)" in
 	hurd)
                 # TODO: detect VGA hurd console, and enable it in installed
                 # system.
-		console=console
+		consoles=/dev/console
 		;;
 	*)
-		console=$(cat /var/run/console-device)
-		console=${console#/dev/}
+		consoles="$(cat /var/run/console-devices)"
 		;;
 esac
 
@@ -60,50 +59,54 @@ else
 	upstart_tty1=
 fi
 
-case "$console" in
-    tty[A-Zu]*|duart*)
-	log "Configuring init for serial console"
-	consoletype=${console%%[0-9]*}
-	ttyline=${console#$consoletype}
-	ttyspeed=$(chroot /target stty --file /dev/$console speed)
-	ttyterm="$TERM"
-
-	flowctrlarg=""
-	if uses_hw_flowcontrol $console; then
-		flowctrlarg="-h "
-	fi
-
-	if [ -z "$ttyterm" ]; then ttyterm=vt100; fi
-	if [ -z "$ttyspeed" ]; then ttyspeed=9600; fi
+for console in $consoles
+do
+	console=${console#/dev/}
+	case "$console" in
+	    tty[A-Zu]*|duart*)
+		log "Configuring init for serial console"
+		consoletype=${console%%[0-9]*}
+		ttyline=${console#$consoletype}
+		ttyspeed=$(chroot /target stty --file /dev/$console speed)
+		ttyterm="$TERM"
+
+		flowctrlarg=""
+		if uses_hw_flowcontrol $console; then
+			flowctrlarg="-h "
+		fi
 
-	if [ -f /target/etc/inittab ]; then
-		# Disable regular VTs
-		if [ -z "$KEEP_VT" ]; then
-			sed -i -e "s/^\([1-6]\):/#\1:/" /target/etc/inittab
+		if [ -z "$ttyterm" ]; then ttyterm=vt100; fi
+		if [ -z "$ttyspeed" ]; then ttyspeed=9600; fi
+
+		if [ -f /target/etc/inittab ]; then
+			# Disable regular VTs
+			if [ -z "$KEEP_VT" ]; then
+				sed -i -e "s/^\([1-6]\):/#\1:/" /target/etc/inittab
+			fi
+			# Enable serial console
+			sed -i -e "s/^#T0\(.*\)ttyS.*/T$ttyline\1$console $ttyspeed $ttyterm/" \
+			    /target/etc/inittab
+			sed -i -e "s/^\(T$ttyline.*\) -8/\1/" /target/etc/inittab
+			sed -i -e "s/^\(T$ttyline.* \)-L/\1$flowctrlarg-L/" /target/etc/inittab
+		fi
+		if [ "$upstart_tty1" ]; then
+			sed -e "s/^\(exec.*getty \).*/\1-L $console $ttyspeed $ttyterm/" \
+			    -e "s/tty1/$console/g" \
+			    "$upstart_tty1" > "$(upstart_console "$console")"
+			sed -i -e "s/^\(exec.*\) -8/\1/" "$(upstart_console "$console")"
+			sed -i -e "s/^\(exec.*\)-L/\1$flowctrlarg-L/" "$(upstart_console "$console")"
+		fi
+		if [ "$(readlink /target/sbin/init)" = "/lib/systemd/systemd" ] ; then
+			chroot /target systemctl --no-reload --quiet enable serial-getty@"$console".service
 		fi
-		# Enable serial console
-		sed -i -e "s/^#T0\(.*\)ttyS.*/T$ttyline\1$console $ttyspeed $ttyterm/" \
-		    /target/etc/inittab
-		sed -i -e "s/^\(T$ttyline.*\) -8/\1/" /target/etc/inittab
-		sed -i -e "s/^\(T$ttyline.* \)-L/\1$flowctrlarg-L/" /target/etc/inittab
-	fi
-	if [ "$upstart_tty1" ]; then
-		sed -e "s/^\(exec.*getty \).*/\1-L $console $ttyspeed $ttyterm/" \
-		    -e "s/tty1/$console/g" \
-		    "$upstart_tty1" > "$(upstart_console "$console")"
-		sed -i -e "s/^\(exec.*\) -8/\1/" "$(upstart_console "$console")"
-		sed -i -e "s/^\(exec.*\)-L/\1$flowctrlarg-L/" "$(upstart_console "$console")"
-	fi
-	if [ "$(readlink /target/sbin/init)" = "/lib/systemd/systemd" ] ; then
-		chroot /target systemctl --no-reload --quiet enable serial-getty@"$console".service
-	fi
 
-	write_console "$rawconsole" /target/etc/securetty
-	if [ -n "$console" ] && [ "$console" != "$rawconsole" ]; then
-		write_console "$console" /target/etc/securetty
-	fi
-	;;
-esac
+		write_console "$rawconsole" /target/etc/securetty
+		if [ -n "$console" ] && [ "$console" != "$rawconsole" ]; then
+			write_console "$console" /target/etc/securetty
+		fi
+		;;
+	esac
+done
 
 # Set up virtualized console via onboard service processor (hvsi/hvc)
 DT_ROOT=/proc/device-tree

Attachment: signature.asc
Description: PGP signature

Reply via email to