Skip to contentSkip to conversation

chroot= as a new kernel parameter

PATCH In review Pawel Plociennik 8 participants 20 messages Mar 1, 2008 – Mar 5, 2008 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chroot= as a new kernel parameter

hi *real* hackers,

it is a my first post to lkml and I hope that you will have not been ignored me if I have done some incorrect thing.

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed. I use that for testing variouses distroes without making a separate partition but by copied a new root-fs to a new subdirectory on the my *base* filesystem.

PS: be sure that you have added my e-mail in a CC because I am not subscribed to the lkml and ...
I sorry but my English can be little incorrect because it is not my *native* language :-( please do not ignore me if I have been done some inccorect thing.

Documentation/kernel-parameters.txt +2 -0
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 	
+	chroot=		[KNL] call chroot() for init proccess.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used
init/main.c +14 -0
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
@@ -755,8 +755,22 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if(chroot_str) {
+		if(sys_chroot(chroot_str) < 0)
+			printk("chroot=%s failed\n", chroot_str);
+		else
+			printk("chroot=%s successed\n",chroot_str);
+	}
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
#1 lore raw
Quoted 3 lines · Pawel Plociennik

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed.

Hey, this is cool, I've wanted something like this for a long time. However, I was thinking of implementing it in mkinitrd, not in the kernel proper.

OT1H, having it in the kernel proper makes it easier to support even on distros whose mkinitrd doesn't support this stuff, or that don't even use an initrd. OTOH, having it in mkinitrd means you can use this even on distros whose kernels don't support chroot=.

And then, given that booting up a kernel from one distro on another requires setting up /lib/modules for proper functioning (unless your mkinitrd does that for you, which is something else I've been thinking of doing for similar reasons), I figured changing mkinitrd might be a better way to go.

Signature · 4 lines
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
#2 lore raw
In reply to Pawel Plociennik
Quoted 9 lines · Pawel Plociennik

hi *real* hackers,

it is a my first post to lkml and I hope that you will have not been ignored me if I have done some incorrect thing.

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed. I use that for testing variouses distroes without making a separate partition but by copied a new root-fs to a new subdirectory on the my *base* filesystem.

Hi!

Gentoos initrd (build by genkernel) has support for a chrooted boot, the parameter is called subdir=
Maybe other distros have something similar, it's easy to support this with a initrd/initramfs.

Cheers
Stefan

PS: This is my first post to lkml, too :)

#3 lore raw
Quoted 11 lines · Stefan Hellermann
Quoted 9 lines · Pawel Plociennik

hi *real* hackers,

it is a my first post to lkml and I hope that you will have not been ignored me if I have done some incorrect thing.

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed. I use that for testing variouses distroes without making a separate partition but by copied a new root-fs to a new subdirectory on the my *base* filesystem.

Quoted 5 lines

Hi!

Gentoos initrd (build by genkernel) has support for a chrooted boot, the parameter is called subdir=
Maybe other distros have something similar, it's easy to support this with a initrd/initramfs.

Hey!

Im a simple guy though, i prefer this being in the kernel. I do not even use an initramfs.

Quoted 10 lines

Cheers
Stefan

PS: This is my first post to lkml, too :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to Pawel Plociennik

Hi!

Quoted 1 line

hi *real* hackers,

:-).

Quoted 7 lines

it is a my first post to lkml and I hope that you will have not been ignored me if I have done some incorrect thing.

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed. I use that for testing variouses distroes without making a separate partition but by copied a new root-fs to a new subdirectory on the my *base* filesystem.

Yes please. I was thinking about doing this long ago, but never got to coding it.

Quoted 20 lines

diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt +2 -0
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 
+	chroot=		[KNL] call chroot() for init proccess.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used

diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c

init/main.c +1 -0
@@ -755,8 +755,22 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;

init/main.c static void __init do_pre_smp_initcalls( · line 768

Quoted 10 lines
init/main.c +8 -0
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if(chroot_str) {

'if ('

init/main.c static void __init do_pre_smp_initcalls( · line 769

Quoted 1 line
init/main.c +1 -0
+		if(sys_chroot(chroot_str) < 0)

here too.

init/main.c static void __init do_pre_smp_initcalls( · line 772

Quoted 3 lines
init/main.c +3 -0
+			printk("chroot=%s failed\n", chroot_str);
+		else
+			printk("chroot=%s successed\n",chroot_str);

And I do not think we want to printk in the success case.

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#5 lore raw
In reply to Pawel Plociennik

Pawel Plociennik ha scritto:

Quoted 1 line

hi *real* hackers,

(...)

Documentation/kernel-parameters.txt and is between 256 and 4096 characters. · line 384

Quoted 8 lines

diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt +1 -0
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 
+	chroot=		[KNL] call chroot() for init proccess.

Isn't the called function 'sys_chroot()'?

(...)

Documentation/kernel-parameters.txt and is between 256 and 4096 characters. · line 386

Quoted 2 lines
Documentation/kernel-parameters.txt +2 -0
+		if(sys_chroot(chroot_str) < 0)
+			printk("chroot=%s failed\n", chroot_str);

Thanks.

Signature · 9 lines
Filippo Zangheri

GPG key ID: 0xE1D879FA
Key fingerprint: 816B CE57 D43C 0A47 EF35 3378 EA5F A72A E1D8 79FA
Key server: pgp.mit.edu

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE d- s+:- a-- C++ UL+++ P+ L+++ E-- W+ N* o-- K- w--- O-- M--  V- PS++ PE+ Y+ PGP++ t 5-- X++ R* tv b+ DI-- D---- G-- e++ h--  r++ z*                                                          ------END GEEK CODE BLOCK------
#6 lore raw
In reply to Pawel Plociennik
Quoted 2 lines · Pawel Plociennik

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed.

Wouldn't booting with 'init=/usr/sbin/chroot /path /sbin/init' achieve the same effect?
Haven't tested it, just wondering.

Quoted 6 lines

+ if(chroot_str) {
+ if(sys_chroot(chroot_str) < 0)
+ printk("chroot=%s failed\n", chroot_str);
+ else
+ printk("chroot=%s successed\n",chroot_str);
+ }

Continuing booting normally when the chroot failed sounds like a security issue to me.

Regards.

Signature · 1 line
Guillaume
#7 lore raw
Quoted 3 lines · Guillaume Chazarain

Wouldn't booting with 'init=/usr/sbin/chroot /path /sbin/init' achieve the same effect?
Haven't tested it, just wondering.

Hi,

I think that procces which has pid 0 is a special procces because it removes a *zombie* procceses so it is good to use a *dedicated* program for it such as a /sbin/init .
/usr/sbin/chroot doesn't remove a *zombie* procceses :-(

Regards,

Pawel Plociennik

#8 lore raw
Quoted 5 lines · Pawel Plociennik
Quoted 2 lines · Guillaume Chazarain

Wouldn't booting with 'init=/usr/sbin/chroot /path /sbin/init' achieve the same effect?

I think that procces which has pid 0 is a special procces

You mean pid 1, right? ;-)

Quoted 4 lines

because it
removes a *zombie* procceses so it is good to use a *dedicated* program for it such as a /sbin/init . /usr/sbin/chroot doesn't remove a *zombie* procceses :-(

Sure, but chroot should then exec /sbin/init as per the given kernel command line. And then you run a real init.

I cannot try it as I don't have another distribution installed in a subdirectory, but if you could test it we would quickly know if it works or not.

Thanks.

Signature · 1 line
Guillaume
#9 lore raw
Quoted 1 line · Guillaume Chazarain

You mean pid 1, right? ;-)

Of course that (my brain has been mistaked) :-(

Quoted 8 lines

Sure, but chroot should then exec /sbin/init as per the given kernel command line. And then you run a real init.

I cannot try it as I don't have another distribution installed in a subdirectory, but if you could test it we would quickly know if it works or not.

You have right.
I have tested that and it *works* :-)
so I thing that my patch is *unnecessary* now :-(

Thanks You

Regards,
Pawel

#10 lore raw
Quoted 8 lines · Pawel Plociennik
Quoted 1 line · Guillaume Chazarain

You mean pid 1, right? ;-)

Of course that (my brain has been mistaked) :-(

Quoted 4 lines

Sure, but chroot should then exec /sbin/init as per the given kernel command line. And then you run a real init.

Quoted 7 lines
Quoted 4 lines

I cannot try it as I don't have another distribution installed in a subdirectory, but if you could test it we would quickly know if it works or not.

You have right.
I have tested that and it *works* :-)
so I thing that my patch is *unnecessary* now :-(

Actually I disagree here. This means that if distro in / breaks, you will not be able to boot in ditstro in /foo any more :-(.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#11 lore raw
Quoted 5 lines · Pavel Machek
Quoted 1 line · Pawel Plociennik

so I thing that my patch is *unnecessary* now :-(

Actually I disagree here. This means that if distro in / breaks, you will not be able to boot in ditstro in /foo any more :-(.

For this case, you can boot with something like:

init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib /working_distro/usr/sbin/chroot /working_distro/ /sbin/init

And that's actually how you should setup your grub.conf to avoid depending on the distro in /.

Signature · 1 line
Guillaume
#12 lore raw
Quoted 5 lines · Guillaume Chazarain

init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib /working_distro/usr/sbin/chroot /working_distro/ /sbin/init

root=<root> init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib working_distro/usr/sbin/chroot /working_distro/ /sbin/init

I think that it is *interestly* hack but I am not sure that it will be an usable method for all of a distroes which exists on the world. At last my patch is as simple as possible and it has *only* a *few lines of the code* and it can be used
as *independent* method to various *hundred* distroes.

root=<root> chroot=<chroot>

and it looks *beautiful* I think :-)

so I have sent a patch again which it has corrected a *coding style* and a new description in a kernel-parameters.txt file (a suggestions for better description are welcome).
I think that this can be a *last version* of a patch.
Because I am *newbie* in a kernel hacking I hope that someone will had been written me what now with it ? Maybe send this patch *directly* to *kernel guru* such as Andrew Morton which manages a -mm series ?

Documentation/kernel-parameters.txt +2 -0
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 	
+	chroot=		[KNL] change a root for an init process.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used
init/main.c +12 -0
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
@@ -755,8 +755,20 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if (chroot_str)
+		if (sys_chroot(chroot_str) < 0)
+			printk(KERN_WARNING "chroot=%s failed\n", chroot_str);
+
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
Acked-by
#13 lore raw

Hi!

Quoted 15 lines · Guillaume Chazarain
Quoted 5 lines

init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib /working_distro/usr/sbin/chroot /working_distro/ /sbin/init

root=<root> init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib working_distro/usr/sbin/chroot /working_distro/ /sbin/init

I think that it is *interestly* hack but I am not sure that it will be an usable method for all of a distroes which exists on the world. At last my patch is as simple as possible and it has *only* a *few lines of the code* and it can be used
as *independent* method to various *hundred* distroes.

root=<root> chroot=<chroot>

Quoted 8 lines

and it looks *beautiful* I think :-)

so I have sent a patch again which it has corrected a *coding style* and a new description in a kernel-parameters.txt file (a suggestions for better description are welcome).
I think that this can be a *last version* of a patch.
Because I am *newbie* in a kernel hacking I hope that someone will had been written me what now with it ? Maybe send this patch *directly* to *kernel guru* such as Andrew
Morton which manages a -mm series ?

You need to add Signed-off-by... as per Documentation/Submitting*... and proper changelog would be nice.

And you can add

Yes, I think this should go to mm. ... but better Cc Andrew next time.
Pavel

Quoted 37 lines

diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt +2 -0
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 
+	chroot=		[KNL] change a root for an init process.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used

diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c

init/main.c +12 -0
@@ -755,8 +755,20 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if (chroot_str)
+		if (sys_chroot(chroot_str) < 0)
+			printk(KERN_WARNING "chroot=%s failed\n", chroot_str);
+
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#14 lore raw
In reply to Pawel Plociennik
Quoted 2 lines · Pawel Plociennik

At last my patch is as simple as possible and it has *only* a *few lines of the code* and it can be used as *independent* method to various *hundred* distroes.

Your method requires a certain kernel, mine does not ;-)

Quoted 6 lines

static void run_init_process(char *init_filename) {
+ if (chroot_str)
+ if (sys_chroot(chroot_str) < 0)
+ printk(KERN_WARNING "chroot=%s failed\n", chroot_str);
+

As I said before, this chroot= option can be used for security reason instead of testing purpose, and in this case, continuing booting after a failed chroot sounds like a security issue.

Signature · 1 line
Guillaume
author Acked-by Pavel Machek
#15 lore raw

Hi Andrew and other *real* hackers,

I have sent a *last* version of a patch which it has added a new kernel parameter chroot= It were discusioned a *long time* on a lkml so I hope that it will has been applied.

Thanks,
Pawel

---

Documentation/kernel-parameters.txt +2 -0
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 	
+	chroot=		[KNL] change a root for init process.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used
init/main.c +12 -0
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
@@ -755,8 +755,20 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if (chroot_str)
+		if (sys_chroot(chroot_str) < 0)
+			panic("chroot=%s failed\n", chroot_str);
+
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
author Acked-by Pavel Machek
#16 lore raw
In reply to Guillaume Chazarain

Hi Andrew and other *real* hackers,

I have sent a *last* version of a patch which it has added a new kernel parameter chroot= It were discusioned a *long time* on a lkml so I hope that it will has been applied.

Thanks,
Pawel

---

Documentation/kernel-parameters.txt +2 -0
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 	
+	chroot=		[KNL] change a root for init process.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used
init/main.c +12 -0
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
@@ -755,8 +755,20 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if (chroot_str)
+		if (sys_chroot(chroot_str) < 0)
+			panic("chroot=%s failed\n", chroot_str);
+
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
author Acked-by Pavel Machek
#17 lore raw
In reply to Guillaume Chazarain

Hi Andrew and other *real* hackers,

I have sent a *last* version of a patch which it has added a new kernel parameter chroot= It were discusioned a *long time* on a lkml so I hope that it will has been applied.

Thanks,
Pawel

---

Documentation/kernel-parameters.txt +2 -0
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
@@ -381,6 +381,8 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 	
+	chroot=		[KNL] change a root for init process.
+
 	clock=		[BUGS=X86-32, HW] gettimeofday clocksource override.
 			[Deprecated]
 			Forces specified clocksource (if available) to be used
init/main.c +12 -0
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
@@ -755,8 +755,20 @@ static void __init do_pre_smp_initcalls(
 		spawn_softlockup_task();
 }
 
+static void *chroot_str;
+static int __init chroot_setup(char *str)
+{
+	chroot_str = str;
+	return 1;
+}
+__setup("chroot=", chroot_setup);
+
 static void run_init_process(char *init_filename)
 {
+	if (chroot_str)
+		if (sys_chroot(chroot_str) < 0)
+			panic("chroot=%s failed\n", chroot_str);
+
 	argv_init[0] = init_filename;
 	kernel_execve(init_filename, argv_init, envp_init);
 }
#18 lore raw
In reply to Pawel Plociennik
Quoted 1 line

I think that procces which has pid 0 is a special procces because it

pid 1

Quoted 3 lines

removes a *zombie* procceses so it is good to use a *dedicated* program for it such as a /sbin/init . /usr/sbin/chroot doesn't remove a *zombie* procceses :-(

It exec's the process so the resulting process is still pid 1

#19 lore raw
In reply to Guillaume Chazarain

Hi!

Quoted 7 lines · Pawel Plociennik
Quoted 2 lines

In the short this patch has added a new chroot= kernel parameter which can be used to changing a chroot of an init process before it will has been runed.

Wouldn't booting with 'init=/usr/sbin/chroot /path /sbin/init' achieve the same effect?
Haven't tested it, just wondering.

This breaks down when there's no distribution installed in /, or when distro in / is badly broken.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html