6

Is it possible to boot linux without a initrd.img ? I am planning to add default drivers as a part-of-kernel itself and avoid initrd completely.

What are the modules that should be made part-of-the-kernel instead of loadable modules ?

2
  • 1
    What ever is needed for the kernel to see your boot media (hard disk/raid driver/volume manager) and the root filesystem.
    – forcefsck
    Mar 17, 2011 at 11:59
  • You might also want to add drivers for the thing you're using as the system console - on BIOS-based systems this can usually be either a VGA text console or a frame-buffer console; on UEFI systems, an UEFI frame-buffer console driver is required. Of course, you also have the alternative of using a serial port as a console. Sure, it's possible to boot without a console and then load a console driver after the real root filesystem has been mounted - but I would not recommend that for your first initrd-less kernel, as if something goes wrong it will be a pain to troubleshoot.
    – telcoM
    Oct 23, 2021 at 18:39

2 Answers 2

14

It is, unless your root volume is on an LVM, on a dmcrypt partition, or otherwise requires commands to be run before it can be accessed.

I haven't used an initrd on my server in years. You need at a minimum these modules built in:

  • the drivers of whatever controller where your root volume disk lives
  • the drivers necessary to "get to" that like PCI, PCIe support, USB support, etc.
  • the modules that run the filesystem mounted on it

    It's also a very good idea to build in your network card drivers as well.

    I've found that lspci/lsmod can help you here from your currently running kernel, look at what's there and use the make menuconfig search option before compiling to find where to enable the modules.

2
  • UPDATE: Linux needs a user-space program to boot off of a volume by uuid. You will almost always want to boot by uuid if A) you are trying to boot off of USB and B) there's a possibility that other mass-storage devices may be connected - Linux doesn't always assign your boot-time USB partitions /dev/sd*. So you will want to specify a uuid. And you need an initrd that contains the script that mounts the root volume by uuid, the kernel can't do it.
    – LawrenceC
    Aug 10, 2012 at 21:16
  • 3
    You can boot from USB without an initramfs by using PARTUUID= and rootwait. See kernel-parameters.txt and Why can't I specify my root fs with a UUID? and What's the point of rootwait/rootdelay?
    – bain
    Jan 28, 2016 at 14:51
0

planning to add default drivers

Then start with make defconfig && make, as a related answer laconically suggests. Well first just the default (x86_64?) .config.

That way you get a quite large kernel -- today 9 MB. The only as-modules are netfilter ones.

A more tailor-made config results in 4.5 MB kernel, and some more modules (notably the i915 module).

Some modules have to be built-in. See other answer. Ten years later, I should also explicitly add I/O devices: USB_HID for keyboard, FB (framebuffer) for integrated graphics card, depending on the system.

Devices, it seems, don't like to stay un-driven after power-up: graphic card module and network module, plus some bus helper reduce my Watts from 5.1 to 3.1. This is a bit counter-intuitive; explained by the drivers putting the devices into the correct suspend state, or otherwise calming them down.

While the e1000e module can be removed (and the 0.2 Watts or so don't seem to come back; and the network will be down), the i915 cannot even be removed. So these "modules" behave very differently.

After make defconfig, and equipped with lsmod from a initrd/udevd installation/distro, you can make nconfig or similar and start weed out (or even add something). Work with Kconfig.

With the modified .config ready:

make -jx bzImage

This image can be installed (copied and given a KCL: root=) and test booted. If it works, and you also want the modules:

make -jx modules
make INSTALL_MOD_PATH=/maybe/mnt/elseroot modules_install

Don't forget to save and name the .config file before reconfiguring.

Some modules (netfilter, filesystem support) are nicely removable. Modules are compiled separately from bzImage, which can save kernel compile time if repeated. Otherwise the difference is not big, unless you care how lsmod output looks.

Oh and then systemd also has some requirements and expectations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.