Creating initrd from scratch

OK, not really from scratch, but almost. Using the previous method to mount the initrd and then observe and copy the desired stuff over and just redo the desired stuff.

Copy over the linuxrc file, this is the file that is called by the kernel and does all the magic stuff. It is a very simple bash script:

cp /mnt/initrd/linuxrc /root/USBHD

This is the first file for the new initrd built from scratch. If it would run on its own, we would probably be already finished but it calls other programs that need to be put on /root/USBHD. So open it in a text editor. As you see the following commands are required:

cd is not a program, so no need to do anything.


Before continuing with this time consuming work make sure you system is updated! So what you will copy over is up-to date.

This means those commands need to be found in the chrooted environment and copied over including their paths and permissions to /root/USBHD. The command whereis sleep helps to find the paths.

Unfortunately those programs require libraries to run so again go though their list and find out the required libraries as ldd /bin/bash. Note that most of the libraries are just links to the actual libraries. So copy the actual libraries to /root/USBHD/lib and then make a symbolic link. Ignore since it is produced by the kernel and put in RAM (ldd was also not able to find it on the hard).

Additional stuff to put in /root/USBHD that can be copied over (or for the addict be re-created manually ) are

  1. cd /root/USBHD/bin and ln -s bash sh to create this link, so sh can be called instead of bash as commonly used in Linux

  2. /etc with a dummy empty /etc/fstab file in it

  3. /new-root an empty directory that is used to switch over root

  4. /proc an empty directory

  5. If you like more functionalities, especially when you like to call sh instead of linuxrc, then you can add some more commands to /root/USBHD as , cat, ls and verify if new libraries are required.

When calling the mkinitrd script the /dev directory and the necessary device files are created.

In the old days hard disks as IDE where called /dev/hda1 so the first USB hard disk ended up to be /dev/sda1. This has changed with SATA so the first internal hard disks is /dev/sda1. Therefore the USB hard disk gets a name as /dev/sdb1. Verify this, and if necessary correct this in linuxrc.

Linurs startpage