Wednesday, June 8, 2016

Restore a chroot to a different machine

On a chromebook you can set up chroots. This is possible through crouton. Chroots are separated environments that run all your linux software on the same kernel as the host machine. The result is you can take a chroot and copy it to a completely different machine and everything will run as before. That is just a fantastic and super easy way to keep all the environments on different machines in sync. So I routinely copy over chroots from one to the other machine, here is how to do that.

I use a chromebox and a chromebook. The chromebox is faster and has a better internet connection (over ehternet). So I tend to set up the chroot on the chromebox and then copy it to the chromebook. That is actually very easy.

The chromebox becomes the source machine and the chromebook is the target. The first step is to make a backup of your chroot on the source machine.

cd ~/Downloads
sudo edit-chroot -b trusty

Now copy the backup to a medium. I use a USB stick.

cp trusty-datestring-timestring.tar.gz  /media/removable/USB\ Drive/

That datestring-timestring will look like 20160607-2007 or similar.

On the target machine remove the old chroot if the name is the same, otherwise you can leave it there. Then insert the USB Drive and restore the chroot.

To remove the old chroot: sudo edit-chroot -d trusty

I assume you already have crouton on this device if not download it from https://goo.gl/fd3zc

cd ~/Downloads
sudo sh -e crouton -r trusty -f /media/removable/USB\ Drive/trusty-datestring-timestring.tar.gz 

That is all. You now have an identical chroot with all your software on the target machine.

I have set up virtual box on the source machine so when I fire up the chroot on the target I get this error.

/etc/rc.local failed with code 2

You can either set up the condition for virtual box (see my post from June 7) or get rid of the error. To get rid of the error make rc.local non executable with:

sudo chmod 644 /etc/rc.local

The error will not reappear. Obviously virtualbox will not be able to start on the target machine.

Written with StackEdit.

1 comment: