Considering that GRUB executes following lines:
kernel /vmlinuz root=/dev/sda1 ro
initrd /initrd
On boot, how does the Linux kernel finds out about /dev/sda1
device node?
I know that initrd/initramfs images contain modules for storage (etc.) devices, which are loaded into memory to enable access to the storage. What bugs me, is how exactly the kernel parameter root=/dev/sda1
is parsed by the kernel.
Does the /init
(or /linuxrc
) script in initrd/initramfs creates the /dev
directory and then the device node /dev/sda1
in it? Or the "major" and "minor" numbers for /dev/sda1
are hardcoded in the kernel?
Best Answer
If you have an initramfs the kernel just unpacks and mounts the initramfs and executes
/init
afterwards. Everything else will be handled by the/init
executable. This also means the kernel doesn't mount the device specified in theroot
boot parameter.Different Distributions use different initramfs frameworks like e.g. dracut for Fedora or initramfs-tools for Debian. Most common solutions are either using something like
udev
,mdev
ordevtmpfs
. Some may also just useMAKEDEV
to generate a static layout or have the device files already integrated into their image.If you boot without an initramfs the kernel can just boot from devices with known major/minor numbers, e.g.
/dev/sda1
but not from lvm devices.