2008-03-01 13:10:51

by Pawel Plociennik

[permalink] [raw]
Subject: [PATCH] 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.

diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
--- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
+++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-02-25 20:51:21.000000000 -0500
@@ -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
--- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
+++ linux-2.6.24/init/main.c 2008-02-25 20:36:06.000000000 -0500
@@ -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);
}


2008-03-01 19:17:18

by Alexandre Oliva

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Mar 1, 2008, Pawel Plociennik <[email protected]> wrote:

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

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

2008-03-01 20:05:26

by Stefan Hellermann

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Pawel Plociennik schrieb:
> 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 :)

2008-03-02 11:18:19

by Kasper Sandberg

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Sat, 2008-03-01 at 20:44 +0100, Stefan Hellermann wrote:
> Pawel Plociennik schrieb:
> > 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.

Hey!

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

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

2008-03-02 15:43:23

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Hi!

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

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


> diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
> --- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
> +++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-02-25 20:51:21.000000000 -0500
> @@ -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
> --- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
> +++ linux-2.6.24/init/main.c 2008-02-25 20:36:06.000000000 -0500
> @@ -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 ('

> + if(sys_chroot(chroot_str) < 0)

here too.

> + 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
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2008-03-02 16:00:19

by Filippo Zangheri

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Pawel Plociennik ha scritto:
> hi *real* hackers,
(...)

> diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
> --- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
> +++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-02-25 20:51:21.000000000 -0500
> @@ -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()'?


(...)
> + if(sys_chroot(chroot_str) < 0)
> + printk("chroot=%s failed\n", chroot_str);

Thanks.


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

2008-03-02 16:00:47

by Guillaume Chazarain

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Sat, Mar 1, 2008 at 8:09 PM, Pawel Plociennik <[email protected]> wrote:
> 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.

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

--
Guillaume

2008-03-02 18:00:19

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Sunday 02 March 2008 11:00, Guillaume Chazarain wrote:
> 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

2008-03-02 18:05:59

by Guillaume Chazarain

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Mon, Mar 3, 2008 at 12:59 AM, Pawel Plociennik
<[email protected]> wrote:
> On Sunday 02 March 2008 11:00, Guillaume Chazarain wrote:
> > 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? ;-)

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

--
Guillaume

2008-03-02 19:09:42

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Sunday 02 March 2008 13:05, Guillaume Chazarain wrote:

> You mean pid 1, right? ;-)
Of course that (my brain has been mistaked) :-(
>
> 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

2008-03-02 19:17:20

by Alan

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

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

pid 1

> 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

2008-03-03 14:44:22

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Sun 2008-03-02 20:09:03, Pawel Plociennik wrote:
> On Sunday 02 March 2008 13:05, Guillaume Chazarain wrote:
>
> > You mean pid 1, right? ;-)
> Of course that (my brain has been mistaked) :-(
> >
> > 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 :-(

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
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2008-03-03 14:44:54

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Hi!

> On Sat, Mar 1, 2008 at 8:09 PM, Pawel Plociennik <[email protected]> wrote:
> > 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
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2008-03-03 15:19:49

by Guillaume Chazarain

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Mon, Mar 3, 2008 at 3:12 PM, Pavel Machek <[email protected]> wrote:
> On Sun 2008-03-02 20:09:03, Pawel Plociennik wrote:
> > 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 /.

--
Guillaume

2008-03-03 16:08:42

by Bodo Eggert

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Pavel Machek <[email protected]> wrote:
>> On Sat, Mar 1, 2008 at 8:09 PM, Pawel Plociennik <[email protected]>

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

Yes.

Real life example: I set up a system in qemu and moved it to ~/temp/foo
in order to test it before overwriting the old system. I had to boot into
/bin/sh, mount the home disc and chroot into that directory.

OTOH, I'm not sure if the kernel would have found my home if it were on LVM.

2008-03-05 07:38:41

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Monday 03 March 2008 10:19, Guillaume Chazarain wrote:
>
> 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 ?


diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
--- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
+++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-03-04 09:51:52.000000000 -0500
@@ -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
--- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
+++ linux-2.6.24/init/main.c 2008-03-05 08:23:32.000000000 -0500
@@ -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);
}

2008-03-05 12:32:30

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Hi!

> On Monday 03 March 2008 10:19, Guillaume Chazarain wrote:
> >
> > 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 ?

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

And you can add

Acked-by: Pavel Machek <[email protected]>

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

>
> diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
> --- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
> +++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-03-04 09:51:52.000000000 -0500
> @@ -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
> --- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
> +++ linux-2.6.24/init/main.c 2008-03-05 08:23:32.000000000 -0500
> @@ -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);
> }

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

2008-03-05 13:23:55

by Guillaume Chazarain

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

On Wed, Mar 5, 2008 at 2:38 PM, Pawel Plociennik <[email protected]> wrote:
> 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 ;-)

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

--
Guillaume

2008-03-05 22:52:49

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

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

Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Pawel Plociennik <[email protected]>

---
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
--- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
+++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-03-04 09:51:52.000000000 -0500
@@ -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
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
--- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
+++ linux-2.6.24/init/main.c 2008-03-05 15:08:20.000000000 -0500
@@ -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);
}

2008-03-05 23:00:48

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

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

Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Pawel Plociennik <[email protected]>

---
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
--- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
+++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-03-04 09:51:52.000000000 -0500
@@ -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
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
--- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
+++ linux-2.6.24/init/main.c 2008-03-05 15:08:20.000000000 -0500
@@ -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);
}

2008-03-05 23:04:57

by Pawel Plociennik

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

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

Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Pawel Plociennik <[email protected]>

---
diff -urp linux-2.6.24-orig/Documentation/kernel-parameters.txt linux-2.6.24/Documentation/kernel-parameters.txt
--- linux-2.6.24-orig/Documentation/kernel-parameters.txt 2008-02-25 20:53:26.000000000 -0500
+++ linux-2.6.24/Documentation/kernel-parameters.txt 2008-03-04 09:51:52.000000000 -0500
@@ -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
diff -urp linux-2.6.24-orig/init/main.c linux-2.6.24/init/main.c
--- linux-2.6.24-orig/init/main.c 2008-03-01 12:58:37.000000000 -0500
+++ linux-2.6.24/init/main.c 2008-03-05 15:08:20.000000000 -0500
@@ -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);
}

2008-03-06 00:16:32

by Bodo Eggert

[permalink] [raw]
Subject: Re: [PATCH] chroot= as a new kernel parameter

Guillaume Chazarain <[email protected]> wrote:
> On Wed, Mar 5, 2008 at 2:38 PM, Pawel Plociennik <[email protected]>

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

Your method requires to type the whole bible on the command line.

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

Even if not, continuing on unknown/bad options is a BAD idea. If I made a
typo in the path, the wrong system would be started, leaving me to choose
between waiting (felt) five minutes until I can shut it down cleanly or
to hard reboot and fsck.