Gentoo Archives: gentoo-user

From: Hans-Werner Hilse <hilse@×××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] initramfs, network diskless boot, init process, problems with switchroot (pivot_root)
Date: Wed, 21 Jun 2006 21:46:17
Message-Id: 20060621234505.d3471724.hilse@web.de
In Reply to: Re: [gentoo-user] initramfs, network diskless boot, init process, problems with switchroot (pivot_root) by Richard Fish
1 Hi,
2
3 On Wed, 21 Jun 2006 13:50:12 -0700
4 "Richard Fish" <bigfish@××××××××××.org> wrote:
5
6 > pivot_root is specifically *not* allowed from an initramfs
7 > environment. What you want to do is simply mount the new root
8 > filesystem, chroot into it, and execute init. Something like:
9 >
10 > cd /new_root ; exec ./bin/chroot . ./sbin/init "$@" >dev/console
11 > <dev/console 2>&1
12 >
13 > If you are *extremely* tricky, and use a symlinked /lib directory, you
14 > can actually delete everything from the initramfs before doing the
15 > chroot/init calls. Let me know if you need some more details on this.
16
17 Hm, I'm pretty sure that it is well possible to pivot_root from an
18 initramfs. Isn't that the whole point of pivot_root? But you may be
19 right that it is not possible for NFS mounts, I never tried that before.
20
21 In fact, the approach you took is weak. /sbin/init wouldn't run as PID
22 1 in this case which is bad for the situation that the calling script
23 (which _has_ PID 1) dies. The kernel would recognize this and reboot
24 (and/or panic, not sure). To avoid this, one has to exec the init from
25 the script.
26
27 So basically it boils down to this /init in the initramfs:
28
29 #!/bin/sh
30 PATH=/bin:/sbin
31 modprobe supermightyrootfsprovidingmodule && \
32 mount -t blahfs /dev/whereitis /mnt/stagetwo && \
33 cd /mnt/stagetwo && \
34 pivot_root . /mnt/initramfs || reboot -f
35 exec /sbin/init
36
37 Note that I assume /mnt/stagetwo exists in initramfs (as well as
38 modprobe, mount, pivot_root and reboot) and /mnt/initramfs exists in
39 the to-be-mounted fs. Note that the last point may prevent
40 pivot_root'ing in a scenario where an NFS root fs is desired (because
41 I'm not sure if it can have mounts in it, but that would be needed for
42 proc, sys and dev, too, so it _may_ work here, too). The call
43 to /sbin/init happens in the new fs because pivot_root manipulates the
44 namespace of the calling process. Exec'ing is important so
45 that /sbin/init gets PID 1 and we don't have a process which depends on
46 the initramfs anymore, so we can unmount it at a later point.
47
48 -hwh
49 --
50 gentoo-user@g.o mailing list

Replies