1 |
On 6/21/06, Hans-Werner Hilse <hilse@×××.de> wrote: |
2 |
> On Wed, 21 Jun 2006 13:50:12 -0700 |
3 |
> |
4 |
> Hm, I'm pretty sure that it is well possible to pivot_root from an |
5 |
> initramfs. Isn't that the whole point of pivot_root? But you may be |
6 |
> right that it is not possible for NFS mounts, I never tried that before. |
7 |
|
8 |
http://bugzilla.kernel.org/show_bug.cgi?id=4857 |
9 |
|
10 |
My final comments on that bug are based on the attached email that I |
11 |
received from Andrew Morton that made it clear that Al Viro was |
12 |
opposed to pivot_root being used from an initramfs. (BTW, viro's |
13 |
comments are not very polite, but you have to expect such directness |
14 |
from kernel hackers!) |
15 |
|
16 |
Note, be sure we are talking about an initramfs here, not an initrd. |
17 |
>From an initrd it is still possible and supported to use pivot_root. |
18 |
|
19 |
> In fact, the approach you took is weak. /sbin/init wouldn't run as PID |
20 |
> 1 in this case which is bad for the situation that the calling script |
21 |
> (which _has_ PID 1) dies. The kernel would recognize this and reboot |
22 |
> (and/or panic, not sure). To avoid this, one has to exec the init from |
23 |
> the script. |
24 |
|
25 |
No, this works perfectly. I use it every time I boot my kernel, and |
26 |
my init *is* PID 1. |
27 |
|
28 |
The "exec ./bin/chroot" part replaces the shell executing the /init |
29 |
script with the chroot command, so chroot then becomes PID 1. Chroot |
30 |
then does an exec of ./sbin/init so that init becomes PID 1. |
31 |
|
32 |
> |
33 |
> So basically it boils down to this /init in the initramfs: |
34 |
> |
35 |
> #!/bin/sh |
36 |
> PATH=/bin:/sbin |
37 |
> modprobe supermightyrootfsprovidingmodule && \ |
38 |
> mount -t blahfs /dev/whereitis /mnt/stagetwo && \ |
39 |
> cd /mnt/stagetwo && \ |
40 |
> pivot_root . /mnt/initramfs || reboot -f |
41 |
> exec /sbin/init |
42 |
|
43 |
Be warned that if you do this, and then you try to "mount --move" |
44 |
anything, your kernel will probably hang. |
45 |
|
46 |
But again, in recent kernels, pivot_root *should* be returning -EINVAL |
47 |
if you do this. Indeed I just checked my 2.6.16 sources, and the code |
48 |
that returns EINVAL in sys_pivot_root for unattached mounts is still |
49 |
there: |
50 |
|
51 |
error = -EINVAL; |
52 |
if (user_nd.mnt->mnt_root != user_nd.dentry) |
53 |
goto out2; /* not a mountpoint */ |
54 |
if (user_nd.mnt->mnt_parent == user_nd.mnt) |
55 |
goto out2; /* not attached */ |
56 |
if (new_nd.mnt->mnt_root != new_nd.dentry) |
57 |
goto out2; /* not a mountpoint */ |
58 |
if (new_nd.mnt->mnt_parent == new_nd.mnt) |
59 |
goto out2; /* not attached */ |
60 |
|
61 |
So unless your the pivot_root program is doing something other than |
62 |
sys_pivot_root(), I don't see how this can possibly work on a recent |
63 |
kernel. |
64 |
|
65 |
-Richard |
66 |
-- |
67 |
gentoo-user@g.o mailing list |