How to Use Clonezilla to Back Up and Migrate VPS
In a previous tutorial, I explain the process of backing up your hard drive with Clonezilla, which is a free open-source disk imaging and cloning tool. Clonezilla can also be used to back up and migrate your Linux VPS (Virtual Private Server).
The Importance of Backing Up Your VPS
On March 10 2021, a fire completely destroyed OVH’s Strasbourg data center, causing millions of websites offline. Users who don’t have disaster recovery plan have no way to recover their data. If you back up your VPS with Clonzilla, you can easily restore it after an incident like this. You can use Clonzilla to create an image backup of your VPS. You can also migrate it to another VPS hosting provider if you like to.
Clonezilla Features
- You can create an image of the current disk or partition (disk imaging), and restore the image to disk at any time.
- Allows you to clone directly between two disks (disk cloning), without creating a disk image.
- The disk image can be encrypted with ecryptfs, and saved to or read from local disk, SSH server, Samba server, NFS server, WebDAV server or AWS S3 storage.
- The disk image can be compressed with GZIP or ZSTD algorithm.
- Supports lots of file systems like ext4, XFS, Btrfs, F2FS, FAT32, NTFS, HFS+, UFS.
- Supports MBR and GPT partition table.
- Supports BIOS and UEFI firmware.
- Clonezilla Server Edition allows you to do massive system deployment over the network.
- Unattended mode: Almost all steps can be done via commands and options.
Prerequisites
To use Clonezilla to back up or migrate VPS, your hosting provider needs to allow you to boot VPS from a recovery ISO or custom ISO image. The following is a list of supported hosting providers/hosting platform.
Step 1: Booting Up Your VPS from ISO Image
Clonezilla can create an image of the current disk on your VPS, preserving every transaction. The downside is that you need to shut down the VPS and do it from a live or recovery ISO. This is because Clonezilla currently doesn’t support online imaging/cloning. The partition to be imaged or cloned has to be unmounted.
Clonezilla is included in the repository of Debian, Ubuntu and Arch Linux. In this tutorial, I will use Ubuntu server as the live ISO. If your hosting provider supports custom ISO image, then you can use the Clonezilla Live ISO, so you can start using Clonezilla right away, without having to find and install missing software components for Clonezilla.
Go to your VPS control panel. Attach Ubuntu ISO image to your VPS, then establish a VNC connection to your VPS. You can get VNC login info from your hosting provider. Many hosting companies also allow you to use a web-based console to access your server. Next, shut down your VPS and boot it up from the Ubuntu ISO image. (If you don’t know how to do this, ask your hosting provider.)
Note: It’s recommended to use the Ubuntu server live ISO, instead of Ubuntu desktop ISO, because Ubuntu desktop consumes lots of RAM. If your server has only 1GB RAM, you will run out of RAM when using Ubuntu desktop.
Normally you have to press a key like ESC
or F12
in the VNC window to bring up the boot menu, which allows you to select which device your VPS will boot from. Select optical disk drive so your VPS will boot the Ubuntu ISO image. Note: The default firmware for KVM virtual machines is called SeaBIOS.
After the Ubuntu live installer is running, choose your language and keyboard layout.
Then configure the network connection.
Don’t continue the installation, but send the Ctrl+Alt+F2
key combination to your VPS, so you will switch to a virtual terminal.
Try to ping 8.8.8.8 to see if your VPS is connected to the Internet.
ping 8.8.8.8
Now your VPS is connected to the Internet, install Clonezilla with:
sudo apt-add-repository universe sudo apt update sudo apt install clonezilla net-tools sshfs ecryptfs-utils binutils e2fsprogs screen
Step 2: Back Up Your VPS with Clonezilla
Before backing up the VPS, I recommend using the GNU Screen utility, so if you lost network connection, you can still re-connect to your previous SSH session. To use GNU Screen, simply run in the following command.
screen
You will see an introduction text, press Enter and you will be able to use the command line as usual. Next, run the following command to start Clonezilla.
sudo clonezilla
If you use the Clonezilla Live ISO image, you have the option to choose a language.
And you can change the keyboard layout. (I use the default US keyboard.)
Then, it asks you if you want to use the Clonezilla wizard (which is easy for beginners) or use the command-line interface). Choose the first option to start the Clonezilla wizard.
Next, select a mode. This tutorial selects the first mode.
- device-image: create an image of the current disk or partition
- device-device: clone directly between two disks, without creating a disk image.
After that, choose where the Cloned image will be saved. You have many options: local device
, SSH server
, Samba server
, WebDAV Server
, AWS S3 server
, etc. This tutorial selects SSH server, so the disk image will be transferred to another server over SSH connection.
Next, enter the IP address or hostname of the SSH server where you want the disk image to be stored.
Choose SSH port.
Enter the SSH username.
Enter the directory where you want the disk image to be stored. Make sure the directory exists on the SSH server.
Enter SSH password.
Next, choose between beginner and expert mode. If you are a Clonezilla beginner, then choose the beginner mode.
In the next screen, you can choose to save an entire disk as an image or save a specific partition as an image. This tutorial chooses the first one (savedisk
).
Then give the image a name.
And choose which disk you want to make a backup of.
Next, choose which compression algorithm you want to use to compress the image.
After that, choose if you want to check the disk file system before backing it up. The file system check is very fast, so I recommend checking the file system.
And choose if you want to check the image is restorable.
In the next screen, you have the option to encrypt the image, which is useful if you save the image on a network location, so I choose to encrypt the image.
And choose which action to take when everything is finished.
Now Clonezilla kindly gives you the equivalent command-line, so you can enter this one-liner next time you make a backup without going through all the questions again. Press Enter to continue.
Then enter a passphrase to encrypt the disk image. You will need to enter it twice.
Press y
to start saving your disk to an image.
Once Clonezilla finishes its job, you can reboot your VPS. If the process failed, you can check the /var/log/partclone.log
file.
Migrate to a New VPS Hosting Provider
If you want to migrate to a new VPS hosting provider, then create a new VPS instance at the new hosting provider. The disk size of the new VPS must be equal to or larger than the disk size of the old VPS. Next, you can restore the Clonezilla image to your new VPS. The restoration process is very similar to creating a backup. I won’t explain every step but show a few key steps.
First, you need to follow the same procedure described in step 1 to boot up the new VPS from an Ubuntu ISO, connect to the Internet, and install Clonezilla.
Then, Use fdisk
to create a disk layout same as the old VPS:
- same partition table
- same file system
- same sector number
You can run the following command on the old VPS to print the disk layout.
sudo fdisk -l /dev/sda
To create disk partitions on the new VPS, run:
sudo fdisk /dev/sda
Follow these instructions.
- You need to delete existing partitions by pressing
o
org
.o
will create MBR partition table.g
will create GPT partition table. - Type n to create a new partition.
- Type p to select primary partition.
- Type 1 to create
/dev/sda1
. - Press Enter to choose the default first sector
- Use the same last sector location as your old VPS for
/dev/sda1
. - Type n again to create the second partition.
Once the partitions are created, press w to apply the changes.
Next, start Clonezilla.
sudo clonezilla
Choose your language, keyboard layout and start the Clonezilla wizard, choose the device-image
mode to restore the image to disk.
Then select where the image will be read from. I stored the image on a remote SSH server, so this time I also make Clonezilla read the image from the remote SSH server.
If you choose to read Clonezilla image from a network location, then follow the instructions to set up network connection and authentication (username and password).
After that, you should be able to choose the restoredisk
mode to restore an image to local disk.
And follow the rest of the instructions.
When restoring the image to disk, Clonezilla will convert the device name of the disk partitions if they are different (for example, vda to sda).
Restoration complete.
Before restarting your VPS, you can run the following command to get the MAC address of the main network interface, which you might need when configuring network connection.
ip addr
Now you can reboot the new VPS from disk drive. If your OS is not bootable, you may need to update /etc/fstab
file. Copy the content of /etc/fstab
file from the old VPS.
Change Network Connection for the New VPS
After the image is restored on the new VPS, boot up the new VPS without the live operating system. Since the cloned disk contains network settings for the old VPS, you need to log in via VNC console and update the network configuration for the new VPS.
If you use CentOS/RHEL, you can update network configuration with:
sudo nmtui
For the changes to take effect, you need to deactivate the existing connection and activate it again.
If you use Ubuntu, the network configuration can be edited under the /etc/netplan/
directory. Note that you need to change the MAC address. Once you finish editing netplan file, run the following command to apply your changes.
sudo netplan apply
Now your new VPS should be able to connect to the Internet.
Troubleshooting
Unable to find target partition sda1
If you see the following error when restoring the Clonezilla image to your new VPS, it’s likely that your Ubuntu live system doesn’t have the command required by Clonezilla to create disk partitions (unsupported command). You can use the fdisk
command as described above to create disk partitions before using Clonezilla to restore the image on your new VPS.
Wrapping Up
I hope this tutorial helped you use Clonezilla to back up or migrate your VPS. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂
Great way to save a vps to another.
But is there a way to save a image from a proxmox server in home lan to another server in home lan, without
to use a usb stick for clonezilla ? Best way to have three computer. computer A for clonzilla computer b is the proxmox server and computer c a NAS for save the image form computer b.
bro u a homie frfr, saved me from paying 20$ fees per month for hosting the snapshots on vultr