Hi,

On Wed, 21 Jun 2006 13:50:12 -0700
"Richard Fish" <[EMAIL PROTECTED]> wrote:

> pivot_root is specifically *not* allowed from an initramfs
> environment.  What you want to do is simply mount the new root
> filesystem, chroot into it, and execute init.  Something like:
> 
> cd /new_root ; exec ./bin/chroot . ./sbin/init "$@" >dev/console
> <dev/console 2>&1
> 
> If you are *extremely* tricky, and use a symlinked /lib directory, you
> can actually delete everything from the initramfs before doing the
> chroot/init calls.  Let me know if you need some more details on this.

Hm, I'm pretty sure that it is well possible to pivot_root from an
initramfs. Isn't that the whole point of pivot_root? But you may be
right that it is not possible for NFS mounts, I never tried that before.

In fact, the approach you took is weak. /sbin/init wouldn't run as PID
1 in this case which is bad for the situation that the calling script
(which _has_ PID 1) dies. The kernel would recognize this and reboot
(and/or panic, not sure). To avoid this, one has to exec the init from
the script.

So basically it boils down to this /init in the initramfs:

#!/bin/sh
PATH=/bin:/sbin
modprobe supermightyrootfsprovidingmodule && \
  mount -t blahfs /dev/whereitis /mnt/stagetwo && \
  cd /mnt/stagetwo && \
  pivot_root . /mnt/initramfs || reboot -f
exec /sbin/init

Note that I assume /mnt/stagetwo exists in initramfs (as well as
modprobe, mount, pivot_root and reboot) and /mnt/initramfs exists in
the to-be-mounted fs. Note that the last point may prevent
pivot_root'ing in a scenario where an NFS root fs is desired (because
I'm not sure if it can have mounts in it, but that would be needed for
proc, sys and dev, too, so it _may_ work here, too). The call
to /sbin/init happens in the new fs because pivot_root manipulates the
namespace of the calling process. Exec'ing is important so
that /sbin/init gets PID 1 and we don't have a process which depends on
the initramfs anymore, so we can unmount it at a later point.

-hwh
-- 
gentoo-user@gentoo.org mailing list

Reply via email to