Skip to content

Instantly share code, notes, and snippets.

@rksm
Created March 11, 2024 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rksm/c8b5ced305fdd619d0868454d1eccb38 to your computer and use it in GitHub Desktop.
Save rksm/c8b5ced305fdd619d0868454d1eccb38 to your computer and use it in GitHub Desktop.
clonezilla

Using Clonezilla to create and restore a hard drive snapshot is a multi-step process that involves booting into a Clonezilla environment, creating the image, and then later restoring it. Clonezilla should handle copying the EFI partition and setting up the bootloader, but additional steps may be required if you're restoring to a new drive. Here’s how you do it:

Creating a Snapshot:

  1. Download Clonezilla: Go to the Clonezilla website and download the appropriate Clonezilla live CD/USB image.
  2. Create Bootable Media: Burn the downloaded ISO to a CD or use a tool like dd or Rufus to create a bootable USB stick.
  3. Boot Into Clonezilla: Insert the bootable Clonezilla media into your computer and boot from it. You may need to select the boot device or change the boot order in your BIOS/UEFI settings.
  4. Choose Language and Keyboard: Select your preferred language and keyboard layout in the Clonezilla menu.
  5. Start Clonezilla: Select "Start Clonezilla".
  6. Select Mode: Choose "device-image" to work with disk images.
  7. Choose Local or Network Storage for the Image: Select where you want to save the disk image. For a local storage device, choose a connected drive that is not the source drive.
  8. Choose Source Disk: Select the disk or partition you want to create an image of.
  9. Choose Image Repository: Select the directory where you want to save the image.
  10. Choose Filename and Save Options: Provide a name for the disk image and select any additional parameters you want, like encryption or compression.
  11. Start Cloning: Confirm and start the cloning process. Wait for it to complete.

Restoring a Snapshot:

  1. Boot Into Clonezilla: Use the Clonezilla media to boot into the environment as you did before.
  2. Start Clonezilla: Choose "Start Clonezilla".
  3. Select Mode: Choose "device-image" again.
  4. Select Restore Disk Image: Choose the option that allows you to restore an image.
  5. Choose Source Image: Select the previously created disk image as the source.
  6. Choose Target Disk: Select the destination disk. Be careful, as this will overwrite the content of the disk.
  7. Confirm and Restore: Confirm all choices and proceed with the restoration.

Post-Restoration:

  • If you restore to a different drive, you may need to adjust your BIOS/UEFI settings to boot from the new drive.
  • In case the restored system does not boot properly (for instance, if the UUIDs of the partitions have changed or if the new drive requires a different boot setup), you might need to use a live Linux USB stick to repair GRUB. You can do this by chrooting into the restored system and reinstalling GRUB:
    sudo mount /dev/sdXY /mnt          # Replace sdXY with your root partition
    sudo mount /dev/sdXZ /mnt/boot/efi # Replace sdXZ with your EFI partition, if you have one
    for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
    sudo chroot /mnt
    grub-install /dev/sdX               # Replace sdX with your drive, e.g., /dev/sda
    update-grub
    exit
    reboot
    

Clonezilla does a bit-by-bit cloning process, so it should copy the EFI/System Reserved partition as well as the main partition(s) where Ubuntu is installed. However, when moving to a different drive, especially when sizes differ or when migrating between legacy BIOS and UEFI systems, manual intervention might be necessary to ensure the system boots correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment