4

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.

| improve this question | | | | |
4

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
| improve this answer | | | | |
2

Is that that easy?

You'll have to have everything in system A shut down, I think, or you won't be able to umount the old root.

You can use chroot on its own without pivot_root, in which case both systems can be accessible at the same time, e.g., by switching VT's, or just starting from a GUI terminal (this means not umounting old root, too). I recommend you try this out first.

Could I break something doing this

It isn't a serious risk, no.

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

Not as if you had rebooted, no. I've actually never tried this with a full-fledged distro installation, but I think one issue will be that the usual system services won't be running. Nothing will be running but your instance of the shell, and init. So if you want to make things normal, you'll have to tell init/upstart something to get it to start services. This is one reason tooling around with just chroot will be easier until you have everything figured out, since if something gets screwed up, system A will still be running and you can start again from there rather than having to reboot. It's also easy to copy stuff back and forth from the perspective of system A (just be sensible about it, e.g., don't replace in-use files).

Both distributions have different kernels.

Only the system A kernel will be used. I think it is possible to hot swap kernels (q.v. kexec) but that is a whole other question, and something you probably want to avoid if possible. It should not be necessary anyway.

However...

Make sure you place a copy of the /lib/modules/x.x.x directory for the system A kernel in the system B root filesystem, or you won't be able to load any kernel modules!

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.