pivotroot does not work with initramfs
Subsystems (3)
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.
calltrace is:c0073684 check_mnt
c0074584 do_remountc003dc7c __alloc_pagesc0074cf0 do_mountc007511c sys_mountc000782c ret_from_syscall
#+ mount -t ext2 -o ro /udev/sda8 /mnt
+ umount /sys
+ cd /mnt
+ /bin/pivot_root . fw
+ chroot . /bin/bash --login
(none):/# mount -noremount,rw / NIP: C0073684 LR: C0074584 SP: C050DE70 REGS: c050ddc0 TRAP: 0501 Not tainted MSR: 00009030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11 TASK = c4624080[160] 'mount' Last syscall: 21 GPR00: C47F54A0 C050DE70 C4624080 C47F5FA0 00000000 00000000 C471F000 C471F000 GPR08: 00000000 00000001 FFFFFFFF C47F5FA0 99000535 Call trace: [c0074cf0] do_mount+0x15c/0x168 [c007511c] sys_mount+0xc8/0xf8 [c000782c] ret_from_syscall+0x0/0x4c Serial port locked ON by debugger ! Keyboard interrupt vector: 501 at pc = c0073684, lr = c0074584 msr = 9030, sp = c050de70 [c050ddc0] current = c4624080, pid = 160, comm = mount mon> t backtrace: c003dc7c c0074cf0 c007511c c000782c exception:c01 [c050df50] ff85abc 10002608 10003bb8 10003ec0 10004ef8 0febfce4 00000000 mon>
Total memory = 72MB; using 256kB for hash table (at c0380000)
Linux version 2.6.0-test9-7200 (builds@ibook) (gcc version 3.2.3 (SuSE Linux)) #143 Sun Nov 16 17:26:06 CET 2003
I use this script as /sbin/init for kinit:
#! /bin/ash
set -x
#mount -t proc proc /proc
#bb mkfs.minix /udev/ram0
#bb mv /dev/zero /dev/null /dev/console /udev
#mount -t minix /udev/ram0 /dev
#bb mv /udev/* /dev
#bb mkfs.minix /dev/ram1
mount -t ext2 -o ro /udev/sda8 /mnt
#mount -t minix /dev/ram1 /mnt/root
umount /sys
#umount /proc
#bb mv /dev/* /mnt/root/
#umount /dev
#umount /mnt/root
cd /mnt
#bb cat proc/mounts/bin/pivot_root . fw
#exec
chroot . /bin/bash --login
echo done
I have to use this patch to make udev happy.
fs/binfmt_elf.c +2 -2
@@ -1449,7 +1449,7 @@ cleanup:#endif /* USE_ELF_CORE_DUMP */ -static int __init init_elf_binfmt (void ) +int init_elf_binfmt (void ) {return register_binfmt (&elf_format); }
@@ -1460,6 +1460,6 @@ static void __exit exit_elf_binfmt(void)unregister_binfmt (&elf_format); } -module_init(init_elf_binfmt) +EXPORT_SYMBOL (init_elf_binfmt); module_exit(exit_elf_binfmt) MODULE_LICENSE("GPL");
init/do_mounts.c +22 -0
@@ -14,6 +14,7 @@#include "do_mounts.h" extern int get_filesystem_list (char * buf); +extern asmlinkage long sys_access (const char * filename,int mode);int __initdata rd_doload;/* 1 = load RAM disk, 0 = don't load */
@@ -370,6 +371,17 @@ void __init mount_root(void)mount_block_root ("/dev/root" , root_mountflags); } +static char *kinit_command; + +static int __init kinit_setup (char *str) +{ + kinit_command = str; +return 1 ; +} + +__setup ("kinit=" , kinit_setup); + +/* * Prepare the namespace - decide what/where to mount, load ramdisks, etc. */
@@ -393,6 +405,16 @@ void __init prepare_namespace(void)if (initrd_load ()) goto out; +/* +* check if there is an early userspace init, if yes +* let it do all the work +*/ +if (kinit_command ||sys_access ("/sbin/init" ,0 ) ==0 ) { +extern char *execute_command; + execute_command = kinit_command ? kinit_command :0 ; + goto out; + } +if (is_floppy && rd_doload &&rd_load_disk (0 ))ROOT_DEV = Root_RAM0;
init/initramfs.c +3 -2
@@ -100,11 +100,11 @@ static void __init parse_header(char *s) {unsigned long parsed[12 ];char buf[9 ]; -int i; +int i,j=1 ; buf[8 ] ='\0' ;for (i =0 , s +=6 ; i <12 ; i++, s +=8 ) { -memcpy (buf, s,8 ); +memcpy (buf, s,7 + j); parsed[i] =simple_strtoul (buf,NULL ,16 ); } ino = parsed[0 ];
@@ -493,6 +493,7 @@ void __init populate_rootfs(void)printk (" it is\n" );unpack_to_rootfs ((char *)initrd_start, initrd_end - initrd_start,0 ); +printk (" mount sysfs returned %ld\n" ,sys_mount ("sys" ,"/sys" ,"sysfs" ,NULL ,NULL ));free_initrd_mem (initrd_start, initrd_end);return ; }
init/main.c +1 -0
@@ -534,6 +534,7 @@ static void __init do_basic_setup(void)sock_init ();init_workqueues (); +init_elf_binfmt ();do_initcalls (); }
kernel/kmod.c +1 -1
@@ -249,7 +249,7 @@ int call_usermodehelper(char *path, char };DECLARE_WORK (work, __call_usermodehelper, &sub_info); -if (!system_running) +if (0 && !system_running)return -EBUSY ;if (path[0 ] =='\0' )
usr/Makefile +11 -2
@@ -3,7 +3,14 @@ obj-y := initramfs_data.o host-progs := gen_init_cpio -clean-files := initramfs_data.cpio.gz +clean-files := initramfs_data.cpio.gz sbin/hotplug + +$(obj)/ash/sh.static: $(obj)/ash/Makefile + cd $(obj)/ash ; make + +$(obj)/sbin/hotplug: $(obj)/sbin/hotplug.c + diet gcc -Wall -o $@ -Os $< -s -static + # initramfs_data.o contains the initramfs_data.cpio.gz image. # The image is included using .incbin, a dependency which is not
@@ -16,7 +23,8 @@ $(obj)/initramfs_data.o: $(obj)/initramf # here. # Commented out for now -# initramfs-y := $(obj)/root/hello +initramfs-y := $(obj)/ash/sh.static $(obj)/bin/chroot $(obj)/bin/dd $(obj)/bin/fstype $(obj)/bin/mkdir $(obj)/bin/mkfifo $(obj)/bin/mount $(obj)/bin/pivot_root $(obj)/bin/umount $(obj)/busybox $(obj)/mounts $(obj)/myinit.sh $(obj)/sbin/hotplug $(obj)/sbin/udev /bin/sash + quiet_cmd_cpio = CPIO $@ cmd_cpio = ./$< > $@
@@ -28,6 +36,7 @@ targets += initramfs_data.cpio $(obj)/initramfs_data.cpio.gz: $(obj)/initramfs_data.cpio FORCE $(call if_changed,gzip) + /bin/gzip -cd $@ | cpio -vt targets += initramfs_data.cpio.gz
Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/busybox and linuxppc-2.5_2.6.0-test9-bk/usr/busybox differ
usr/gen_init_cpio.c +45 -2
60 lines not on this page · raw message
Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/initramfs_data.cpio and linuxppc-2.5_2.6.0-test9-bk/usr/initramfs_data.cpio differ
usr/mounts +3 -0
@@ -0,0 +1,3 @@ +rootfs / rootfs rw 0 0 +sys /sys sysfs rw 0 0 +proc /proc proc rw 0 0
usr/myinit.sh +21 -0
@@ -0,0 +1,21 @@ +#! /bin/ash +set -x +#mount -t proc proc /proc +#bb mkfs.minix /udev/ram0 +#bb mv /dev/zero /dev/null /dev/console /udev +#mount -t minix /udev/ram0 /dev +#bb mv /udev/* /dev +#bb mkfs.minix /dev/ram1 +mount -t ext2 -o ro /udev/sda8 /mnt +#mount -t minix /dev/ram1 /mnt/root +umount /sys +#umount /proc +#bb mv /dev/* /mnt/root/ +#umount /dev +#umount /mnt/root +cd /mnt +#bb cat proc/mounts +/bin/pivot_root . fw +#exec +chroot . /bin/bash --login +echo done
Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/sbin/hotplug and linuxppc-2.5_2.6.0-test9-bk/usr/sbin/hotplug differ
usr/sbin/hotplug.c +47 -0
47 lines not on this page · raw message
Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/sbin/udev and linuxppc-2.5_2.6.0-test9-bk/usr/sbin/udev differ
Signature · 7 lines
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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Olaf Hering
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.
See the klibc mailing list for examples of people using initramfs and pivotroot properly together. They have done it successfully.
good luck,
greg k-h
Quoted 4 lines · Olaf Hering
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:
fs/namespace.c +5 -0
@@ -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; }
init/do_mounts.c +39 -0
@@ -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;
init/initramfs.c +5 -0
@@ -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;
init/main.c +2 -0
@@ -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 (); }
kinit/kinit.c +10 -4
@@ -181,10 +181,16 @@ char *get_arg(int argc, char *argv[], coint 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 ; + } + } } }
klibc/Makefile +1 -1
@@ -61,7 +61,7 @@ tests/% : tests/%.o $(LIB) $(CRT0) $(STRIP) [email protected] 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 $@ [email protected] $(STRIP) [email protected]
klibc/arch/ppc/MCONFIG +1 -0
@@ -9,3 +9,4 @@ OPTFLAGS = -Os -fomit-frame-pointer BITSIZE = 32 +SHAREDFLAGS = -shared
Signature · 7 lines
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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 16 lines · Olaf Hering
Quoted 4 lines · Olaf Hering
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_rootand returns.prepare_namespace()doessys_mount(".", "/", NULL, MS_MOVE, NULL);
which leads to this loop:
Quoted 7 lines
check_mnt(103)+ swapper
c47f51e0c47f54a0
0c47f51e0192.168.1.2:/nfsroot/macc47f54a0rootfs 1c47f54a0rootfsc47f51e0192.168.1.2:/nfsroot/mac 2c47f51e0192.168.1.2:/nfsroot/macc47f54a0rootfs 3c47f54a0rootfsc47f51e0192.168.1.2:/nfsroot/mac 4c47f51e0192.168.1.2:/nfsroot/macc47f54a0rootfs
...
This seems to cure it.
fs/namespace.c 2003-11-22 21:46:27.000000000 +0100 renamed from fs/namespace.c 2003-10-08 03:52:02.000000000 +0200 +1 -0
@@ -99,6 +99,7 @@ EXPORT_SYMBOL(lookup_mnt); static int check_mnt(struct vfsmount *mnt) { spin_lock(&vfsmount_lock); + if(mnt->mnt_parent->mnt_parent != mnt) while (mnt->mnt_parent != mnt) mnt = mnt->mnt_parent; spin_unlock(&vfsmount_lock);
Signature · 7 lines
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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
fs/namespace.c 2003-11-22 21:46:27.000000000 +0100 EXPORT_SYMBOL(lookup_mnt); · line 105
Quoted 10 lines · Olaf Hering
fs/namespace.c 2003-11-22 21:46:27.000000000 +0100 renamed from fs/namespace.c 2003-10-08 03:52:02.000000000 +0200 +1
-0@@ -99,6 +99,7 @@ EXPORT_SYMBOL(lookup_mnt); static int check_mnt(struct vfsmount *mnt) { spin_lock(&vfsmount_lock); + if(mnt->mnt_parent->mnt_parent != mnt) while (mnt->mnt_parent != mnt) mnt = mnt->mnt_parent; spin_unlock(&vfsmount_lock);
That's just plain ugly. Could you explain what the hell are you trying to do?
If it's an attempt to make pivot_root move rootfs somewhere else - the above is nowhere near enough. If it's something else, I wonder how the could that patch change anything.
*NOTE*: attempting to move rootfs away from root of mount tree is unsupported and for a good reason - it complicates logics big way and doesn't buy you anything that couldn't be done without it.
Quoted 15 lines · On Sat, Nov 22, [email protected] wrote:
fs/namespace.c 2003-11-22 21:46:27.000000000 +0100 EXPORT_SYMBOL(lookup_mnt); · line 105
Quoted 10 lines · Olaf Hering
fs/namespace.c 2003-11-22 21:46:27.000000000 +0100 renamed from fs/namespace.c 2003-10-08 03:52:02.000000000 +0200 +1
-0@@ -99,6 +99,7 @@ EXPORT_SYMBOL(lookup_mnt); static int check_mnt(struct vfsmount *mnt) { spin_lock(&vfsmount_lock); + if(mnt->mnt_parent->mnt_parent != mnt) while (mnt->mnt_parent != mnt) mnt = mnt->mnt_parent; spin_unlock(&vfsmount_lock);That's just plain ugly. Could you explain what the hell are you trying to do?
Quoted 7 lines
If it's an attempt to make
pivot_rootmove rootfs somewhere else - the above is nowhere near enough. If it's something else, I wonder how the could that patch change anything.*NOTE*: attempting to move rootfs away from root of mount tree is unsupported and for a good reason - it complicates logics big way and doesn't buy you anything that couldn't be done without it.
Ok, so pivot_root on rootfs is a bad idea. What I do now is to just look for a /sbin/kinit binary (or something that is passed via kinit=) and run this. And skip the call to mount_root() in prepare_namespace(). Seems to work well.
kinit is supposed to find and mount the final root filesystem and mount it on /root. Then return and let prepare_namespace() do the final work, free the initmem and run the init process.
I dont know what you have in mind for 2.7, how much of the code will disappear. We will hopefully use initramfs via cpio for 2.6 and get rid of linuxrc. Lets see how far we get with that plan.
Signature · 7 lines
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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html