Cloning an Ubuntu system with rsync

It is great to be able to quickly reinstall a whole Linux system without having to install package by package.

The way I found to do this, instead of imaging the system or reinstalling the boot manager, is to simply install the same distribution from scratch on another HD and copy the whole system from a donor to the new system. I have done this with the new system running and it worked just fine.

The only catch is that you need to use the same (or at the very least a very similar) installation image. The goal here is to replicate a system, avoiding all the reconfiguration and package installation, not to upgrade it. When I upgrade, I install and configure from scratch as every once in a while something important changes.

sudo rsync -acv --delete --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys \
                         --exclude=/dev --exclude=/tmp --exclude=fstab \
                         /sourceOS /

In my case, /sourceOS was an external HD containing the donor system and / was the root directory in the new system.

After I copied the /sourceOS into /, I had to regenerate /boot/grub/grub.cfg because it pointed to the UUID of /sourceOS.

sudo update-grub

When I rebooted the computer, it booted into the new OS, but with all the changes made in the source OS, as expected.

When doing this on an offline system, it will be necessary to chroot into the cloned system to run update-grub.

The command below will allow you to accomplish the above. Run it from your live system before you run update-grub:

mount /dev/sdX /mnt/cloned
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt/cloned$i; done
chroot /mnt/cloned

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s