Linux Administration for Nerds

Copyright 2018 Brian Davis - CC-BY-NC-SA

Clonezilla

Clonezilla is a tool for cloning disks and partitions. Not only can you clone physical disks but you can also clone virtual disks. This gives us a powerful tool for moving systems from the virtual world to the physical and back again.

The process looks something like this:

  1. Create a virtual machine
  2. Install and configure operating system and applications
  3. Boot the virtual machine using a Clonezilla ISO
  4. Insert a USB stick a redirect it to the VM
  5. Clone the virtual disk to an image on the USB (alternatively you could clone the virtual disk to the USB directly and get a bootable USB out of the deal)
  6. Boot target machine with Clonezilla CD or USB
  7. Restore from image on USB stick

To create a Clonezilla bootable USB stick:

  1. Download Clonezilla .zip file from clonezilla.org
  2. Unzip directly to a recently formatted USB (see note below about partitions)
  3. Go to your USB drive, to utils/ and run the appropriate makeboot script

Note about partitions: Clonezilla will need a place to save the images it makes.
You could just use the root of the USB drive where you installed Clonezilla, or you could create a separate partition to mount as /home/partimag. This is useful because if you boot your virtual machine using the Clonezilla iso, you can have it mount the partition from the USB drive and have it save the image there.

Installing from a live system

If you have a live Linux system running from a CD or USB drive you can install that system to the target machine. The basic steps are:

  1. Partition the target disk as you see fit
  2. Create your desired filesystem(s)
  3. Copy the live system to the target
  4. Mount the virtual filesystems
  5. Change root into the target drive
  6. Install grub

Below are the commands I used for a target system with a btrfs filesystem.
Notice the extra step of remounting with the subvolume as the root. In this case it was a flash disk so I chose to forgo swap).

mkfs.btrfs /dev/sda1
mount /dev/sda1 /mnt/sda
btrfs subvolume create /mnt/sda/rootfs
mkdir /mnt/sda/snapshots
cp -rp /mnt/btrfs/rootfs /mnt/sda/rootfs
umount /dev/sda; mount /dev/sda1 -o subvol=rootfs /mnt/sda
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt/sda$i; done
chroot /mnt/sda
grub-install /dev/sda
update-grub