chroot= as a new kernel parameter
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
@@ -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
@@ -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); }
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}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 :)
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
StefanPS: 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/
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.txtlinux-2.6.24/Documentation/kernel-parameters.txtDocumentation/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 useddiff -urp
linux-2.6.24-orig/init/main.clinux-2.6.24/init/main.cinit/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
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.txtlinux-2.6.24/Documentation/kernel-parameters.txtDocumentation/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------
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
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
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/chrootdoesn'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
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/initas 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
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/initas 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
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
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
@@ -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
@@ -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); }
Pavel Machek
Acked-byHi!
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/initroot=<root> init=/working_distro/lib/ld-linux.so.2 --library-path /working_distro/lib working_distro/usr/sbin/chroot /working_distro/
/sbin/initI 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.txtlinux-2.6.24/Documentation/kernel-parameters.txtDocumentation/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 useddiff -urp
linux-2.6.24-orig/init/main.clinux-2.6.24/init/main.cinit/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
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
Pawel Plociennik
Acked-by Pavel MachekHi 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
@@ -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
@@ -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); }
Pawel Plociennik
Acked-by Pavel MachekHi 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
@@ -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
@@ -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); }
Pawel Plociennik
Acked-by Pavel MachekHi 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
@@ -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
@@ -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); }
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/chrootdoesn't remove a *zombie* procceses :-(
It exec's the process so the resulting process is still pid 1
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