Skip to contentSkip to conversation

2.6 early userspace init

PATCH Michael Schroeder 3 participants 5 messages Nov 12, 2003 – Nov 14, 2003

lore
Share & tools
lore
#0 lore raw

Hi folks,

how about adding something like this to init/do_mounts.c?

do_mounts.c renamed from do_mounts.c.orig +8 -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 */
 
@@ -393,6 +394,13 @@
 	if (initrd_load())
 		goto out;
 
+	/*
+	 * check if there is an early userspace init, if yes
+	 * let it do all the work
+	 */
+	if (sys_access("/sbin/init", 0) == 0)
+		goto out;
+
 	if (is_floppy && rd_doload && rd_load_disk(0))
 		ROOT_DEV = Root_RAM0;
 

I wont to be able to fetch the boot= parameter via /proc/cmdline in kinit and choose the boot devices, so I dislike the boot=0:0 suggestion.

Also, should the above code clear the init= parameter, i.e. main.c:execute_command?

Cheers,
Michael.

Signature · 2 lines
Michael Schroeder                                   [email protected]
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}
#1 lore raw
Quoted 1 line · Michael Schroeder

how about adding something like this to init/do_mounts.c?

It's not a bad idea, but surely you should be using the init= boot parameter instead of hard-coding a path.

In any case, I don't think you should expect a patch to be accepted. There's not much point in further crufting up do_mounts.c in generic kernels during 2.6, until do_mounts moves completely out of the kernel. Some people are happy enough with root=0:0, so there's not obviously a consensus about which stopgap measure will do for now.

	<b
#2 lore raw
Quoted 6 lines · Bryan O'Sullivan
Quoted 1 line · Michael Schroeder

how about adding something like this to init/do_mounts.c?

It's not a bad idea, but surely you should be using the init= boot parameter instead of hard-coding a path.

I'm not so sure about this. One can argue that the init= parameter should be evaluated by kinit when calling the real init.

Quoted 5 lines

In any case, I don't think you should expect a patch to be accepted. There's not much point in further crufting up do_mounts.c in generic kernels during 2.6, until do_mounts moves completely out of the kernel. Some people are happy enough with root=0:0, so there's not obviously a consensus about which stopgap measure will do for now.

Well, root=0:0 also needs a kernel patch and has the disadvantage that one cannot specify the desired root as a boot option.

The point is that it is impossible to use initramfs as a initrd replacement with the current code (2.6-test9), so one of the patches should go in, either the 0:0 patch or my patch.

Cheers,
Michael.

Signature · 2 lines
Michael Schroeder                                   [email protected]
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}
#3 lore raw
In reply to Bryan O'Sullivan
Followup to:  <[email protected]>
By author:    "Bryan O'Sullivan" <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 14 lines · Michael Schroeder
Quoted 2 lines

how about adding something like this to init/do_mounts.c?

It's not a bad idea, but surely you should be using the init= boot parameter instead of hard-coding a path.

In any case, I don't think you should expect a patch to be accepted. There's not much point in further crufting up do_mounts.c in generic kernels during 2.6, until do_mounts moves completely out of the kernel. Some people are happy enough with root=0:0, so there's not obviously a consensus about which stopgap measure will do for now.

I think it's useful to maintain bass-ackwards compatibility with root=, especially since if any hack is put it now, it creates new legacy.

Looking for init, or linuxrc, inside the initramfs makes sense. It should *NOT* be tied to the init= option, though... consider when all of this is pulled out of kernel space; you don't want "init=" to break finding your RAID volumes when you're trying to find a different "real" init binary.

Having a kinit= option (or earlyinit= or whatever, kinit seems to be the term we have been using) would be another matter, of course.

-hpa

Signature · 4 lines
<[email protected]> at work, <[email protected]> in private!
If you send me mail in HTML format I will assume it's spam.
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
#4 lore raw
Quoted 9 lines · H. Peter Anvin

I think it's useful to maintain bass-ackwards compatibility with root=, especially since if any hack is put it now, it creates new legacy.

Looking for init, or linuxrc, inside the initramfs makes sense. It should *NOT* be tied to the init= option, though... consider when all of this is pulled out of kernel space; you don't want "init=" to break finding your RAID volumes when you're trying to find a different "real" init binary.

Exactly. People may want to change the root partition with a root= option, so reserving root=0:0 to flag kinit booting is IMHO a bad idea. And init=/bin/bash should provide the user with a mounted root.

So, how's the following patch:

do_mounts.c renamed from do_mounts.c.orig +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 @@
 	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 @@
 	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;
 

It also adds a 'kinit' option for the brave users who really want to specify a diffenent kinit, e.g. 'ash'.

Of course, the kinit program should also be changed to check for a init=xxx parameter instead of kinit=xxx.

Cheers,
Michael.

Signature · 2 lines
Michael Schroeder                                   [email protected]
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}