replace switch_root shell script with binary
PATCH 1/1 replace switch_root shell script with binary
The switch_root shell script did not work with bash-4.0-2, because "exec" gets the real path of the executable which is then "/sysroot/lib/ld-linux.so.2" instread of "./lib/ld-linux.so.2".
Also the required chroot binary might live in /usr/bin, which can be mounted later.
Here is the switch_root code from nash, which can be stripped down further, but which works.
From f1b1e4f8694104f007e4483c36b0bf40a5760167 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <[email protected]>
Date: Wed, 4 Mar 2009 13:41:07 +0100
Subject: [PATCH] replace switch_root shell script with binary
The switch_root shell script did not work with bash-4.0-2, because "exec" gets the real path of the executable which is then "/sysroot/lib/ld-linux.so.2" instead of "./lib/ld-linux.so.2". Also the required chroot binary might live in /usr/bin, which can be mounted later.
Here is the switch_root code from nash, which can be stripped down further, but which works.
--- Makefile | 11 +- init | 3 + switch_root | 111 ------------ switch_root.c | 556 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 566 insertions(+), 115 deletions(-) delete mode 100755 switch_root create mode 100644 switch_root.c
Makefile +7 -4
@@ -1,7 +1,9 @@ -all: - @echo "Nothing to do" +switch_root: switch_root.c + gcc -o switch_root switch_root.c -install: +all: switch_root + +install: all mkdir -p $(DESTDIR)/usr/libexec/dracut mkdir -p $(DESTDIR)/sbin mkdir -p $(DESTDIR)/usr/libexec/dracut/hooks
@@ -16,6 +18,7 @@ install: for module in modules/*.sh; do install -m 0755 $$module $(DESTDIR)/usr/libexec/dracut ; done clean: rm -f *~ + rm -f switch_root -archive: +archive: git archive --format=tar HEAD --prefix=dracut/ |bzip2 > dracut-$(shell git rev-list --abbrev-commit -n 1 HEAD |cut -b 1-8).tar.bz2
init +3 -0
@@ -103,6 +103,9 @@ INIT=$(getarg init); INIT=${INIT#init=} } source_all pre-pivot + +kill $(pidof udevd) + echo "Switching to real root filesystem $root" exec switch_root "$NEWROOT" "$INIT" $CMDLINE || { # davej doesn't like initrd bugs
switch_root deleted +0 -111
111 lines not on this page · raw message
switch_root.c new file +556 -0
556 lines not on this page · raw message
Signature · 1 line
1.6.0.6
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · Harald Hoyer
The
switch_rootshell script did not work with bash-4.0-2, because "exec" gets the real path of the executable which is then "/sysroot/lib/ld-linux.so.2" instread of "./lib/ld-linux.so.2".
That is a little odd -- dash does not exhibit that behaviour.
The only command that tries to use ./lib/ld-linux.so.2 is the final chroot, and at that point /sysroot does not mean anything anymore because of the move mount we did. Is this a bug in bash we can work around by setting $PWD?
Quoted 2 lines
Also the required chroot binary might live in
/usr/bin, which can be mounted later.
yeah, but /usr/sbin and /usr/bin are stupid places to have chroot, it is a core utility anyways. :)
[ patch snipped ]
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html