From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Subject: Re: pivotroot does not work with initramfs Date: Sat, 22 Nov 2003 17:46:08 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20031122164608.GA8009@suse.de> References: <20031116170438.GA4466@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from ns.suse.de ([195.135.220.2]:17543 "EHLO Cantor.suse.de") by vger.kernel.org with ESMTP id S262280AbTKVQqK (ORCPT ); Sat, 22 Nov 2003 11:46:10 -0500 Received: from Hermes.suse.de (Hermes.suse.de [195.135.221.8]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by Cantor.suse.de (Postfix) with ESMTP id 8DA521830DDE for ; Sat, 22 Nov 2003 17:46:09 +0100 (CET) To: linux-fsdevel@vger.kernel.org Content-Disposition: inline In-Reply-To: <20031116170438.GA4466@suse.de> List-Id: linux-fsdevel.vger.kernel.org On Sun, Nov 16, Olaf Hering wrote: >=20 > I cant remount the root filesystem rw, mounting proc doesnt work eith= er, > 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=3DttyS0,38400 rw ip=3Deth0 root=3D/dev/nfs nfsroot=3D192.168.1.= 2:/nfsroot/mac kinit=3D/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 =2E.. I'm using these changes: diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_e= xclude.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= =2E000000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/fs/namespace.c 2003-11-22 17:27:52.0000= 00000 +0100 @@ -98,10 +98,15 @@ EXPORT_SYMBOL(lookup_mnt); =20 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 !=3D mnt) + { + printk("%p %s %p %s\n",mnt,mnt->mnt_devname, mnt->mnt_parent,mnt->mn= t_parent->mnt_devname); mnt =3D mnt->mnt_parent; + } spin_unlock(&vfsmount_lock); + printk("%s(%u)- %p\n",__FUNCTION__,__LINE__,current->namespace->root)= ; return mnt =3D=3D current->namespace->root; } =20 diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_e= xclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/do_mounts.c linuxppc-2= =2E5_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.00= 0000000 +0100 @@ -370,12 +370,37 @@ void __init mount_root(void) mount_block_root("/dev/root", root_mountflags); } =20 +extern int foobar; +extern asmlinkage long sys_access(const char * filename, int mode); +static char *kinit_command =3D "/bin/sh"; + +static int __init kinit_setup(char *str) +{ + kinit_command =3D str; + return 1; +} + +__setup("kinit=3D", kinit_setup); + +static int __init kinit_exec(void * shell) +{ + static char *argv[] =3D { "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; =20 mount_devfs(); =20 @@ -393,6 +418,20 @@ void __init prepare_namespace(void) if (initrd_load()) goto out; =20 + if (foobar) + sys_umount("/sys",0); + /* + * check if there is an early userspace init, if yes + */ + if (kinit_command && sys_access(kinit_command,0) =3D=3D 0) { + pid =3D kernel_thread(kinit_exec, kinit_command, SIGCHLD); + if (pid > 0) { + while (pid !=3D waitpid(-1, &i, 0)) + yield(); + } + goto out; + } + if (is_floppy && rd_doload && rd_load_disk(0)) ROOT_DEV =3D Root_RAM0; =20 diff -x initrd -x bin -x ash -x klibc -purNX /home/olaf/kernel/kernel_e= xclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/initramfs.c linuxppc-2= =2E5_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.00= 0000000 +0100 @@ -477,12 +477,17 @@ extern char __initramfs_start, __initram #include #endif =20 +extern int foobar; + void __init populate_rootfs(void) { char *err =3D unpack_to_rootfs(&__initramfs_start, &__initramfs_end - &__initramfs_start, 0); if (err) panic(err); + foobar =3D sys_mount("sys", "/sys","sysfs",NULL,NULL); + printk(" mount sysfs returned %ld\n", foobar); + foobar =3D !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_e= xclude.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.00= 0000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/init/main.c 2003-11-22 15:23:11.0000000= 00 +0100 @@ -471,6 +471,7 @@ asmlinkage void __init start_kernel(void } =20 int __initdata initcall_debug; +int foobar; =20 static int __init initcall_debug_setup(char *str) { @@ -534,6 +535,7 @@ static void __init do_basic_setup(void) sock_init(); =20 init_workqueues(); + init_elf_binfmt(); do_initcalls(); } =20 diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x sys= calls -x socketcalls klibc-0.81.orig/kinit/kinit.c klibc-0.81/kinit/kin= it.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; =20 for (i =3D 1; i < argc; i++) { - if (argv[i] && strncmp(argv[i], name, len) =3D=3D 0 && - (argv[i][len] =3D=3D '\0')) { - ret =3D argv[i] + len; - break; + if (argv[i] && strncmp(argv[i], name, len) =3D=3D 0) { + if (argv[i][len] =3D=3D '\0') { + ret =3D argv[i]; + break; + } else { + if (len && argv[i][len-1] =3D=3D '=3D') { + ret =3D argv[i] + len; + break; + } + } } } =20 diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x sys= calls -x socketcalls klibc-0.81.orig/klibc/Makefile klibc-0.81/klibc/Ma= kefile --- 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 =20 tests/%.shared : tests/%.o interp.o $(SOLIB) - $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBG= CC) + $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o $(SOLIB) $(LIBGCC) cp $@ $@.stripped $(STRIP) $@.stripped =20 diff -x ash -purNX /home/olaf/kernel/kernel_exclude.txt -x linux -x sys= calls -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.00000000= 0 +0200 +++ klibc-0.81/klibc/arch/ppc/MCONFIG 2003-11-22 13:43:53.000000000 +01= 00 @@ -9,3 +9,4 @@ =20 OPTFLAGS =3D -Os -fomit-frame-pointer BITSIZE =3D 32 +SHAREDFLAGS =3D -shared --=20 USB is for mice, FireWire is for men! sUse lINUX ag, n=C3=9CRNBERG - 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