Linux – don’t we include File System drivers in the kernel itself instead of using Initrd/Initramfs

bootinitramfsinitrdlinux-kernel

The Linux kernel contains very minimal code that is necessary to boot on a majority of devices but I don't get the point of having Initrd/Initramfs.
As far as I've understood Initrd/Initramfs job is to temporary provide the file system drivers to actually load the root file system.

If this the case, then why don't we simply add the necessary file system drivers into the kernel itself.
We have to ultimately load both the kernel and the Initrd/Initramfs so why no integrate both into one image file since both of them take the same amount of memory.

*******Update******

1. What actually constitutes the linux kernel? Is it just the vmlinuz image(approximately 5-6MB) or the collection of loadable modules,vmlinuz image, initrd file and other components.

2. Why is the size of the kernel image vmlinuz(approx 5-6MB) less than size of initrd file(approx 18MB). The kernel contains the code for many other things as compared to initrd that just contains code to mount the File system.

Best Answer

First, it's not just the filesystem drivers. It's also the drivers for whatever storage device the filesystem is on. And possibly more if you use LVM, encryption, etc.

Regardless, it's definitely possible to build them into the kernel. I know slackware at least has a kernel choice named 'huge' which does just that and does not require an initramfs for typical PC hardware.

The downside is that such a kernel has to include everything anyone might possibly need: every possible filesystem that might be used as root, the device drivers for whatever might hold that filesystem, etc. So you end up with a bloated kernel which contains a lot of unused code and wastes memory.

I think there are also some drivers which can only be built as kernel modules but that's more a design choice than a real technical limitation.

Answer to edits:

  1. It probably depends who you ask and in what context. To me, it's everything which runs in kernel space so that includes all the drivers. A kernel developer might have a different view with many more names for different pieces.

  2. Actually, the vast majority of the kernel code is loadable modules and drivers. Some of those are quite large. On my system, btrfs alone is 500 kB compressed. NFS is nearly as large. ext4 is 300 kB. There is a huge number of supported storage devices as well and you might need any of them to get your root filesystem. Just browse through /lib/modules/*/kernel/drivers/ on a linux system and you'll see.