2004-10-21 10:38:34

by Mildred Frisco

[permalink] [raw]
Subject: making a linux kernel with no root filesystem

Hi,
I would like to ask help in compiling a minimal linux kernel.
Basically, it would only contain the kernel andno filesystem (or
probably devfs). I would only have to boot the kernel from floppy.
Then after the necessary kernel initializations, I would issue a
prompt where I can either shutdown or reboot the system. That's the
only functionality required. As I've learned from the init program
(and startup scripts), the init services and shutdown commands are
called from /sbin. However, I do not require to mount the root fs
anymore. I also tried to search for the source code of the shutdown
program but I can't find it. Please help on the steps that I should
do.
Thanks in advance.
Please CC my email add in the reply. Thanks

Mildred <[email protected]>


2004-10-21 10:08:33

by Mildred Frisco

[permalink] [raw]
Subject: making a linux kernel with no root filesystem

Hi,
I would like to ask help in compiling a minimal linux kernel.
Basically, it would only contain the kernel andno filesystem (or
probably devfs). I would only have to boot the kernel from floppy.
Then after the necessary kernel initializations, I would issue a
prompt where I can either shutdown or reboot the system. That's the
only functionality required. As I've learned from the init program
(and startup scripts), the init services and shutdown commands are
called from /sbin. However, I do not require to mount the root fs
anymore. I also tried to search for the source code of the shutdown
program but I can't find it. Please help on the steps that I should
do.
Thanks in advance.
Please CC my email add in the reply. Thanks

Mildred <[email protected]>

2004-10-21 10:50:59

by Paulo Marques

[permalink] [raw]
Subject: Re: making a linux kernel with no root filesystem

Mildred Frisco wrote:
> Hi,
> I would like to ask help in compiling a minimal linux kernel.
> Basically, it would only contain the kernel andno filesystem (or
> probably devfs). I would only have to boot the kernel from floppy.
> Then after the necessary kernel initializations, I would issue a
> prompt where I can either shutdown or reboot the system. That's the
> only functionality required. As I've learned from the init program
> (and startup scripts), the init services and shutdown commands are
> called from /sbin. However, I do not require to mount the root fs
> anymore. I also tried to search for the source code of the shutdown
> program but I can't find it. Please help on the steps that I should
> do.

Your /sbin/init can be a simple script (or even just bash or another shell).

You can use statically compiled binaries against dietlibc from here:

ftp://foobar.math.fu-berlin.de:2121/pub/dietlibc/bin-i386/

If you use "ash" as /sbin/init and place busybox there with the
appropriate symlinks, you get a small semi-functional shell for a mere
120kb of executables.

If you're really desperate for space, you can build your own executable
that asks for shutdown/reboot and calls reboot(2) with the appropriate
parameters, and link against dietlibc (or ulibc).

This is not really kernel related and you should not mess with the
kernel code for acomplishing this. If you really need to cut down extra
space in the kernel you can check the patches from the "tiny" tree to
build an incredibly small kernel.

I hope this helps,

--
Paulo Marques - http://www.grupopie.com

All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)

2004-10-21 12:15:59

by Richard B. Johnson

[permalink] [raw]
Subject: Re: making a linux kernel with no root filesystem

On Thu, 21 Oct 2004, Paulo Marques wrote:

> Mildred Frisco wrote:
>> Hi,
>> I would like to ask help in compiling a minimal linux kernel.
>> Basically, it would only contain the kernel andno filesystem (or
>> probably devfs). I would only have to boot the kernel from floppy.
>> Then after the necessary kernel initializations, I would issue a
>> prompt where I can either shutdown or reboot the system. That's the
>> only functionality required. As I've learned from the init program
>> (and startup scripts), the init services and shutdown commands are
>> called from /sbin. However, I do not require to mount the root fs
>> anymore. I also tried to search for the source code of the shutdown
>> program but I can't find it. Please help on the steps that I should
>> do.
>
> Your /sbin/init can be a simple script (or even just bash or another shell).
>
> You can use statically compiled binaries against dietlibc from here:
>
> ftp://foobar.math.fu-berlin.de:2121/pub/dietlibc/bin-i386/
>
> If you use "ash" as /sbin/init and place busybox there with the appropriate
> symlinks, you get a small semi-functional shell for a mere 120kb of
> executables.
>
> If you're really desperate for space, you can build your own executable that
> asks for shutdown/reboot and calls reboot(2) with the appropriate parameters,
> and link against dietlibc (or ulibc).
>
> This is not really kernel related and you should not mess with the kernel
> code for acomplishing this. If you really need to cut down extra space in the
> kernel you can check the patches from the "tiny" tree to build an incredibly
> small kernel.
>
> I hope this helps,
>
> --
> Paulo Marques - http://www.grupopie.com


Let me add the basics that the kernel expects to execute
/sbin/init. This means that there must be a root file-system
to contain it. However, it can be a RAM-disk. That's how
initrd works. /sbin/init can be a program that you write
that does everything you need yout system to do. It can
fork off multiple tasks, etc. Just don't accidentally call
exit() or return from main()!

The kernel configuration can be changed so that it's really
small. It is possible to boot the Linux operating system plus
an entire network router from a 1.44Mb floppy disk, or anything
that can emulate such a disk (a NVRAM disk).

Shutdown and reboot are simple, for instance 'reboot' is
system-call number 88. It takes some documented parameters.
You don't really need a 'C' runtime library if you want
to make your own interface to the kernel. The kernel
directly provides the non-buffered file stuff, basically
most everything in unistd.h and more.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 GrumpyMips).
98.36% of all statistics are fiction.

2004-10-21 12:00:35

by Denis Vlasenko

[permalink] [raw]
Subject: Re: making a linux kernel with no root filesystem

On Thursday 21 October 2004 12:46, Mildred Frisco wrote:
> Hi,
> I would like to ask help in compiling a minimal linux kernel.
> Basically, it would only contain the kernel andno filesystem (or
> probably devfs). I would only have to boot the kernel from floppy.
> Then after the necessary kernel initializations, I would issue a
> prompt where I can either shutdown or reboot the system. That's the
> only functionality required. As I've learned from the init program
> (and startup scripts), the init services and shutdown commands are
> called from /sbin. However, I do not require to mount the root fs
> anymore. I also tried to search for the source code of the shutdown
> program but I can't find it. Please help on the steps that I should
> do.

Okay please imagine that kernel initialized all hardware and,
now, what shall it do instead of mounting root fs and starting
$INIT?

You want a "prompt where I can either shutdown or reboot the system".
How to do that? It is best done from small userspace environment,
like initrd or initramfs. Putting this into kernel is ugly.
--
vda

2004-10-21 19:21:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: making a linux kernel with no root filesystem

On Thu, 21 Oct 2004, Denis Vlasenko wrote:
> You want a "prompt where I can either shutdown or reboot the system".
> How to do that? It is best done from small userspace environment,
> like initrd or initramfs. Putting this into kernel is ugly.

Magic Sysrequest?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2004-10-21 19:57:44

by Mathieu

[permalink] [raw]
Subject: Re: making a linux kernel with no root filesystem

"Richard B. Johnson" <[email protected]> disait derni?rement que :

> On Thu, 21 Oct 2004, Paulo Marques wrote:
>
> Let me add the basics that the kernel expects to execute
> /sbin/init. This means that there must be a root file-system
> to contain it. However, it can be a RAM-disk. That's how
> initrd works. /sbin/init can be a program that you write
> that does everything you need yout system to do. It can
> fork off multiple tasks, etc. Just don't accidentally call
> exit() or return from main()!

but initrd needs a FS code linked in :)
the only way to have no fs linked in the kernel, is to use initramfs,
i.e. rootfs as the real root.
The solution to the problem is to provide the basics of a system in
the newc cpio format (see in Documentation/early-userspace/) which
will require no FS code linked in (huh, I guess RAMFS is needed ;)),
tweak usr/Makefile to get it use the in-place initramfs_data.cpio.gz and
put the cpio archive in usr. (I do this way because the initramfs_list
"mechanics" never succeeded in getting me a working kernel :))

--
"I know how hard it is for you to put food on your family."

George W. Bush
January 27, 2000
During a campaign speech in Nashua, New Hampshire.