Remix.run Logo
teraflop 4 days ago

Nice article! One point of clarification:

> When the kernel starts it does not have all of the parts loaded that are needed to access the disks in the computer, so it needs a filesystem loaded into the memory called initramfs (Initial RAM filesystem).

The kernel might not have all the parts needed to mount the filesystem, especially on a modern Linux distro that supports a wide variety of hardware.

Initramfs exists so that parts of the boot logic can be handled in userspace. Part of this includes deciding which device drivers to load as kernel modules, using something like udev.

Another part is deciding which root filesystem to mount. The root FS might be on an LVM volume that needs to be configured with device-mapper, or unlocked with decrypt. Or it might be mounted over a network, which in turn requires IP configuration and authentication. You don't want the kernel to have those mechanisms hard-coded, so initramfs allows handling them in userspace.

But strictly speaking, you don't need any of that for a minimal system. You can boot without initramfs at all, as long as no special userspace setup is required. i.e., the root FS is a plain old disk partition specified on the kernel command line, and the correct drivers (e.g. for a SCSI/SATA hard drive) are already linked into the kernel.

ktpsns 4 days ago | parent | next [-]

When I used Gentoo, where you typically configure&compile the kernel yourself, I never used initramfs.

This was 20yrs ago. Gentoo was really a great teacher.

spwa4 4 days ago | parent [-]

Problem with that was that you'd run literally every module initialization and occasionally there were some that crashed the kernel.

piperswe 4 days ago | parent [-]

Only if you compiled your kernel with literally every module. If you compile your kernel with only the modules your system needs, there’s no such issue

compsciphd 3 days ago | parent [-]

which then made it difficult to upgrade your hardware.

piperswe 3 days ago | parent [-]

Well yes, when you start customizing Gentoo it tends to make hardware changes more difficult. e.g. march=native makes CPU changes difficult, but it's still very common on Gentoo

seanw444 4 days ago | parent | prev | next [-]

I've used Linux for quite some time, and had always kinda wondered what purpose initramfs served, since I have to rebuild it so often. Thanks.

tosti 4 days ago | parent [-]

Linux includes a cpio utility and documentation for building your own initramfs.

tosti 4 days ago | parent | prev [-]

This. Only CPU microcode can't be loaded without an initramfs unless you enable late loading, but that's labeled dangerous because it may cause instability. If needed, you could let the built-in motherboard uefi do the microcode updates instead.