Linux Administration for Nerds
Copyright 2018 Brian Davis - CC-BY-NC-SA
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:
- Create a virtual machine
- Install and configure operating system and applications
- Boot the virtual machine using a Clonezilla ISO
- Insert a USB stick a redirect it to the VM
- 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)
- Boot target machine with Clonezilla CD or USB
- Restore from image on USB stick
To create a Clonezilla bootable USB stick:
- Download Clonezilla .zip file from clonezilla.org
- Unzip directly to a recently formatted USB (see note below about partitions)
- 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:
- Partition the target disk as you see fit
- Create your desired filesystem(s)
- Copy the live system to the target
- Mount the virtual filesystems
- Change root into the target drive
- 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