Here is an updated patch series, including the final patch that includes a runsystem.sysv that can be used instead of the current runsystem.gnu to use sysvinit to boot Debian/Hurd systems.
Thanks, Justus
From 3957b17c8ffb9da8679e600b4b3142377051c172 Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 11:41:33 +0200 Subject: [PATCH 1/8] initscripts: hurd has a proper tmpfs now, remove workaround --- debian/changelog | 3 +++ debian/src/initscripts/lib/init/mount-functions.sh | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index ddb344c..67bb5db 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,9 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium - Update invoke-rc.d and service to trim .sh from service names when calling systemctl. (Closes: #726483) + [ Justus Winter ] + * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround. + -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 sysvinit (2.88dsf-45) unstable; urgency=medium diff --git a/debian/src/initscripts/lib/init/mount-functions.sh b/debian/src/initscripts/lib/init/mount-functions.sh index 9fd369b..5126780 100644 --- a/debian/src/initscripts/lib/init/mount-functions.sh +++ b/debian/src/initscripts/lib/init/mount-functions.sh @@ -190,7 +190,6 @@ domount () { elif [ "$PRIFSTYPE" = tmpfs ]; then # always accept tmpfs, to mount /run before /proc case "$KERNEL" in - GNU) FSTYPE=none ;; # for now *) FSTYPE=$PRIFSTYPE ;; esac elif grep -E -qs "$PRIFSTYPE\$" /proc/filesystems; then -- 1.8.5.2
From d61800b0a879b84ec7086d6839003542ea82a851 Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 12:40:09 +0200 Subject: [PATCH 2/8] initscripts: add -ocompatible to procfs mounts on Hurd --- debian/changelog | 1 + debian/src/initscripts/lib/init/mount-functions.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 67bb5db..2e686e5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium [ Justus Winter ] * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround. + * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/src/initscripts/lib/init/mount-functions.sh b/debian/src/initscripts/lib/init/mount-functions.sh index 5126780..8bb3031 100644 --- a/debian/src/initscripts/lib/init/mount-functions.sh +++ b/debian/src/initscripts/lib/init/mount-functions.sh @@ -176,7 +176,8 @@ domount () { if [ "$PRIFSTYPE" = proc ]; then case "$KERNEL" in - Linux|GNU) FSTYPE=proc ;; + Linux) FSTYPE=proc ;; + GNU) FSTYPE=proc; FS_OPTS="-ocompatible" ;; *FreeBSD) FSTYPE=linprocfs ;; *) FSTYPE=procfs ;; esac -- 1.8.5.2
From 3f50e4c5b0e5700ff917f183e975287d2d27ff0e Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 12:48:42 +0200 Subject: [PATCH 3/8] initscripts: use pidof -s /sbin/init for robustness pidof -s returns the first matching process. Since readdir(2) on procfs returns the processes in ascending order, this returns the first process. This is more robust if there is more than one /sbin/init process. Currently on Hurd there are two /sbin/init processes. Clearly this needs some investigation. But as far as I can tell this could also happen if INITDEBUG is defined as /sbin/init then forks a child that can be ptrace(2)d on a vanilla Linux kernel. --- debian/changelog | 1 + debian/src/initscripts/etc/init.d/mountall.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 2e686e5..0b73e79 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium [ Justus Winter ] * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround. * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd. + * mountall.sh: Use pidof -s /sbin/init for robustness. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/src/initscripts/etc/init.d/mountall.sh b/debian/src/initscripts/etc/init.d/mountall.sh index 5f913cd..392eeec 100755 --- a/debian/src/initscripts/etc/init.d/mountall.sh +++ b/debian/src/initscripts/etc/init.d/mountall.sh @@ -55,7 +55,7 @@ do_start() { mknod -m 600 "$INITCTL" p # Reopen control channel. - PID="$(pidof /sbin/init || echo 1)" + PID="$(pidof -s /sbin/init || echo 1)" [ -n "$PID" ] && kill -s USR1 "$PID" fi -- 1.8.5.2
From 52644e408c25cd56d3187287200ecf97cacef868 Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 18:35:44 +0200 Subject: [PATCH 4/8] initscripts: Only run rootcheck on Linux Neither kFreeBSD nor Hurd have /dev/root and the device ids used here are specific to Linux. Note that fsck is still run, rootcheck refers to the check whether the root device in /etc/fstab matches the actual device. --- debian/changelog | 2 ++ debian/src/initscripts/etc/init.d/checkroot.sh | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 0b73e79..32a24d3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround. * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd. * mountall.sh: Use pidof -s /sbin/init for robustness. + * checkroot.sh: Only run rootcheck on Linux. Neither kFreeBSD nor Hurd + have /dev/root and the device ids used here are specific to Linux. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/src/initscripts/etc/init.d/checkroot.sh b/debian/src/initscripts/etc/init.d/checkroot.sh index 05a3c96..61afa70 100755 --- a/debian/src/initscripts/etc/init.d/checkroot.sh +++ b/debian/src/initscripts/etc/init.d/checkroot.sh @@ -84,7 +84,11 @@ do_start () { # If not we try to use the /dev/root alias device, and if that # fails we create a temporary node in /run. # - if [ "$rootcheck" = yes ] + # Do this only on Linux. Neither kFreeBSD nor Hurd have + # /dev/root and the device ids used here are specific to + # Linux. + KERNEL="$(uname)" + if [ "$rootcheck" = yes ] && [ "$KERNEL" = Linux ] then ddev="$(mountpoint -qx $rootdev)" rdev="$(mountpoint -d /)" -- 1.8.5.2
From 3a5b62e23bc71f309ba3091a1b475ab772fe0603 Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 15:56:46 +0200 Subject: [PATCH 5/8] killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS. If sysconf returns an error, fall back to MAXSYMLINKS on platforms that define it. Fixes build on Hurd. --- debian/changelog | 2 ++ src/killall5.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 32a24d3..8d192ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,8 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium * mountall.sh: Use pidof -s /sbin/init for robustness. * checkroot.sh: Only run rootcheck on Linux. Neither kFreeBSD nor Hurd have /dev/root and the device ids used here are specific to Linux. + * killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS. + Fixes build on Hurd. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/src/killall5.c b/src/killall5.c index 5937d98..2c9bb4f 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -367,13 +367,26 @@ out: } /* + * Get the maximal number of symlinks to follow. + */ +static int maxsymlinks(void) +{ + int v = sysconf(_SC_SYMLOOP_MAX); +#ifdef MAXSYMLINKS + if (v == -1) + return MAXSYMLINKS; +#endif + return v; +} + +/* * Check path is located on a network based partition. */ int check4nfs(const char * path, char * real) { char buf[PATH_MAX+1]; const char *curr; - int deep = MAXSYMLINKS; + int deep = maxsymlinks(); if (!nlist) return 0; -- 1.8.5.2
From 97f6d9db739f788fbefe4ac4f55772629843289b Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 8 Jul 2013 19:00:04 +0200 Subject: [PATCH 6/8] sysvinit: Fix getty path in /etc/inittab on Hurd. This is essentially the same as 89f6476d8979174f395a1bf784486254464c349d but fixes the existing /etc/inittab file in the postinstall script. --- debian/changelog | 1 + debian/sysvinit-core.config | 43 ++++++++++++++++++++++++++++++++++++++++++ debian/sysvinit-core.postinst | 13 +++++++++++++ debian/sysvinit-core.templates | 15 +++++++++++++++ 4 files changed, 72 insertions(+) create mode 100755 debian/sysvinit-core.config create mode 100644 debian/sysvinit-core.templates diff --git a/debian/changelog b/debian/changelog index 8d192ae..23b6a4c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,7 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium have /dev/root and the device ids used here are specific to Linux. * killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS. Fixes build on Hurd. + * sysvinit.postinst: Fix file name of gettys in /etc/inittab on Hurd. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/sysvinit-core.config b/debian/sysvinit-core.config new file mode 100755 index 0000000..ce34f63 --- /dev/null +++ b/debian/sysvinit-core.config @@ -0,0 +1,43 @@ +#!/bin/sh +# config script for sysvinit +# +# see: dh_installdeb(1) + +set -e + +. /usr/share/debconf/confmodule + +# summary of how this script can be called: +# * <config> `configure' <installed-version> +# * <config> `reconfigure' <installed-version> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + +case "$1" in + configure|reconfigure) + + if [ "$(uname)" = GNU ]; then + db_set sysvinit/hurd-fix-inittab "true" + if echo '3e3693078d18d4696c83a76531433cd4 /etc/inittab' \ + | md5sum --status --check -; then + # The file is unmodified, update it silently. + : + elif fgrep -q '/libexec/getty' /etc/inittab; then + db_input low sysvinit/hurd-fix-inittab || true + db_go + fi + fi + ;; + + *) + echo "config script called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/sysvinit-core.postinst b/debian/sysvinit-core.postinst index 1750412..d78fe86 100755 --- a/debian/sysvinit-core.postinst +++ b/debian/sysvinit-core.postinst @@ -5,6 +5,9 @@ set -e +# Source debconf library. +. /usr/share/debconf/confmodule + # Restart init, and migrate to /run/initctl if needed. do_restart() { INITCTL=/run/initctl @@ -83,6 +86,16 @@ rm -f /etc/ioctl.save if [ ! -f /etc/inittab ] then cp -p /usr/share/sysvinit/inittab /etc/inittab +elif [ "$(uname)" = GNU ] && fgrep -q '/libexec/getty' /etc/inittab; then + rm -f -- /etc/inittab.dpkg-new + sed -e '/^[^#]/ s|/libexec/getty|/sbin/getty|' \ + < /etc/inittab > /etc/inittab.dpkg-new + + db_get sysvinit/hurd-fix-inittab + if [ "${RET}" = "true" ]; then + mv -- /etc/inittab /etc/inittab.dpkg-old + mv -- /etc/inittab.dpkg-new /etc/inittab + fi fi restart=yes diff --git a/debian/sysvinit-core.templates b/debian/sysvinit-core.templates new file mode 100644 index 0000000..935ae84 --- /dev/null +++ b/debian/sysvinit-core.templates @@ -0,0 +1,15 @@ +Template: sysvinit/hurd-fix-inittab +Type: boolean +_Description: Update getty file names in /etc/inittab? + Your /etc/inittab seems to use /libexec/getty as getty. The default + inittab has been changed, however your /etc/inittab has been + modified. Note that sysvinit has never been used to boot an Hurd + system, so any errors in that file would not have shown up. + . + Do you want me to change /etc/inittab to use /sbin/getty as getty? + . + If you choose yes, a backup will be stored in /etc/inittab.dpkg-old. + . + If you choose no, an updated inittab will be written to + /etc/inittab.dpkg-new. Please review the changes and update your + /etc/inittab accordingly. -- 1.8.5.2
From b8848ccd465d5a984fab087092d026b273ebdf3a Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Wed, 18 Sep 2013 13:17:23 +0200 Subject: [PATCH 7/8] initscripts: Break hurd << 0.5.git20131101~ Older versions of the hurd package lack the necessary functionality to boot Debian/Hurd using sysvinit. --- debian/changelog | 3 +++ debian/control | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 23b6a4c..506fc5f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,9 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium * killall5.c: Use sysconf(_SC_SYMLOOP_MAX) instead of MAXSYMLINKS. Fixes build on Hurd. * sysvinit.postinst: Fix file name of gettys in /etc/inittab on Hurd. + * Break hurd << 0.5.git20131101~. Older versions of the hurd + package lack the necessary functionality to boot Debian/Hurd using + sysvinit. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/control b/debian/control index a0aaf06..817c017 100644 --- a/debian/control +++ b/debian/control @@ -130,7 +130,9 @@ Breaks: # being a symlink #668616 and #668650 initramfs-tools (<< 0.104), # Needed for transition to dependency-based boot for wheezy - bootchart (<< 0.10~svn407-4) + bootchart (<< 0.10~svn407-4), +# Older versions of hurd do not implement the neccessary functionality + hurd (<< 0.5.git20131101~) Description: scripts for initializing and shutting down the system The scripts in this package initialize a standard Debian system at boot time and shut it down at halt or reboot time. -- 1.8.5.2
From 1843727e6f6ae5985fb52adb9ddb8d61e4fd3984 Mon Sep 17 00:00:00 2001 From: Justus Winter <4win...@informatik.uni-hamburg.de> Date: Mon, 13 Jan 2014 11:20:05 +0100 Subject: [PATCH 8/8] initscripts: add runsystem.sysv runsystem.sysv does some very early initialization of Hurd and execs /sbin/init to start the system using sysvinit. Hurd uses the alternatives system to choose which runsystem to use and traditionally shipped a custom init solution. Add runsystem.sysv using update-alternatives in initscripts.postinst. Since the choice of runsystems also dictate which halt and reboot to use, add those utilities as slaves to the runsystem alternative and display instructions on how to reboot or halt the system if installing the initscript package switches the runsystem. --- debian/changelog | 1 + debian/initscripts.postinst | 30 +++++++ debian/rules | 3 + debian/src/initscripts/etc/hurd/runsystem.sysv | 106 +++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 debian/src/initscripts/etc/hurd/runsystem.sysv diff --git a/debian/changelog b/debian/changelog index 506fc5f..4267445 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,7 @@ sysvinit (2.88dsf-46) UNRELEASED; urgency=medium * Break hurd << 0.5.git20131101~. Older versions of the hurd package lack the necessary functionality to boot Debian/Hurd using sysvinit. + * Add runsystem.sysv that uses sysvinit to boot Debian/Hurd. -- James McCoy <james...@debian.org> Thu, 02 Jan 2014 20:48:18 -0500 diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst index bf20b7f..7288c2c 100755 --- a/debian/initscripts.postinst +++ b/debian/initscripts.postinst @@ -222,6 +222,36 @@ then fi fi +# +# Install runsystem.sysv on Hurd. +# +if [ "$(uname -s)" = GNU ] +then + get_runsystem() { + update-alternatives --query runsystem \ + | sed -n -e '/^Value:/s|.*\.||p' + } + + current="$(get_runsystem)" + update-alternatives --quiet \ + --install /etc/hurd/runsystem runsystem \ + /etc/hurd/runsystem.sysv 10 \ + --slave /sbin/halt halt /sbin/halt-sysv \ + --slave /sbin/reboot reboot /sbin/reboot-sysv + new="$(get_runsystem)" + + if [ "$current" != "$new" ]; then + echo "Switching from runsystem.$current to runsystem.$new." + echo + fi + + echo "You can use update-alternatives --config runsystem to select" + echo "the runsystem to use." + echo + echo "You must use halt-hurd or reboot-hurd to halt or reboot the" + echo "system whenever you change the runsystem." +fi + # Ensure we have a random seed on first boot. if [ "$PREV_VER" = "" ]; then if which invoke-rc.d >/dev/null 2>&1 diff --git a/debian/rules b/debian/rules index 341b9be..10af575 100755 --- a/debian/rules +++ b/debian/rules @@ -126,6 +126,9 @@ ifeq ($(DEB_HOST_ARCH_OS), hurd) mv $(sysvtmp)/sbin/halt $(sysvtmp)/sbin/halt-sysv rm $(sysvtmp)/sbin/reboot ln -s halt-sysv $(sysvtmp)/sbin/reboot-sysv + $(INSTALL) -d $(inittmp)/etc/hurd + $(INSTALL) debian/src/initscripts/etc/hurd/runsystem.sysv \ + $(inittmp)/etc/hurd endif override_dh_installdeb-indep: diff --git a/debian/src/initscripts/etc/hurd/runsystem.sysv b/debian/src/initscripts/etc/hurd/runsystem.sysv new file mode 100644 index 0000000..c80c9f3 --- /dev/null +++ b/debian/src/initscripts/etc/hurd/runsystem.sysv @@ -0,0 +1,106 @@ +#!/bin/sh +# +# This program is run by /hurd/init at boot time after the essential +# servers are up. It does some initialization of its own and then +# execs the SysV init to bring up the "userland" parts of a normal +# system. +# + +### +### Where to find programs, etc. +### + +PATH=/bin:/sbin:/usr/bin:/usr/sbin +export PATH + +# If we lose badly, try to exec each of these in turn. +fallback_shells='/bin/sh /bin/dash /bin/bash /bin/csh /bin/ash /bin/shd' + +# Shell used for normal single-user startup. +SHELL=/bin/sh + +### + +# If we get a SIGLOST, attempt to reopen the console in case +# our console ports were revoked. This lets us print messages. +reopen_console () +{ + exec 1>/dev/console 2>&1 || exit 3 +} +trap 'reopen_console' 32 # SIGLOST = server died on GNU + + +# Call this when we are losing badly enough that we want to punt normal +# startup entirely. We exec a single-user shell, so we will not come back +# here. The only way to get to multi-user from that shell will be +# explicitly exec this script or something like that. +singleuser() +{ + test $# -eq 0 || echo "$0: $*" + for try in ${fallback_shells}; do + SHELL=${try} + exec ${SHELL} + done + exit 127 +} + +# Print a newline. +echo + +# See whether pflocal is setup +# +# Normally this should be the case, but we better make sure since +# without the pflocal server, pipe(2) does not work. +if ! test -e /servers/socket/1 && which settrans >/dev/null ; then + # The root filesystem should be read-only at this point. + if fsysopts / --update --writable ; then + settrans -c /servers/socket/1 /hurd/pflocal + else + singleuser "Failed to create /servers/socket/1." + fi +fi + +# We expect to be started by console-run, which gives us no arguments and +# puts FALLBACK_CONSOLE=file-name in the environment if our console is +# other than a normal /dev/console. + +if [ "${FALLBACK_CONSOLE+set}" = set ]; then + singleuser "Running on fallback console ${FALLBACK_CONSOLE}" +fi + +### +### Normal startup procedures +### + +# Parse the multiboot command line. We only pay attention to -s and -f. +# The first argument is the kernel file name; skip that. +shift +flags= +single= +while [ $# -gt 0 ]; do + arg="$1" + shift + case "$arg" in + --*) ;; + *=*) ;; + -*) + flags="${flags}${arg#-}" + ;; + 'single') + single="-s" + ;; + 'fastboot'|'emergency') + ;; + esac +done + +# Start the default pager. It will bail if there is already one running. +/hurd/mach-defpager + +# This is necessary to make stat / return the correct device ids. +sleep 0.1 # Work around a race condition (probably in the root + # translator). +fsysopts / --update --readonly + +# Finally, start the actual SysV init. +exec /sbin/init ${single} -a -- 1.8.5.2