Solution with INITRD

Before I discovered the solution with the kernel parameter, I used the following approach for over two years. It can be consider as a historic way to do the same or it is a backup solution when the first solution does not work or it might be helpful to solve some other boot issues.

Quick install

If you don't care about how it works but you just would like that it works try the following. If boot works then it is fine, if not don't panic you need to do just some extra work, so jump to the next chapter. Failures can have many reasons as:

You have an other system than 32bit x86 Linux
Version conflicts between kernel and stuff inside the initrd
The device file as /dev/sdb1 does not match with the setup

To try out if the prepared initrd works here the steps:

  1. Install Gentoo as written in the handbook except that you install it on the USB device.

  2. If you compile the kernel go into the Device driver>Block devices section>RAM block device support: CONFIG_BLK_DEV_RAM and in General Setup>Initial RAM filesystem and RAM disk>CONFIG_BLK_DEV_INITRD are set.

  3. Download initrd.gz from the Internetand copy it to /boot.

    cd /boot

    wget http://www.linurs.org/download/initrd.gz

  4. Modify your /boot/grub/grub.conf to have something as:

                title=Gentoo Linux <ver> linuxrc
    root (hd0,0)
    kernel /kernel<ver>gentoo root=/dev/ram0 init=/linuxrc rw
    initrd /boot/initrd.gz
  5. Create a /initrd directory on your USB hard disk.

  6. Now boot your PC and make sure it boots from the USB device first

How it works in Details

The boot concept

The concept is not using the USB at when the kernel boots. Something more quick and more easy to access then the USB drive is the internal RAM. Grub supports to load a file into the RAM. The name of this file is usually initrd (initial RAM disk) or if it is compressed initrd.gz. This single compressed file is expanded to a root file system containing all necessary files required to boot.

Additionally to grub, the kernel supports such files. Add root=/dev/ram0 in grub to indicate to the kernel to unzip the initrd.gz and mount it to the ram disk /dev/ram0. The file will be read from the kernel via the device /dev/initrd and unpacked and written to /dev/ram0.

By default the kernel starts /sbin/init after boot. /sbin/init accesses the /etc/initab that manages the init V boot process with all its runlevels. To have it simple, you can pass init=/bin/sh to the kernel via grub to let the kernel start the shell instead of /sbin/init, this might be helpful for debugging. With the same mechanism you can tell the kernel to start the linuxrc script that is found in the initial RAM disk mounted at /dev/ram0.

The linuxrc can be a script or an executable binary. However make sure that all files are in initrd that linuxrc requires. e.g.: If linuxrc is a script, it can not run without bash, so copy bash to the initrd. Note bash can not run, since its libraries are missing. Type ldd /bin/bashto see what you have and to copy that the /lib directory of the initial ram disk. How to create a initrd.gz file and linuxrc script will follow later in this document.

It is up to the linuxrc script what will happen after the kernel is alive. To boot the following steps are required:

  1. Mount the USB disk to the initrd (e.g. under /new-root)

  2. Flip the directory tree so that /new-root gets / and the the initrd gets /initrd using the pivot_root command

  3. Start /sbin/init in the new root / using chroot command

change root from the ram disk to the newly mounted USB hard disks. This is done via pivot_root command followed by a regularly start of /sbin/init.

Kernel

This document assumes that you are not use the Gentoo genkernel (since it already uses initrd and linuxrc, it would get complicated dealing with two different initrd).

Putting all necessary kernel modules for the boot process into the kernel is the easy solution. Otherwise the kernel would need to find those modules on some filesystem that might again not accessible.

Go into the Device driver&gt;Block devices section>RAM block device support: CONFIG_BLK_DEV_RAM and in General Setup>Initial RAM filesystem and RAM disk>CONFIG_BLK_DEV_INITRD are set.

Add also support for the loop devices to get /dev/loop, since this is required by the mkinitrd script used to create and for customizing initrd.


Linurs Servernest startpage