Pivot root between two Linux installations

chrootdistros

I have two Linux distributions installed (Debian and Ubuntu). Each with its own usr, swap, and whatever. Both are completely independent, each in its partition.

According to the man pages, I could pivot between them with:

cd new_root
pivot_root . put_old
exec chroot . command
umount /old-root

Is that that easy? Could I break something doing this (like files being copied or overwritten in any installation).

Will this just stop running the distribution A and start running the distribution B 'as if' I had re-booted?

Both distributions have different kernels.

Best Answer

pivot_root is actually used at boot time in order to jump from a ramdisk into the real root. It is easy. When you get managed that no process accessing the old root file system, then you can also umount your old root.

It is also not possible to run more than one kernel at the same time, except you use some virtualization techniques.

If you are on Debian and want to run some programs on Ubuntu and assume you have a kernel which works on both, then you can easy chroot to it:

mount /dev/vg/ubuntu-root /mnt/ubuntu
cd /mnt/ubuntu
for p in dev proc sys; do mount --bind /$p $p; done
chroot . /bin/bash --login

or perhaps much easier

kvm -m 900 -vga std -hda /dev/vg/ubuntu-root
Related Question