Backup and Restore the Operating System with Clonezilla

There are several open source programs that allows for GIS and Remote Sensing analyses. Personally, I  often install several new programs and try them for a while. Sometimes I need to uninstall those programs in order to free hard disk space, but this can be a tedious process.
It can be useful to create a backup copy of the whole hard disk or partition (including operating system and data). This way, the operating system can be restored in a few minutes, along with all the programs and settings that were at the backup time.
This post is about how to create a backup of system partitions with Clonezilla, which is open source software and works with most file systems.
At the end of this post you can find the video of this tutorial.

Attention! Backup or restoring system partitions are delicate processes, which can imply loss of data. Always backup important data to external hard disks or CDs and DVDs, before attempting to backup or restore system partitions.

Clonezilla is a live CD, which allows for the backup of several file systems (such as ext2, ext3, ext4, FAT32 and NTFS), saving only used blocks in the hard disk.
Firstly, download the latest stable image from here. Choose a version according to your CPU, and select the file type iso. After downloading (about 120 MB), burn the iso file to a CD; therefore, boot the computer from the CD.

Hint for Linux users: if you use the GRUB boot loader, it is possible to add an entry for Clonezilla Live, in order to backup and restore your system without a CD.
The following steps add the Clonezilla entry to the menu of GRUB 2, in a Debian based distro:
  1. Having root privileges, create the directory /clonezilla ; move the  Clonezilla iso file into this directory and rename the file as clonezilla.iso.
  2. Edit the file (if file does not exist, create it) /etc/grub.d/40_custom as follows
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Clonezilla" {
 set isofile="/clonezilla/clonezilla.iso"
 loopback loop $isofile 
 linux (loop)/live/vmlinuz boot=live live-config  union=aufs nolocales noprompt nomodeset gfxpayload=800x600x16 ip=frommedia nosplash toram  findiso=$isofile
 initrd (loop)/live/initrd.img
  1. Open a terminal and, as root, type update-grub and press Enter; this way, a new entry is added to the GRUB list, which will be available after a system restart. If you select the Clonezilla entry, Clonezilla will be loaded to RAM.

In this tutorial, I am going to backup a 10 GB ext4 partition to an USB external disk (100 GB, FAT32); of course, your configuration may be different. You can practice using a virtual machine and VirtualBox, before  using Clonezilla on your system.
Use the arrow keys to navigate through the menus of Clonezilla (you could also use the mouse, but I find arrow keys more practical).
  1. Start the Clonezilla live system
    • Select the first entry Clonezilla live and press Enter ; the system will load in a few seconds.

  1. Choose the language and configure the keymap
    • Use the arrow keys to highlight your language (we are going to use English) and press Enter;
    • You can select the keymap from a list; if you do not have particular needs, select Don't touch keymap and press Enter.

  1. Start Clonezilla and mount the image directory
    The image directory is where to save the system backup that, in our case, is the external hard disk.
    • Press Enter to start Clonezilla;
    • Select local_dev under Mount Clonezilla image directory and press Enter;
    • Insert the USB external disk, wait 5 seconds, then press Enter;
    • Select the partition of the external hard disk (in this case sdb1) and press Enter;

Hint: The names of system partitions start with sd (or hd) followed by a letter (for instance a), which distinguish the hard disks, and a number that distinguish the partition (for instance 1). In order to identify which is the external disk you need to pay attention to the text beside partition name. That text displays useful information such as the disk size (for instance 100G stands for 100 GB), and the file system (vfat stands for FAT32 file system).
    • Clonezilla can save backups only in the top directory of the hard disk, or in a subdirectory  of the top directory (first level), but not in a second level directory; select Top_directory_in_the_local_device and press Enter;

    • After a few seconds, Clonezilla will show the disk space usage;  press Enter.

  1. Backup the system partition
    • Choose the mode Beginner and press Enter;

    • Select saveparts and press Enter;
    • Type the name of the backup directory (a new directory that will be created in the top directory  of the external disk), which describes the backup (for instance the backup date is OK);
    • Choose the partition to backup (if you have more than one partition on your local disk, use the arrow keys to highlight the system partition and press the spacebar to select it), and press Enter;
    • Press Enter to skip checking/repairing source (we assume that the system partition has no issue);
    • Press Enter to check the saved image (this is optional, but it is safer to check if  the image is saved correctly);
    • Press Enter again to continue; then type y beside Are you sure you want to continue? and press Enter.

The backup process will start, and it will be completed in a few minutes, depending on your system disk size.

When the process is completed, press Enter to continue and select poweroff to shut down the system and eject the CD. The backup is in your external disk.

When you want to restore the system backup, follow the above steps from 1 to 3; then:

  1. Restore the system backup
    • Choose the mode Beginner and press Enter;
    • Select restoreparts and press Enter;
    • Use the arrow keys to select the backup name and press Enter;
    • Select the target partition where the backup will be restored (Attention! All the files in this partition will be deleted, so be sure to select the right partition), and press Enter;
    • Press Enter again to continue;  then type y beside Are you sure you want to continue? and press Enter;  type y beside Let me ask you again. Are you sure you want to continue? and press Enter.

Clonezilla will start to restore the system. When the process is completed, press Enter to continue and select reboot to restart the system and eject the CD; the operating system is restored to its previous state.

The process is a bit more complicated if you want to restore the operating system to a different disk partition, because the different position could break some settings of the operating system. However, Clonezilla offers several other options and modes, such as system cloning; for further information please visit the official website.

The following is the video of this tutorial.