Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[RFC][Patch] Allow not mounting a root fs

3 views
Skip to first unread message

Bodo Eggert

unread,
Jul 5, 2007, 10:01:02 PM7/5/07
to linux-...@vger.kernel.org
This patch adds the option to not mount another root filesystem
by specifying root=initramfs.

TODO: Documentation
---

BTW: Is it possible to mount a tmpfs on / before extracting the cpio?


While I'm at it:

In init/do_mounts.c, mount_root(void):
ROOT_NFS: Is it desirable to use the floppy as a root device if nfs-root
failed? If I tell my system to d A, i usually dislike it to do B instead.

Is the boot-from-floppy code here still usable, even though booting from
floppy is no longer supported?

diff -X dontdiff -pruN 2.6.21.ori/init/do_mounts.c 2.6.21/init/do_mounts.c
--- 2.6.21.ori/init/do_mounts.c 2007-07-06 03:31:57.000000000 +0200
+++ 2.6.21/init/do_mounts.c 2007-07-06 03:27:33.000000000 +0200
@@ -427,6 +427,9 @@ void __init prepare_namespace(void)
mount_block_root(root_device_name, root_mountflags);
goto out;
}
+ if (!strncmp(root_device_name, "initramfs", 3)) {
+ goto out_nomount;
+ }
ROOT_DEV = name_to_dev_t(root_device_name);
if (strncmp(root_device_name, "/dev/", 5) == 0)
root_device_name += 5;
@@ -444,6 +447,7 @@ void __init prepare_namespace(void)
out:
sys_mount(".", "/", NULL, MS_MOVE, NULL);
sys_chroot(".");
+out_nomount:
security_sb_post_mountroot();
}

--
Top 100 things you don't want the sysadmin to say:
65. What do you mean /home was on that disk? I umounted it!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

H. Peter Anvin

unread,
Jul 5, 2007, 10:09:16 PM7/5/07
to Bodo Eggert, linux-...@vger.kernel.org
Bodo Eggert wrote:
> This patch adds the option to not mount another root filesystem
> by specifying root=initramfs.

Uhm, the kernel doesn't mount anything if you're using an initramfs.

> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?

Not in the stock kernel. There have been some patches floating around
for that, I think.

-hpa

Bodo Eggert

unread,
Jul 6, 2007, 11:01:08 AM7/6/07
to H. Peter Anvin, Bodo Eggert, linux-...@vger.kernel.org
On Thu, 5 Jul 2007, H. Peter Anvin wrote:

> Bodo Eggert wrote:
> > This patch adds the option to not mount another root filesystem
> > by specifying root=initramfs.
>
> Uhm, the kernel doesn't mount anything if you're using an initramfs.

Yes, instead it panics trying to mount the non-existing "root=".
I've put the complete system into initrams, and I just want the kernel to
run /sbin/init.

> > BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>
> Not in the stock kernel. There have been some patches floating around
> for that, I think.

Are they messy, or would it just be a case of calling sys_mount before
unpacking the cpio?
--
The complexity of a weapon is inversely proportional to the IQ of the
weapon's operator.

Dan Aloni

unread,
Jul 6, 2007, 11:33:06 AM7/6/07
to Bodo Eggert, H. Peter Anvin, linux-...@vger.kernel.org
On Fri, Jul 06, 2007 at 05:00:40PM +0200, Bodo Eggert wrote:
> On Thu, 5 Jul 2007, H. Peter Anvin wrote:
>
> > Bodo Eggert wrote:
> > > This patch adds the option to not mount another root filesystem
> > > by specifying root=initramfs.
> >
> > Uhm, the kernel doesn't mount anything if you're using an initramfs.
>
> Yes, instead it panics trying to mount the non-existing "root=".
> I've put the complete system into initrams, and I just want the kernel to
> run /sbin/init.

If I understood you correctly, you're trying to get the kernel
to execute the "/sbin/init" file of your initramfs. However, "/init"
is the sole default initramfs entry point. To fix this, you can pass
rdinit=/sbin/init _or_ modify your initramfs image so that "/init"
is the entrypoint.

Normally, if your initramfs has a /init script your kernel would
skip the entire stage where it panics in the perpare_namespace()
function for trying to mount "root=" by itself (see
init/main.c:init()).

--
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il

Andre Noll

unread,
Jul 6, 2007, 1:04:12 PM7/6/07
to Bodo Eggert, H. Peter Anvin, linux-...@vger.kernel.org
On 17:00, Bodo Eggert wrote:

> I've put the complete system into initrams, and I just want the kernel to
> run /sbin/init.

Did you try to exec /sbin/init as the last thing in the init script
of your initramfs? That worked for me some time ago.

Andre
--
The only person who always got his work done by Friday was Robinson Crusoe

signature.asc

H. Peter Anvin

unread,
Jul 6, 2007, 1:16:46 PM7/6/07
to Andre Noll, Bodo Eggert, linux-...@vger.kernel.org
Andre Noll wrote:
> On 17:00, Bodo Eggert wrote:
>
>> I've put the complete system into initrams, and I just want the kernel to
>> run /sbin/init.
>
> Did you try to exec /sbin/init as the last thing in the init script
> of your initramfs? That worked for me some time ago.
>

Just add a symlink:

/init -> /sbin/init

-hpa

Jan Engelhardt

unread,
Jul 7, 2007, 2:31:09 PM7/7/07
to H. Peter Anvin, Bodo Eggert, linux-...@vger.kernel.org

On Jul 5 2007 19:08, H. Peter Anvin wrote:
>
>> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>
>Not in the stock kernel. There have been some patches floating around
>for that, I think.

What would it buy? rootfs is a tmpfs, is not it?


Jan
--

H. Peter Anvin

unread,
Jul 7, 2007, 4:57:28 PM7/7/07
to Jan Engelhardt, Bodo Eggert, linux-...@vger.kernel.org
Jan Engelhardt wrote:
> On Jul 5 2007 19:08, H. Peter Anvin wrote:
>>> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>> Not in the stock kernel. There have been some patches floating around
>> for that, I think.
>
> What would it buy? rootfs is a tmpfs, is not it?

No, rootfs is ramfs.

-hpa

Jan Engelhardt

unread,
Jul 7, 2007, 5:14:09 PM7/7/07
to H. Peter Anvin, Bodo Eggert, linux-...@vger.kernel.org

On Jul 7 2007 13:56, H. Peter Anvin wrote:
>Jan Engelhardt wrote:
>> On Jul 5 2007 19:08, H. Peter Anvin wrote:
>>>> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>>> Not in the stock kernel. There have been some patches floating around
>>> for that, I think.
>>
>> What would it buy? rootfs is a tmpfs, is not it?
>
>No, rootfs is ramfs.

Thanks for clarifying. Well, why is it a ramfs, and not tmpfs?
(I think I know the difference, but the question stands.
A system without any swap somewhat equals a ramfs, or?)


Jan
--

H. Peter Anvin

unread,
Jul 7, 2007, 5:17:57 PM7/7/07
to Jan Engelhardt, Bodo Eggert, linux-...@vger.kernel.org
Jan Engelhardt wrote:
> On Jul 7 2007 13:56, H. Peter Anvin wrote:
>> Jan Engelhardt wrote:
>>> On Jul 5 2007 19:08, H. Peter Anvin wrote:
>>>>> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>>>> Not in the stock kernel. There have been some patches floating around
>>>> for that, I think.
>>> What would it buy? rootfs is a tmpfs, is not it?
>> No, rootfs is ramfs.
>
> Thanks for clarifying. Well, why is it a ramfs, and not tmpfs?
> (I think I know the difference, but the question stands.
> A system without any swap somewhat equals a ramfs, or?)

It gets initialized very early, and a lot of the setup needed for tmpfs
to work isn't ready yet.

-hpa

Bodo Eggert

unread,
Jul 7, 2007, 5:30:26 PM7/7/07
to Jan Engelhardt, H. Peter Anvin, Bodo Eggert, linux-...@vger.kernel.org
On Sat, 7 Jul 2007, Jan Engelhardt wrote:
> On Jul 5 2007 19:08, H. Peter Anvin wrote:

> >> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
> >
> >Not in the stock kernel. There have been some patches floating around
> >for that, I think.
>
> What would it buy? rootfs is a tmpfs, is not it?

As far as I understand, it is a ramfs aka. non-swappable tmpfs without any
limit and including a chance of DoSing the system.

Since I'm toying with root-on-initcpio, I'm looking for things that might
make the task some easier.

Currently I'm thinking about changing the root=initramfs to root=tmpfs and
additionally mounting a tmpfs on / before unpacking the cpios. OTOH, this
seems to be a little bit messy. OTOH again, in _that_ boot code, nobody
should complain :)

--
"Whoever said the pen is mightier than the sword obviously never
encountered automatic weapons."
-Gen. Douglas MacArthur

Jan Engelhardt

unread,
Jul 7, 2007, 5:39:34 PM7/7/07
to Bodo Eggert, H. Peter Anvin, linux-...@vger.kernel.org

On Jul 7 2007 23:18, Bodo Eggert wrote:
>> >> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
>> >
>> >Not in the stock kernel. There have been some patches floating around
>> >for that, I think.
>>
>> What would it buy? rootfs is a tmpfs, is not it?
>
>As far as I understand, it is a ramfs aka. non-swappable tmpfs without any
>limit and including a chance of DoSing the system.
>
>Since I'm toying with root-on-initcpio, I'm looking for things that might
>make the task some easier.
>
>Currently I'm thinking about changing the root=initramfs to root=tmpfs and
>additionally mounting a tmpfs on / before unpacking the cpios. OTOH, this
>seems to be a little bit messy. OTOH again, in _that_ boot code, nobody
>should complain :)

Come to speak of it, I think you can have it much easier by having the kernel
exporting the cpio image as a virtual file inside rootfs, so that you could
re-extract it inside a tmpfs. In other words:

mount -t tmpfs tmpfs /mnt;
cd /mnt;
cpio -diuv </initramfs.cpio;
#
# switch_root nukes rootfs, pivot_roots and execs some init
klibc_switch_root .; # or something like that

Of course this needs double the memory than directly mounting tmpfs as
rootfs, but it's an idea too.


Jan
--

H. Peter Anvin

unread,
Jul 7, 2007, 5:46:20 PM7/7/07
to Jan Engelhardt, Bodo Eggert, linux-...@vger.kernel.org
Jan Engelhardt wrote:
>
> Come to speak of it, I think you can have it much easier by having the kernel
> exporting the cpio image as a virtual file inside rootfs, so that you could
> re-extract it inside a tmpfs. In other words:
>
> mount -t tmpfs tmpfs /mnt;
> cd /mnt;
> cpio -diuv </initramfs.cpio;
> #
> # switch_root nukes rootfs, pivot_roots and execs some init
> klibc_switch_root .; # or something like that
>
> Of course this needs double the memory than directly mounting tmpfs as
> rootfs, but it's an idea too.
>

Well, we're doing exactly this for non-initramfs initrd, however, it
would definitely be cleaner just to overmount rootfs with a tmpfs before
extraction -- it's an absolutely trivial amount of code; the biggest
complexity would be spotting the kernel command line option to invoke it.

Yet another variant, which works on existing kernels, is to have a
nested cpio, where your rootfs consists of a trivial /init which mounts
tmpfs and extracts another tar- or cpioball.

-hpa

Willy Tarreau

unread,
Jul 7, 2007, 5:47:18 PM7/7/07
to Bodo Eggert, Jan Engelhardt, H. Peter Anvin, linux-...@vger.kernel.org
On Sat, Jul 07, 2007 at 11:18:59PM +0200, Bodo Eggert wrote:
> On Sat, 7 Jul 2007, Jan Engelhardt wrote:
> > On Jul 5 2007 19:08, H. Peter Anvin wrote:
>
> > >> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
> > >
> > >Not in the stock kernel. There have been some patches floating around
> > >for that, I think.
> >
> > What would it buy? rootfs is a tmpfs, is not it?
>
> As far as I understand, it is a ramfs aka. non-swappable tmpfs without any
> limit and including a chance of DoSing the system.
>
> Since I'm toying with root-on-initcpio, I'm looking for things that might
> make the task some easier.
>
> Currently I'm thinking about changing the root=initramfs to root=tmpfs and
> additionally mounting a tmpfs on / before unpacking the cpios. OTOH, this
> seems to be a little bit messy. OTOH again, in _that_ boot code, nobody
> should complain :)

Well, maybe it would be time to assign limits to ramfs. I have a patch for
this in all my own 2.4 kernels that I use on appliances, network boot and
bootable CDs. It was a bit tricky to get the limits to work well in 2.4
because it was not easy to track which pages were used by whom. But I presume
that rmap in 2.6 should help a lot.

If someone is willing to give this a try, here's the 2.4 patch :

http://linux.1wt.eu/kernel/patches-2.4.34-wt1/pool/2.4.32-ramfs-limits-5

Regards,
Willy

Rob Landley

unread,
Jul 18, 2007, 6:41:29 PM7/18/07
to H. Peter Anvin, Jan Engelhardt, Bodo Eggert, linux-...@vger.kernel.org
On Saturday 07 July 2007 5:17:31 pm H. Peter Anvin wrote:
> Jan Engelhardt wrote:
> > On Jul 7 2007 13:56, H. Peter Anvin wrote:
> >> Jan Engelhardt wrote:
> >>> On Jul 5 2007 19:08, H. Peter Anvin wrote:
> >>>>> BTW: Is it possible to mount a tmpfs on / before extracting the cpio?
> >>>>
> >>>> Not in the stock kernel. There have been some patches floating around
> >>>> for that, I think.
> >>>
> >>> What would it buy? rootfs is a tmpfs, is not it?
> >>
> >> No, rootfs is ramfs.
> >
> > Thanks for clarifying. Well, why is it a ramfs, and not tmpfs?
> > (I think I know the difference, but the question stands.
> > A system without any swap somewhat equals a ramfs, or?)
>
> It gets initialized very early, and a lot of the setup needed for tmpfs
> to work isn't ready yet.

Out of curiosity, do you know which setup? I know that it won't actually swap
anything out yet because no swap is mounted, but I thought that mounting
tmpfs and doing a swapon afterwards was ok...

> -hpa

Rob
--
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.

H. Peter Anvin

unread,
Jul 18, 2007, 6:50:44 PM7/18/07
to Rob Landley, Jan Engelhardt, Bodo Eggert, linux-...@vger.kernel.org
Rob Landley wrote:
>
> Out of curiosity, do you know which setup? I know that it won't actually swap
> anything out yet because no swap is mounted, but I thought that mounting
> tmpfs and doing a swapon afterwards was ok...
>

Nope, I just know that the "obvious" way to do it crashes the kernel
horribly. It looks based on the patchsets that have flown about
recently as it's mostly a matter of initializing the icache.

-hpa

Roland M. Kruggel

unread,
Jul 18, 2007, 6:53:47 PM7/18/07
to linux-...@vger.kernel.org

--
cu

Roland Kruggel  mailto: rk.liste at bbf7.de
System: Intel, Debian etch, 2.6.16.16, xfce4 KDE 3.5

Test vom script...

0 new messages