From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Subject: pivotroot does not work with initramfs Date: Sun, 16 Nov 2003 18:04:38 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <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]:19159 "EHLO Cantor.suse.de") by vger.kernel.org with ESMTP id S263060AbTKPREk (ORCPT ); Sun, 16 Nov 2003 12:04:40 -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 3ED5F17FE857 for ; Sun, 16 Nov 2003 18:04:39 +0100 (CET) To: linux-fsdevel@vger.kernel.org Content-Disposition: inline List-Id: linux-fsdevel.vger.kernel.org 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_remount c003dc7c __alloc_pages c0074cf0 do_mount c007511c sys_mount c000782c 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 No= t tainted MSR: 00009030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11 TASK =3D c4624080[160] 'mount' Last syscall: 21 GPR00: C47F54A0 C050DE70 C4624080 C47F5FA0 00000000 00000000 C471F000 C= 471F000 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 =3D c0073684, lr =3D c0074584 msr =3D 9030, sp =3D c050de70 [c050ddc0] current =3D c4624080, pid =3D 160, comm =3D mount mon> t backtrace: c003dc7c=20 c0074cf0=20 c007511c=20 c000782c=20 exception:c01 [c050df50] ff85abc=20 10002608=20 10003bb8=20 10003ec0=20 10004ef8=20 0febfce4=20 00000000=20 mon>=20 Total memory =3D 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. diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/fs/binfmt_elf.c linuxppc-2.5_2.6= =2E0-test9-bk/fs/binfmt_elf.c --- linuxppc-2.5_2.6.0-test9-bk.orig/fs/binfmt_elf.c 2003-10-22 07:10:0= 8.000000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/fs/binfmt_elf.c 2003-11-15 19:01:38.000= 000000 +0100 @@ -1449,7 +1449,7 @@ cleanup: =20 #endif /* USE_ELF_CORE_DUMP */ =20 -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); } =20 -module_init(init_elf_binfmt) +EXPORT_SYMBOL(init_elf_binfmt); module_exit(exit_elf_binfmt) MODULE_LICENSE("GPL"); diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.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-15 11:53:12.00= 0000000 +0100 @@ -14,6 +14,7 @@ #include "do_mounts.h" =20 extern int get_filesystem_list(char * buf); +extern asmlinkage long sys_access(const char * filename, int mode); =20 int __initdata rd_doload; /* 1 =3D load RAM disk, 0 =3D don't load */ =20 @@ -370,6 +371,17 @@ void __init mount_root(void) mount_block_root("/dev/root", root_mountflags); } =20 +static char *kinit_command; + +static int __init kinit_setup(char *str) +{ + kinit_command =3D str; + return 1; +} + +__setup("kinit=3D", 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; =20 + /* + * check if there is an early userspace init, if yes + * let it do all the work + */ + if (kinit_command || sys_access("/sbin/init", 0) =3D=3D 0) { + extern char *execute_command; + execute_command =3D kinit_command ? kinit_command : 0; + goto out; + } + if (is_floppy && rd_doload && rd_load_disk(0)) ROOT_DEV =3D Root_RAM0; =20 diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.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-16 03:33:10.00= 0000000 +0100 @@ -100,11 +100,11 @@ static void __init parse_header(char *s) { unsigned long parsed[12]; char buf[9]; - int i; + int i,j=3D1; =20 buf[8] =3D '\0'; for (i =3D 0, s +=3D 6; i < 12; i++, s +=3D 8) { - memcpy(buf, s, 8); + memcpy(buf, s, 7 + j); parsed[i] =3D simple_strtoul(buf, NULL, 16); } ino =3D 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","sysf= s",NULL,NULL)); free_initrd_mem(initrd_start, initrd_end); return; } diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/init/main.c linuxppc-2.5_2.6.0-t= est9-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-16 17:18:42.0000000= 00 +0100 @@ -534,6 +534,7 @@ static void __init do_basic_setup(void) sock_init(); =20 init_workqueues(); + init_elf_binfmt(); do_initcalls(); } =20 diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/kernel/kmod.c linuxppc-2.5_2.6.0= -test9-bk/kernel/kmod.c --- linuxppc-2.5_2.6.0-test9-bk.orig/kernel/kmod.c 2003-10-22 07:10:02.= 000000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/kernel/kmod.c 2003-11-16 04:49:55.00000= 0000 +0100 @@ -249,7 +249,7 @@ int call_usermodehelper(char *path, char }; DECLARE_WORK(work, __call_usermodehelper, &sub_info); =20 - if (!system_running) + if (0 && !system_running) return -EBUSY; =20 if (path[0] =3D=3D '\0') diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/Makefile linuxppc-2.5_2.6.0-= test9-bk/usr/Makefile --- linuxppc-2.5_2.6.0-test9-bk.orig/usr/Makefile 2003-08-04 01:59:27.0= 00000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/usr/Makefile 2003-11-16 15:58:53.000000= 000 +0100 @@ -3,7 +3,14 @@ obj-y :=3D initramfs_data.o =20 host-progs :=3D gen_init_cpio =20 -clean-files :=3D initramfs_data.cpio.gz +clean-files :=3D 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 + =20 # 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. =20 # Commented out for now -# initramfs-y :=3D $(obj)/root/hello +initramfs-y :=3D $(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 $(o= bj)/myinit.sh $(obj)/sbin/hotplug $(obj)/sbin/udev /bin/sash + =20 quiet_cmd_cpio =3D CPIO $@ cmd_cpio =3D ./$< > $@ @@ -28,6 +36,7 @@ targets +=3D initramfs_data.cpio =20 $(obj)/initramfs_data.cpio.gz: $(obj)/initramfs_data.cpio FORCE $(call if_changed,gzip) + /bin/gzip -cd $@ | cpio -vt =20 targets +=3D initramfs_data.cpio.gz =20 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 diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/gen_init_cpio.c linuxppc-2.5= _2.6.0-test9-bk/usr/gen_init_cpio.c --- linuxppc-2.5_2.6.0-test9-bk.orig/usr/gen_init_cpio.c 2003-09-07 05:= 58:23.000000000 +0200 +++ linuxppc-2.5_2.6.0-test9-bk/usr/gen_init_cpio.c 2003-11-16 15:59:09= =2E000000000 +0100 @@ -197,6 +197,7 @@ void cpio_mkfile(const char *filename, c =20 for (i =3D 0; i < buf.st_size; ++i) fputc(filebuf[i], stdout); + offset +=3D buf.st_size; close(file); free(filebuf); push_pad(); @@ -212,9 +213,51 @@ error: =20 int main (int argc, char *argv[]) { + cpio_mkdir("/etc", 0755, 0, 0); + cpio_mkdir("/etc/udev", 0755, 0, 0); cpio_mkdir("/dev", 0755, 0, 0); - cpio_mknod("/dev/console", 0600, 0, 0, 'c', 5, 1); - cpio_mkdir("/root", 0700, 0, 0); + cpio_mknod("/dev/console", 0600, 0, 0, 'c', 5, 1); + cpio_mknod("/dev/null", 0600, 0, 0, 'c', 1, 3); + cpio_mknod("/dev/zero", 0600, 0, 0, 'c', 1, 5); + cpio_mknod("/dev/ram0", 0600, 0, 0, 'b', 1, 0); + cpio_mkdir("/fw", 0700, 0, 0); + cpio_mkdir("/mnt", 0700, 0, 0); + cpio_mkdir("/proc", 0700, 0, 0); + cpio_mkdir("/sys", 0700, 0, 0); + cpio_mkdir("/bin", 0700, 0, 0); + cpio_mkdir("/sbin", 0700, 0, 0); + cpio_mkdir("/tmp", 0700, 0, 0); + cpio_mkdir("/udev", 0700, 0, 0); + cpio_mkfile("usr/mounts", "/proc/mounts", 0700, 0, 0); +#if 0 + cpio_mkfile("usr/sbin/hotplug", "/sbin/hotplug", 0700, 0, 0); + cpio_mkfile("usr/sbin/udev", "/bin/udev", 0700, 0, 0); +#else + cpio_mkfile("usr/sbin/udev", "/sbin/hotplug", 0700, 0, 0); +#endif + cpio_mkfile("usr/busybox", "/bin/bb", 0700, 0, 0); +#if 0 + cpio_mkfile("/bin/sash", "/sbin/init", 0700, 0, 0); + cpio_mkfile("usr/ash/sh.static", "/bin/sh", 0700, 0, 0); +#else + cpio_mkfile("usr/ash/sh.static", "/bin/ash", 0700, 0, 0); + cpio_mkfile("/bin/sash", "/bin/sash", 0700, 0, 0); +#endif +#if 0 + cpio_mkfile("usr/bin/dd","/bin/dd",0700,0,0); + cpio_mkfile("usr/bin/fstype","/bin/fstype",0700,0,0); + cpio_mkfile("usr/bin/mkdir","/bin/mkdir",0700,0,0); + cpio_mkfile("usr/bin/mkfifo","/bin/mkfifo",0700,0,0); +#endif +#if 1 + cpio_mkfile("usr/bin/mount","/bin/mount",0700,0,0); + cpio_mkfile("usr/bin/umount","/bin/umount",0700,0,0); +#endif +#if 1 + cpio_mkfile("usr/bin/chroot","/bin/chroot",0700,0,0); + cpio_mkfile("usr/bin/pivot_root","/bin/pivot_root",0700,0,0); +#endif + cpio_mkfile("usr/myinit.sh", "/sbin/init", 0700, 0, 0); cpio_trailer(); =20 exit(0); Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/initramfs_data.cpio a= nd linuxppc-2.5_2.6.0-test9-bk/usr/initramfs_data.cpio differ diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/mounts linuxppc-2.5_2.6.0-te= st9-bk/usr/mounts --- linuxppc-2.5_2.6.0-test9-bk.orig/usr/mounts 1970-01-01 01:00:00.000= 000000 +0100 +++ linuxppc-2.5_2.6.0-test9-bk/usr/mounts 2003-11-16 03:49:04.00000000= 0 +0100 @@ -0,0 +1,3 @@ +rootfs / rootfs rw 0 0 +sys /sys sysfs rw 0 0 +proc /proc proc rw 0 0 diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/myinit.sh linuxppc-2.5_2.6.0= -test9-bk/usr/myinit.sh --- linuxppc-2.5_2.6.0-test9-bk.orig/usr/myinit.sh 1970-01-01 01:00:00.= 000000000 +0100 +++ linuxppc-2.5_2.6.0-test9-bk/usr/myinit.sh 2003-11-16 17:04:04.00000= 0000 +0100 @@ -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 linu= xppc-2.5_2.6.0-test9-bk/usr/sbin/hotplug differ diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclud= e.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/sbin/hotplug.c linuxppc-2.5_= 2.6.0-test9-bk/usr/sbin/hotplug.c --- linuxppc-2.5_2.6.0-test9-bk.orig/usr/sbin/hotplug.c 1970-01-01 01:0= 0:00.000000000 +0100 +++ linuxppc-2.5_2.6.0-test9-bk/usr/sbin/hotplug.c 2003-11-15 21:01:49.= 000000000 +0100 @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include + +#define BUFSIZE 12345 +int +main(int argc, char **argv, char **envp) +{ + int fd, i; + char **ep =3D envp; + char *buf, *p; + sleep(42); + buf =3D malloc(42); + if (!buf) + exit(1); + p =3D getenv("SEQNUM"); + snprintf(buf, 42, "/udev/x/dbg.%08u.%s", getpid(), p ? p : ""); + if ((fd =3D open(buf, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) { + //perror(buf); + exit(1); + } + free(buf); + p =3D malloc(BUFSIZE); + buf =3D p; + for (i =3D 0; i < argc; ++i) { + buf +=3D snprintf(buf, p + BUFSIZE - buf, " %s", argv[i]); + if (buf > p + BUFSIZE) + goto full; + } + buf +=3D snprintf(buf, p + BUFSIZE - buf, "\n"); + if (buf > p + BUFSIZE) + goto full; + while (*ep) { + buf +=3D snprintf(buf, p + BUFSIZE - buf, "%s\n", *ep++); + if (buf > p + BUFSIZE) + break; + } + full: + buf =3D p; + write(fd, buf, strlen(buf)); + close(fd); + free(buf); + return 0; +} Binary files linuxppc-2.5_2.6.0-test9-bk.orig/usr/sbin/udev and linuxpp= c-2.5_2.6.0-test9-bk/usr/sbin/udev differ --=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