Skip to content

Boot Without Initramfs

how to boot faster with the kernel only

the vanillar Arch linux installation, comes with initramfs by default because the distro has to work on a large spectrum of machines, with different hardware, setups, but we don't need all that code, let's strip it up, to make a faster boot time and more ligntweight system.

the raison d'être for initramfs, is to mount the rootfs, then pass control to the init process, if the kernel has all needed modules to mount that rootfs, it will not need to use initramfs anymore.

1. Find Required Modules

first we need to detect required modules, to mount rootfs, you need to tell the system to stop booting right after the rootfs is mounted by initramfs. to do it pass the following arg to your kernel, either through a bootloader like grub. or add it to the efi entry:

break=postmount

after booting with that option, you will be droped to an emergency shell, wich we will use to extract currently loaded modules, that are used to mount our rootfs:

lsmod
# you should save the output somewhere, we will need it !

after that just run

exit

which will continue booting normally to userspace.

2. Build a Custom Kernel

using the data gathered from the previous step. you should find the equivalent kernel config options, and build those modules into the kernel, not as dynamically loaded modules (that's very important !).

first go to kernel src tree, to get the current kernel config run:

zcat /proc/config.gz > .config
make olddefconfig

then

make menuconfig

then to search for a module from the list gathered before, press /, you will get a text input, you should write the module name, then press enter. find the most relavant option, then enable it, don't forget to set it as built-in, means the config should be marked with * not M (which means module)

finally the build it:

make -j$(nproc)

3. Install the Kernel

install modules first:

doas make modules_install -j$(nproc)

then the kernel itself:

for archlinux you need to install it manually, because the script kernel_install is not available.

doas cp arch/x86/boot/bzImage /boot/vmlinuz

next we should update the boot entry, if you are using an uefi system run:

doas efibootmgr --create --disk /dev/sda --part 1 --label LITE-BOOT --load /vmlinuz --unicode "root=/dev/sda2 rw loglevel=4" --edd30 3 --verbose

if you are using a bootloader, check out the manual on how to update the boot entry.

there you have it, your boot time will definitely be shorter. to boot even faster I suggest you to read this.

if you face any problem you can:

Contact me at [email protected] or [email protected]