The linux-initrd Spell

Also see linux-initramfs

What is an initrd?

An initrd is a small filesystem image and/or bootsplash that your bootloader can load and your kernel can boot to before any other filesystems are mounted. The filesystem usually has kernel modules and any other applications/shells that the user of the system needs. These modules and applications are there to do a particular task before the root filesystem is mounted or the init process is started.

Basic Structure of Initrds

The basic structure is as follows

| File System ============================== | Bootsplash image ========================= |

The filesystem is always on the front of the initrd and the bootsplash is always concatinated on the end of the initrd. Also at the root of most initrd's there is a file named linuxrc this is the first executed file (usually) in the initrd.

Support

  1. Kernel Support:

There are several things in the kernel that need to be enabled to support using initrds

# CONFIG_BLK_DEV_RAM=y (this cannot be a module for initrd support)

# CONFIG_BLK_DEV_INITRD=y

Also you will need to compile at least one filesystem into the kernel some suggestions are:

# CONFIG_CRAMFS=y (cramfs is in the default stable kernel)

# CONFIG_SQUASHFS=y (squashfs is a patch to the kernel but is also very nice to have)

This means that support for your root filesystem can be a module, because you can load it when you boot to the initrd. Also the tools used for creating these filesystems will also be needed. Cramfs is provided e2fsprogs and squashfs is provided by squashfs-tools. For bootsplash support you have to have a patched kernel with the bootsplash patch, and have it enabled. The option is:

# CONFIG_BOOTSPLASH=y

  1. Bootloader Support:

Most bootloaders support booting to initrd's it's just a matter of telling the bootloader to use the initrd.

  1. Grub Config:
    • Usually there isn't much more needed than to add a line below your kernel line with the initrd name Something like:

      kernel /vmlinubz-$VERSION <more kernel arguments>

      initrd /initrd-$VERSION

    b. Lilo Config:
    • Usually you would add the initrd to your right below the image line for lilo. Something like:

      image=/boot/vmlinubz-$VERSION

      initrd=/boot/initrd-$VERSION

      append="<more kernel arguments>"

    Each individual initrd may require different arguments to be passed to the kernel so the initrd will know what to do. These arguments are passed by just appending them to the kernel line in grub or adding the append in lilo and putting the extra initrd specific arguments there.

The Spell Itself

  1. It's all about options ;)

    1. Filesystem Option: This is the option to create the filesystem in the initrd. There's two parts to this half of the spell:
      1. What the filesystem is going to be?
        • There are several options: mkfs, mkfs.ext2, mkfs.ext3, mkfs.cramfs and mkfs.minix are all part of the e2fsprogs spell mksquashfs is part of the squashfs-tools spell mkisofs is part of the cdrtools spell

          Suggested file systems are the cramfs and squashfs filesystems they are both very compact and can easily fit everything in < 10Mb

        B. What script to run to fill the filesystem
        1. mk_initrd.rescue
          • This script generates an initrd containing all the modules for the version of the linux kernel you have installed plus busybox. Also the file /linuxrc is symlinked to /bin/ash, the busybox shell. There are many symlinks for the applications that busybox supports with the basic busybox config provided with the busybox spell. So if you boot to this initrd you will imediately be given control of the system before the root filesystem is mounted and init starts. The parameters passed to the kernel to boot to this initrd are: init=/linuxrc root=/dev/ram0
          ii. mk_initrd.rescue++
          • This script sets up the exact same filesystem as mk_initrd.rescue. However the only difference is that the linuxrc script is bootable script. The linuxrc script will use the parameter passed to the kernel, real_root, create the device node and pivot root into the system. This script does not have hardware detection and currently only supports ide real_root drives not scsi. The parameters passed to the kernel to boot to this initrd are: init=/linuxrc real_root=<root device> root=/dev/ram0

          iii. mk_initrd.selinux Experimental Script

          • This script is very experimental and should NOT BE USED if you don't know what you are doing or what selinux is. This script it just like the rescue++ only adding the enabling an selinux policy before init is started. The policy is passed to the kernel on the command line. The parameters passed to the kernel to boot to this initrd are: init=/linuxrc real_root=<real root> root=/dev/ram0 selinux_policy=<selinux policy> Once the initrd script is finished the file it creates will be initrd-<version>-<script>, where <version> is the kernel version used and <script> is the part of the script file after the . So for example: if you use the mk_initrd.rescue++ script to generate the inird and the 2.6.10 kernel the initrd name will be "initrd-2.6.12-rescue++"

        C. Bootsplash (everyone's favorite)
        • There's only one real option and that's what theme you would like to add to the end.
        • SMGL: Classic Source Mage GNU/Linux theme doesn't have a progress bar just the verbose option ii. Linux: Default linux theme that comes from bootsplash.org

If you don't put a filesystem on the front of the initrd the file will be called initrd.splash otherwise the string "-<theme>" will be concatinated on the end of the initrd name where <theme> is the theme choosen.

linux-initrd (last edited 2008-09-22 23:34:56 by localhost)