Is the entire kernel loaded into memory on boot?

The entire kernel is loaded into memory at boot, typically along with an initramfs nowadays. (It is still possible to set up a system to boot without an initramfs but that's unusual on desktops and servers.)

The initramfs's role is to provide the functionality needed to mount the "real" filesystems and continue booting the system. That involves kernel modules, and also various binaries: you need at least udev, perhaps some networking, and kmod which loads modules.

Modules can be loaded into the kernel later than just boot, so there's no special preparation of the kernel by the initramfs. They can be stored anywhere: the initramfs, /lib/modules on the real filesystem, in a development tree if you're developing a module... The initramfs only needs to contain the modules which are necessary to mount the root filesystem (which contains the rest).


The entire kernel (but not its modules) will be loaded into memory. If there are modules which the kernel will need before any filesystems are available (this usually means the drivers for the filesystems and their devices), then those modules will be in the initramfs (in memory), and the kernel will load them from there. Other modules can be loaded later from the file system.


The kernel in modern Linux setups is heavily module based, i.e., the kernel proper (loaded on boot into RAM) includes just the bare minimum functionality, all the rest is compiled as modules (loadable at runtime). To make this work even when e.g. the devices or filesystems required for boot are modules, an initramfs is loaded with the kernel (as the name implies, this is a RAM area with a simple filesystem, mounted on boot). This temporary filesystem is mounted on /, and contains startup programs and the required modules. Once the startup on initramfs is done, Linux executes a pivot_root(8), mouning the real / and tossing the initramfs contents.

The point of this complexity is that e.g. a distribution can compile one kernel (minimal kernel and full set of modules), and on installation of the kernel create an initramfs tailored to the hardware and setup of the target machine. All this is required due to the wild variety of devices and configurations of "Personal Computers".