public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Hans-Werner Hilse <hilse@web.de>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] initramfs, network diskless boot, init process, problems with switchroot (pivot_root)
Date: Wed, 21 Jun 2006 23:45:05 +0200	[thread overview]
Message-ID: <20060621234505.d3471724.hilse@web.de> (raw)
In-Reply-To: <7573e9640606211350o4042b571i514307d6ac242fc8@mail.gmail.com>

Hi,

On Wed, 21 Jun 2006 13:50:12 -0700
"Richard Fish" <bigfish@asmallpond.org> 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	other threads:[~2006-06-21 21:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-16 20:05 [gentoo-user] initramfs, network diskless boot, init process, problems with switchroot (pivot_root) Claudinei Matos
2006-06-21 20:50 ` Richard Fish
2006-06-21 21:45   ` Hans-Werner Hilse [this message]
2006-06-21 22:51     ` Richard Fish
2006-06-21 22:53       ` Richard Fish
2006-06-22  0:04       ` Hans-Werner Hilse
2006-06-22  1:12         ` Richard Fish
2006-06-23 23:43           ` Claudinei Matos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060621234505.d3471724.hilse@web.de \
    --to=hilse@web.de \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox