Translate

Archives

Boot Linux Without An Initramfs

So you think you always need an initramfs to boot your Linux system. Not true and I will show you how.

For example, here is my GRUB2 (/boot/grub2/grub.cfg) configuration file for Fedora 17:

menuentry 'Fedora Linux, no initramfs' {
   set root='hd0,msdos1'
   linux	/vmlinuz-3.3.4-5.fc17.i686.PAE rootfstype=ext4 root=/dev/sda2 rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=True  KEYTABLE=us rd.luks=0 LANG=en_US.UTF-8
}


Note there is no line specifying an initramfs!

I was not aware that this was possible until I saw it demonstrated by Harald Hoyer. By the way, in case you were wondering, yes I manually edit my GRUB2 configuration file rather than using the numerous crazy GRUB2 configuration files and scripts.

The key to this technique for booting your kernel is the rootfstype=ext4 kernel command line argument which enables a user to force mount the root filesystem of a given type. This option allows you to give a comma separated list of filesystem types that will be tried for a match when trying to mount the root filesystem. This list will be used instead of the internal default. Internally, initramfs typically sets rootfstype to auto.

The main purpose of initramfs is to enable mounting of the root filesystem. It is a complete set of directories that you would find on a normal root filesystem. It is bundled into a single compressed cpio archive. If you can tell the kernel which filesystem and which filesystem type to mount, you can mostly eliminate the need for an initramfs.

At boot time, the boot loader loads the kernel and the initramfs image into memory and starts the kernel. The kernel checks for the presence of the initramfs and, if found, mounts it as / and runs /init which is typically a shell script. For most distributions, kernel modules are the biggest reason to have an initramfs. The boot process takes significantly longer if an initramfs is used. By the way, you can use the initrd utility to view the contents of your initramfs.

Removing the initramfs load, reduced my Fedora 17 boot time by some 4 seconds.

This technique does not work with EFI Stub booting of Linux kernels on UEFI firmware platforms.

1 comment to Boot Linux Without An Initramfs