public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* pivotroot does not work with initramfs
@ 2003-11-16 17:04 Olaf Hering
  2003-11-19 23:49 ` Greg KH
  2003-11-22 16:46 ` Olaf Hering
  0 siblings, 2 replies; 6+ messages in thread
From: Olaf Hering @ 2003-11-16 17:04 UTC (permalink / raw)
  To: linux-fsdevel


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pivotroot does not work with initramfs
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2003-11-19 23:49 UTC (permalink / raw)
  To: Olaf Hering; +Cc: linux-fsdevel

On Sun, Nov 16, 2003 at 06:04:38PM +0100, 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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pivotroot does not work with initramfs
  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
  2003-11-22 20:48   ` Olaf Hering
  1 sibling, 1 reply; 6+ messages in thread
From: Olaf Hering @ 2003-11-22 16:46 UTC (permalink / raw)
  To: linux-fsdevel

 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pivotroot does not work with initramfs
  2003-11-22 16:46 ` Olaf Hering
@ 2003-11-22 20:48   ` Olaf Hering
  2003-11-22 21:50     ` viro
  0 siblings, 1 reply; 6+ messages in thread
From: Olaf Hering @ 2003-11-22 20:48 UTC (permalink / raw)
  To: linux-fsdevel

 On Sat, Nov 22, Olaf Hering wrote:

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

This seems to cure it.

--- 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 21:46:27.000000000 +0100
@@ -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);



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pivotroot does not work with initramfs
  2003-11-22 20:48   ` Olaf Hering
@ 2003-11-22 21:50     ` viro
  2003-11-25 20:02       ` Olaf Hering
  0 siblings, 1 reply; 6+ messages in thread
From: viro @ 2003-11-22 21:50 UTC (permalink / raw)
  To: Olaf Hering; +Cc: linux-fsdevel, Linus Torvalds

On Sat, Nov 22, 2003 at 09:48:54PM +0100, Olaf Hering wrote:
> --- 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 21:46:27.000000000 +0100
> @@ -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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pivotroot does not work with initramfs
  2003-11-22 21:50     ` viro
@ 2003-11-25 20:02       ` Olaf Hering
  0 siblings, 0 replies; 6+ messages in thread
From: Olaf Hering @ 2003-11-25 20:02 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, Linus Torvalds

 On Sat, Nov 22, viro@parcelfarce.linux.theplanet.co.uk wrote:

> On Sat, Nov 22, 2003 at 09:48:54PM +0100, Olaf Hering wrote:
> > --- 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 21:46:27.000000000 +0100
> > @@ -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.

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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-11-25 20:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2003-11-22 20:48   ` Olaf Hering
2003-11-22 21:50     ` viro
2003-11-25 20:02       ` Olaf Hering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox