Linux – How is the kernel loaded

grubkernellinuxlinux-kernel

I am trying to understand the Linux boot process, and after reading quite some amount of documentation there is one point that I still can't seem to understand.

So the basicis is BIOS -> Grub MBR -> Grub CONF -> Kernel …

with a grub conf that can look like this

title CentOS (2.6.32-358.2.1.el6.i686)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-358.2.1.el6.i686 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-358.2.1.el6.i686.img 

So based on my understanding of the documentation + post I read, kernel will be loaded + mount initramfs as root filesystem. Then init will be executed which will be in charge to do a bunch of various stuff to get the system up and running.

My question is : How is the Kernel loaded?

I mean since the kernel is in /boot/vmlinuz-2.6.32-358.2.1.el6.i686 of my device (hd0,0) the filesystem needs to be mounted somehow first so it can be accessed.

If (what I suspect) Grub mounts hd0,0 partition does it do first a pivot_root with initramfs then another pivot_root with the actual root= fs specificied as kernel parameter ?

Any explanation / links that can help me understand a bit better how is this all working togetheris welcome,

Best Answer

Grub has its own filesystem drivers. It doesn't use Linux's. Grub loads the kernel and initrd into memory according to the Linux kernel boot protocol. A part of the kernel is loaded at a predefined address, and Grub sets some parameters so that the kernel knows where to find the rest.

When the kernel boots, it mounts a root partition using its own drivers (which cannot be modules since there are no modules at that point). The root partition can be an initrd, an initramfs, or (in the absence of an initramfs or initrd) the block device indicated by the root command line argument (or a compiled-in default if there is no root argument).