# Mount the root filesystem.
1 .mount -o ro /dev/sda1 /mnt/root
# Boot the real thing.
2 .exec switch_root /mnt/root /sbin/init
This is a piece of code from /init file of initramfs as mentioned in gentoo. here the rootfs mounted to /mnt/root and later switch_root is performed with /mnt/root as newroot and /sbin/init as destination.
After line 1 is executed the contents of /dev/sda1 is mounted at /mnt/root. i tried,
sudo mount -o ro /dev/sda1 /mnt/temp
and got this message,
mount: /mnt/temp: /dev/sda1 already mounted on /boot/efi.
so I tried, cd /boot/efi
and it stated
cd: command not found
so I tried ./efi
in the /boot dir but now i got this msg,
bash: ./efi: Is a directory
then i tried to view the contents of /sbin/init as:
cd /sbin/init
but now it says,
bash: cd: /sbin/init: Not a directory.
i am confused .how come /dev/sda1 and /mnt/root are directories but all of a sudden /sbin/init is an executable ? shouldn't that be a directory as well ?
cd: command not found
from a shell sounds curious, especially since later thecd
worked. I'd guess you did something odd when entering that command. – ilkkachu Aug 26 '20 at 17:23/sbin/init
isn't the destination, it's the program to execute as the newinit
. – Shadur Aug 26 '20 at 17:30switch_root /mnt/root /sbin/init
switch_root here should move the contents of/mnt/root
to/sbin/init
and make/sbin/init
as the new root filesystem. if the contents are moved then whatever is present in /mnt/root will be present in /sbin/init right ? so if /mnt/root is a directory then /sbin/init must also be a directory right ? – ferb Aug 26 '20 at 17:31switch_root
does at all. If you'll look at the manpage, it explicitly says what it does. – Shadur Aug 26 '20 at 17:34