In this tutorial, we will see how to clone a Linux system to another computer with borg in a few steps.
You might want to clone a Linux system so that you don’t want to reconfigure and install the same packages again to your new installation. Recently I faced the same situation where I wanted to clone my office’s Linux system to my laptop. I found a few ways of cloning the system in internet along with Borg, a deduplicating backup solution which supports encryption, compression and provides very efficient & secure way of backup.
I’ve tested this method with Xubuntu (Ubuntu based distribution) and cloning works fine. It should work in other distributions too as long as you exclude the correct file systems. However, it might not work for different architectures (ex: cloning 64 bit system to 32 bit system or vice versa).
Borg is very well documented. Visit their documentation website and install Borg. Also check the Quick Start guide. So install the Borg in the machine from which you want to clone and initialize a repository (basically a password protected path where you want to save your backup).
Now we will backup the root partition excluding some directories and files. So navigate to the root directory first
Now we will execute the following command. Make sure to replace the _/path/to/repo _to the repository path which you initialized in Quick Start guide. That path will store the backup files. We also excluded the repo path so that it doesn’t include in backup archive.
Borg will now backup the entire file system(s) excluding some system files and directories. The archive name will be
MyBackup_1. When finished, copy the backup directory to your external drive so that we can restore from it later (if you set
/path/to/repo to external drive, then you are ready to restore)
First, install the same Linux distro as usual in another computer. And install borg. You don’t need to initialize the repo.
Connect your external hard disk/usb drive where you saved the backup. Suppose the external drive is mounted to
Now execute the below commands in newly installed Linux
Now let’s restore the backup. Make sure to replace the
/path/to/repo and the
_archive name. Like
/run/media/usb::MyBackup_1 Also we will backup
/etc/grub directories and files in order to avoid the grub error after restoring the backup
Wait until the process finishes. After that, restart the system. Done!