2

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

iOS
  • 61
  • 1
  • 4
  • You want pivot_root – stark Aug 25 '21 at 12:49
  • From man page: pivot_root() changes the root mount in the mount namespace of the calling process. But at the end there are also few words about switch_root(), which seems more suitable for my purposes – iOS Aug 25 '21 at 13:07

1 Answers1

0

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

iOS
  • 61
  • 1
  • 4