So, if you're planning to modify the initramfs and play with it, dracut is here. It's an advanced tool to generate initramfs images.
The initramfs image generated by dracut is considerably smaller in size compared to the default in Ubuntu, so I'm going to use dracut in Ubuntu and this tutorial is Ubuntu specific.
So why not give dracut a try? Though it's a quite interesting, but this tutorial is only for experienced users. Attempt this only if you're sure that you can fix the system anyhow.
Install dracut in Ubuntu
This step is quite straight forward, dracut is already in Ubuntu repo.
sudo apt-get --no-install-recommends install dracut
The above command will install dracut and remove initramfs-tools as well.
The initramfs file will be created automatically, the GRUB willbe updated automatically, but to be sure, update grub once more.
You can check the size of the initramfs file with the du command. It's around 7.9 MB in my case, generated for custom linux kernel 4.10.10 with some extra modules.
Reboot the machine to test the new initramfs, check it with systemd-analyze command.
Enjoy free shipping and One-Day delivery, cancel any time.
If you use the
systemd-analyze command frequently, then you can see it's a little different than the Ubuntu default.
Generate initramfs for a specific kernel version
If you've installed multiple kernels, then you may need to generate or update an initramfs manually.
A generalised command should be like below,
sudo dracut -f /path/to/output/initrd.img kernel-version
A real example, generating initramfs with dracut, kernel verion 4.10.10 .
sudo dracut -f initrd-4.10.10.img 4.10.10
The above command will create the initramfs file in present directory, you need to copy it to the
/boot folder or modify the command to overrite the existing initramfs.
sudo dracut -f /boot/initrd.img-4.10.10 4.10.10
Adding extra kernel modules in dracut
If you need some extra kernel modules in your initramfs to boot the system properly, you can use the instruction below.
- First find out which kernel modules you need, in my case I was in need of the
fbconand related modules.
- Now update the initramfs file, or generate a new one, keep both and use what you you need.
sudo dracut --add-drivers module_name /boot/initrd.img-kernel.version
The above command is just for representation, here's a real example.
sudo dracut --add-drivers fbcon /boot/initrd.img-4.10.10
Dracut is intelligent enough to check the extra module dependencies and also includes them.
So that's all about dracut linux command and how to use it in Ubuntu, hope you enjoyed it. Share your thoughts and opinions below.