A lot of the code that your machine needs in order to boot will be built as kernel modules, and so won’t be immediately available to the kernel at boot-time. For the modules that drive your printer, sound-card, USB devices, etc., this isn’t a problem, but a lot of critical functionality is kept in modules as well. This means that your kernel will need to be able to get itself into a condition whereby it can probe your hardware, and load the appropriate modules.
The problem is that it can’t do that without creating a certain amount of the functionality of the full operating system — file systems, a toolchain, C libraries, etc.
So we have a Catch-22 situation. We need to probe the hardware in order to provide some basic functionality, but we can’t do that without a certain amount of functionality.
The way that Linux cuts through this is to load an initial filesystem into RAM containing the bare minimum, and then to use this to load the appropriate modules and boot the system. In theory this is only needed if you have key functions compiled as modules, but that will almost always be the case for desktop Linux. Embedded Linux is a whole different story…
This initial filesystem is called the
initramfs, and the tools to create one are quite different on different distributions. Of course, it is only the high level tools that differ — the basic technology is still the same, and lower-level functions can be used in an identical way for all distributions. I could provide those instructions, but the good folk at Linux From Scratch have already done a much better job than I ever could.
Initramfs on Arch
The Arch tool to create the initramfs needs a config file, and assuming we have the
ext variable set as in the last post, then this file is
/etc/mkinitcpio.d/linux$ext.preset, and has the following contents.
Now create the initramfs.
mkinitcpio -p linux$ext
Initramfs on Ubuntu
The steps on Ubuntu are similarly simple.
No config file is needed. Instead, just execute the following.
sudo mkinitramfs -k -o initrd.img-4.20.0$ext 4.20.0$ext
4.20.0 used twice in that command. This is a result of me using the 4.20.0 kernel. It is likely that you will have downloaded a kernel with a different version number, and care should be taken to use that instead.
Initramfs on Fedora
Fedora is the easiest of the three covered here. After compilation, execute this.
sudo make install
And you’re done! On Fedora, this will take care of moving the kernel into the right place, creating the initramfs, and updating the bootloader (which we will take care of in the next step for the other distros). So reboot and enjoy!
Although the Fedora people are already done, the rest of us have one more thing to do. We have to make sure our bootloader knows that our new kernel is available, and we will do that in the next post.