All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olh@suse.de>
To: linux-fsdevel@vger.kernel.org
Subject: pivotroot does not work with initramfs
Date: Sun, 16 Nov 2003 18:04:38 +0100	[thread overview]
Message-ID: <20031116170438.GA4466@suse.de> (raw)


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    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.


diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/fs/binfmt_elf.c linuxppc-2.5_2.6.0-test9-bk/fs/binfmt_elf.c
--- linuxppc-2.5_2.6.0-test9-bk.orig/fs/binfmt_elf.c	2003-10-22 07:10:08.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/fs/binfmt_elf.c	2003-11-15 19:01:38.000000000 +0100
@@ -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");
diff -x bin -x ash -x klibc-0.81 -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-15 11:53:12.000000000 +0100
@@ -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;
 
diff -x bin -x ash -x klibc-0.81 -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-16 03:33:10.000000000 +0100
@@ -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;
 		}
diff -x bin -x ash -x klibc-0.81 -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-16 17:18:42.000000000 +0100
@@ -534,6 +534,7 @@ static void __init do_basic_setup(void)
 	sock_init();
 
 	init_workqueues();
+	init_elf_binfmt();
 	do_initcalls();
 }
 
diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclude.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.000000000 +0100
@@ -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')
diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclude.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.000000000 +0200
+++ linuxppc-2.5_2.6.0-test9-bk/usr/Makefile	2003-11-16 15:58:53.000000000 +0100
@@ -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
diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclude.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.000000000 +0100
@@ -197,6 +197,7 @@ void cpio_mkfile(const char *filename, c
 
 	for (i = 0; i < buf.st_size; ++i)
 		fputc(filebuf[i], stdout);
+	offset += buf.st_size;
 	close(file);
 	free(filebuf);
 	push_pad();
@@ -212,9 +213,51 @@ error:
 
 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();
 
 	exit(0);
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
diff -x bin -x ash -x klibc-0.81 -purNX /home/olaf/kernel/kernel_exclude.txt linuxppc-2.5_2.6.0-test9-bk.orig/usr/mounts linuxppc-2.5_2.6.0-test9-bk/usr/mounts
--- linuxppc-2.5_2.6.0-test9-bk.orig/usr/mounts	1970-01-01 01:00:00.000000000 +0100
+++ linuxppc-2.5_2.6.0-test9-bk/usr/mounts	2003-11-16 03:49:04.000000000 +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_exclude.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.000000000 +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 linuxppc-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_exclude.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:00: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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define BUFSIZE 12345
+int
+main(int argc, char **argv, char **envp)
+{
+	int fd, i;
+	char **ep = envp;
+	char *buf, *p;
+	sleep(42);
+	buf = malloc(42);
+	if (!buf)
+		exit(1);
+	p = getenv("SEQNUM");
+	snprintf(buf, 42, "/udev/x/dbg.%08u.%s", getpid(), p ? p : "");
+	if ((fd = open(buf, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) {
+		//perror(buf);
+		exit(1);
+	}
+	free(buf);
+	p = malloc(BUFSIZE);
+	buf = p;
+	for (i = 0; i < argc; ++i) {
+		buf += snprintf(buf, p + BUFSIZE - buf, " %s", argv[i]);
+		if (buf > p + BUFSIZE)
+			goto full;
+	}
+	buf += snprintf(buf, p + BUFSIZE - buf, "\n");
+	if (buf > p + BUFSIZE)
+		goto full;
+	while (*ep) {
+		buf += snprintf(buf, p + BUFSIZE - buf, "%s\n", *ep++);
+		if (buf > p + BUFSIZE)
+			break;
+	}
+      full:
+	buf = 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 linuxppc-2.5_2.6.0-test9-bk/usr/sbin/udev differ
-- 
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

             reply	other threads:[~2003-11-16 17:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-16 17:04 Olaf Hering [this message]
2003-11-19 23:49 ` pivotroot does not work with initramfs Greg KH
2003-11-22 16:46 ` Olaf Hering
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=20031116170438.GA4466@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.