Skip to contentSkip to conversation

pivot_root off an initramfs broken

PATCH Martin Hicks 2 participants 2 messages Dec 4, 2003 VFS

lore
Share & tools
lore
#0 lore raw

This is the conclusion that I've come to. For background please see:

http://www.zytor.com/pipermail/klibc/2003-November/000223.html
which finishes up here:
http://www.zytor.com/pipermail/klibc/2003-December/000254.html

The executive summary is this:

If I boot a 2.6 kernel that first execs /sbin/kinit on the initramfs, does some setup (mostly to find the real root filesystem), then pivot_roots over to the real root filesystem and execs /sbin/init the kernel spins inside check_mnt() while mounting /proc in the initscripts.

The reason is because the vfsmount structures for the root filesystem looks like this:

mnt->mnt_devname = /dev/root (this is good)
mnt->mnt_parent->mnt_devname = rootfs (this is good, I think)
mnt->mnt_parent->mnt_parent->mnt_devname = /dev/root (wrong!)

I think it's in pivot_root that something is going wrong.

The attached patch fixes the problem, but is just a hack. Any comments on how to really fix this?

TIA,
mh

Signature · 2 lines
Martin Hicks                Wild Open Source Inc.
[email protected]     613-266-2296

===== fs/namespace.c 1.50 vs edited =====

fs/namespace.c +3 -0
@@ -1064,6 +1064,9 @@
 	detach_mnt(user_nd.mnt, &root_parent);
 	attach_mnt(user_nd.mnt, &old_nd);
 	attach_mnt(new_nd.mnt, &root_parent);
+	if (new_nd.mnt == new_nd.mnt->mnt_parent->mnt_parent &&
+	    new_nd.mnt != new_nd.mnt->mnt_parent)  /* initramfs loop */
+		new_nd.mnt->mnt_parent->mnt_parent = new_nd.mnt->mnt_parent;
 	spin_unlock(&vfsmount_lock);
 	chroot_fs_refs(&user_nd, &new_nd);
 	security_sb_post_pivotroot(&user_nd, &new_nd);
#1 lore raw
Followup to:  <[email protected]>
By author:    Martin Hicks <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 6 lines

If I boot a 2.6 kernel that first execs /sbin/kinit on the initramfs, does some setup (mostly to find the real root filesystem), then pivot_roots over to the real root filesystem and execs /sbin/init the kernel spins inside check_mnt() while mounting /proc in the initscripts.

The initramfs is the "real root" -- you shouldn't pivot_root from it, instead you should mount the new root on top of it.

This makes cleaning up a bit of an issue -- the proposed rootfs mount_single patch takes care of that -- but it can also be done by leaving a cleanup process with cwd inside the initramfs with would use relative paths to clean up.

Something like this:

	  mount / /dev/real_root_whatever
	  ( rm -rf . ) &
	  exec /sbin/init "$@"

	  -hpa
Signature · 4 lines
<[email protected]> at work, <[email protected]> in private!
If you send me mail in HTML format I will assume it's spam.
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64