public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olh@suse.de>
To: linux-fsdevel@vger.kernel.org
Subject: Re: pivotroot does not work with initramfs
Date: Sat, 22 Nov 2003 17:46:08 +0100	[thread overview]
Message-ID: <20031122164608.GA8009@suse.de> (raw)
In-Reply-To: <20031116170438.GA4466@suse.de>

 On Sun, Nov 16, Olaf Hering wrote:

> 
> I cant remount the root filesystem rw, mounting proc doesnt work either,
> mount hangs, no userinput possible. System is a old powermac.
> It seems pivotroot is either broken, or I dont use it correctly.

Maybe I'm doing something stupid, or there is no obvious RTMF about how
to use kinit from klibc properly. bootargs are:

console=ttyS0,38400 rw ip=eth0 root=/dev/nfs nfsroot=192.168.1.2:/nfsroot/mac kinit=/bin/kinit

kinit does a pivot_root and returns. prepare_namespace() does
sys_mount(".", "/", NULL, MS_MOVE, NULL);
which leads to this loop:

check_mnt(103)+ swapper c47f51e0 c47f54a0
0 c47f51e0 192.168.1.2:/nfsroot/mac c47f54a0 rootfs
1 c47f54a0 rootfs c47f51e0 192.168.1.2:/nfsroot/mac
2 c47f51e0 192.168.1.2:/nfsroot/mac c47f54a0 rootfs
3 c47f54a0 rootfs c47f51e0 192.168.1.2:/nfsroot/mac
4 c47f51e0 192.168.1.2:/nfsroot/mac c47f54a0 rootfs
...

I'm using these changes:


diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/fs/namespace.c linuxppc-2.5_2.6.0-test9-bk/fs/namespace.c
--- linuxppc-2.5_2.6.0-test9-bk.orig/fs/namespace.c	2003-10-08 03:52:02.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/fs/namespace.c	2003-11-22 17:27:52.000000000 +0100
@@ -98,10 +98,15 @@ EXPORT_SYMBOL(lookup_mnt);
 
 static int check_mnt(struct vfsmount *mnt)
 {
+	printk("%s(%u)+ %s %p %p\n",__FUNCTION__,__LINE__,current->comm,mnt, mnt->mnt_parent);
 	spin_lock(&vfsmount_lock);
 	while (mnt->mnt_parent != mnt)
+	{
+		printk("%p %s %p %s\n",mnt,mnt->mnt_devname, mnt->mnt_parent,mnt->mnt_parent->mnt_devname);
 		mnt = mnt->mnt_parent;
+	}
 	spin_unlock(&vfsmount_lock);
+	printk("%s(%u)- %p\n",__FUNCTION__,__LINE__,current->namespace->root);
 	return mnt == current->namespace->root;
 }
 
diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/do_mounts.c linuxppc-2.5_2.6.0-test9-bk/init/do_mounts.c
--- linuxppc-2.5_2.6.0-test9-bk.orig/init/do_mounts.c	2003-10-08 23:10:47.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/init/do_mounts.c	2003-11-22 17:09:52.000000000 +0100
@@ -370,12 +370,37 @@ void __init mount_root(void)
 	mount_block_root("/dev/root", root_mountflags);
 }
 
+extern int foobar;
+extern asmlinkage long sys_access(const char * filename, int mode);
+static char *kinit_command = "/bin/sh";
+
+static int __init kinit_setup(char *str)
+{
+	kinit_command = str;
+	return 1;
+}
+
+__setup("kinit=", kinit_setup);
+
+static int __init kinit_exec(void * shell)
+{
+	static char *argv[] = { "kinit", NULL, };
+	extern char * envp_init[];
+
+	close(0);close(1);close(2);
+	setsid();
+	(void) open("/dev/console",O_RDWR,0);
+	(void) dup(0);
+	(void) dup(0);
+	return execve(shell, argv, envp_init);
+}
 /*
  * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
  */
 void __init prepare_namespace(void)
 {
 	int is_floppy;
+	int pid, i;
 
 	mount_devfs();
 
@@ -393,6 +418,20 @@ void __init prepare_namespace(void)
 	if (initrd_load())
 		goto out;
 
+	if (foobar)
+		sys_umount("/sys",0);
+	/*
+	 * check if there is an early userspace init, if yes
+	 */
+	if (kinit_command && sys_access(kinit_command,0) == 0) {
+		pid = kernel_thread(kinit_exec, kinit_command, SIGCHLD);
+		if (pid > 0) {
+			while (pid != waitpid(-1, &i, 0))
+				yield();
+		}
+		goto out;
+	}
+
 	if (is_floppy && rd_doload && rd_load_disk(0))
 		ROOT_DEV = Root_RAM0;
 
diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/initramfs.c linuxppc-2.5_2.6.0-test9-bk/init/initramfs.c
--- linuxppc-2.5_2.6.0-test9-bk.orig/init/initramfs.c	2003-10-18 17:25:50.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/init/initramfs.c	2003-11-22 15:24:13.000000000 +0100
@@ -477,12 +477,17 @@ extern char __initramfs_start, __initram
 #include <linux/initrd.h>
 #endif
 
+extern int foobar;
+
 void __init populate_rootfs(void)
 {
 	char *err = unpack_to_rootfs(&__initramfs_start,
 			 &__initramfs_end - &__initramfs_start, 0);
 	if (err)
 		panic(err);
+	foobar = sys_mount("sys", "/sys","sysfs",NULL,NULL);
+	printk(" mount sysfs returned %ld\n", foobar);
+	foobar = !foobar;
 #ifdef CONFIG_BLK_DEV_INITRD
 	if (initrd_start) {
 		int fd;
diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/main.c linuxppc-2.5_2.6.0-test9-bk/init/main.c
--- linuxppc-2.5_2.6.0-test9-bk.orig/init/main.c	2003-10-23 00:25:21.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/init/main.c	2003-11-22 15:23:11.000000000 +0100
@@ -471,6 +471,7 @@ asmlinkage void __init start_kernel(void
 }
 
 int __initdata initcall_debug;
+int foobar;
 
 static int __init initcall_debug_setup(char *str)
 {
@@ -534,6 +535,7 @@ static void __init do_basic_setup(void)
 	sock_init();
 
 	init_workqueues();
+	init_elf_binfmt();
 	do_initcalls();
 }
 
diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x syscalls -x socketcalls klibc-0.81.orig/kinit/kinit.c klibc-0.81/kinit/kinit.c
--- klibc-0.81.orig/kinit/kinit.c	2003-06-01 08:18:41.000000000 +0200
+++ klibc-0.81/kinit/kinit.c	2003-11-22 17:40:35.000000000 +0100
@@ -181,10 +181,16 @@ char *get_arg(int argc, char *argv[], co
 	int i;
 
 	for (i = 1; i < argc; i++) {
-		if (argv[i] && strncmp(argv[i], name, len) == 0 &&
-		    (argv[i][len] == '\0')) {
-			ret = argv[i] + len;
-			break;
+		if (argv[i] && strncmp(argv[i], name, len) == 0) {
+			if (argv[i][len] == '\0') {
+				ret = argv[i];
+				break;
+			} else {
+				if (len && argv[i][len-1] == '=') {
+					ret = argv[i] + len;
+					break;
+				}
+			}
 		}
 	}
 
diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x syscalls -x socketcalls klibc-0.81.orig/klibc/Makefile klibc-0.81/klibc/Makefile
--- klibc-0.81.orig/klibc/Makefile	2003-05-03 00:15:18.000000000 +0200
+++ klibc-0.81/klibc/Makefile	2003-11-22 13:44:22.000000000 +0100
@@ -61,7 +61,7 @@ tests/% : tests/%.o $(LIB) $(CRT0)
 	$(STRIP) $@.stripped
 
 tests/%.shared : tests/%.o interp.o $(SOLIB)
-	$(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
+	$(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o $(SOLIB) $(LIBGCC)
 	cp $@ $@.stripped
 	$(STRIP) $@.stripped
 
diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x syscalls -x socketcalls klibc-0.81.orig/klibc/arch/ppc/MCONFIG klibc-0.81/klibc/arch/ppc/MCONFIG
--- klibc-0.81.orig/klibc/arch/ppc/MCONFIG	2002-08-13 06:04:47.000000000 +0200
+++ klibc-0.81/klibc/arch/ppc/MCONFIG	2003-11-22 13:43:53.000000000 +0100
@@ -9,3 +9,4 @@
 
 OPTFLAGS = -Os -fomit-frame-pointer
 BITSIZE  = 32
+SHAREDFLAGS = -shared
-- 
USB is for mice, FireWire is for men!

sUse lINUX ag, nÜRNBERG
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2003-11-22 16:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-16 17:04 pivotroot does not work with initramfs Olaf Hering
2003-11-19 23:49 ` Greg KH
2003-11-22 16:46 ` Olaf Hering [this message]
2003-11-22 20:48   ` Olaf Hering
2003-11-22 21:50     ` viro
2003-11-25 20:02       ` Olaf Hering

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=20031122164608.GA8009@suse.de \
    --to=olh@suse.de \
    --cc=linux-fsdevel@vger.kernel.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