Linux – Given vmlinuz and initrd.gz, how to find out, where the kernel is going to load / (root) file system from

bootinitramfskernellinuxroot-filesystem

I'm trying various ways of Linux installation (from iso, flash, iso on flash, kernel on flash, root FS in iso-file on flash…) and want to understand what's going on.

My question is: is it possible, given the built kernel and ramfs files from a distribution (vmlinuz and initrd), to find out, where they are going to look for the "/" file system? Is it possible to configure this without re-compiling the kernel?

And one more: when kernel loads the root filesystem from loopback device, created from .iso-filesystem, how can I configure this process? Thanks!

EDIT:
In fact, GRUB configuration contains GRUB root, which is not the real kernel root filesystem location, but just a folder that contains GRUB's belongings,.

The real root is configured in init script in initrd as described here.

That's how Debian kernel finds an ISO file on hard drive, when booting from it – initramfs finds it: http://www.debian.org/releases/stable/i386/apas02.html.en#howto-getting-images-hard-disk; note that GRUB configuration doesn't contain any reference to ISO location.

Best Answer

It is given at boot time by your bootloader, for example Grub.

To see with which arguments your kernel was started, do this:

$ cat /proc/cmdline

For me, this ouputs:

BOOT_IMAGE=/vmlinuz-3.5.0-13-generic root=/dev/mapper/crypt-precise--root ro

So the initrd/initramfs will try to mount my /dev/mapper/crypt-precise--root (encrypted LVM) logical volume as /.

You can re-configure Grub to load other operating systems from your harddrive using the same kernel (multi-boot) or edit this line runtime by pressing e while selecting (not yet booting) the Grub entry.

For recent Debian-based distributions, changing it permanently works like this:
(be careful, you may not be able to boot into your original operating system again!)

In the file /etc/default/grub set some GRUB_CMDLINE_LINUX="root=/dev/mydevice" yourself and update Grub by doing update-grub.

However, I recommend you to configure multiboot, otherwise it's not possible to change or update your Grub configuration again easily.

Related Question