Load root filesystem from USB device

277 Views Asked by At

I'm trying to make a fast reboot to the other Linux system. First step is kernel loading, I make it with
sudo kexec --append='$(cat /proc/cmdline)' -l new_kernel.img --reuse-cmdline
sudo kexec -e
It works fine, but loads only kernel, not entire system.

How can I mount an *.img file with OS resources, located at USB as /? Preferable during kernel loading, but afterwards mount is still suitable. *.img format is not necessary, it can be unpacked before

1

There are 1 best solutions below

0
iOS On

As stark said, pivot root() was the call I was searching for. Commands to make a USB located at /dev/sdb1 a root directory:

sudo -s
mkdir /newroot
mount /dev/sdb1 /newroot
cd /newroot
mkdir oldroot
pivot_root . oldroot/

switch_root() deletes all files at the previous root dir, also there are few other differences, this answer might be useful