3

I would like to provide a short tutorial to all of you out there looking for an automated Clonezilla Restore option.

Assumptions

  • UEFI Boot only
  • both Clonezilla /dev/sdb1 and Image repository /dev/sdb2/images are on the same USB stick
  • Restore to entire SSD /dev/sda

I would like to

  1. Boot from USB stick
  2. Auto-select and start custom Clonezilla restore option
  3. Auto-load image repository from USB Stick
  4. User selects the image to be restored
  5. Auto-restore from selected image to SSD
  6. Auto-reboot after successful restore
Chiggiddi
  • 542
  • 1
  • 8
  • 26

3 Answers3

8

Steps

In your Clonezilla USB Stick open /boot/grub/grub.cfg using a text editor. After the following text Since no network setting in the squashfs image, therefore if ip=, the network is disabled.add the following to make this the first Clonezilla default entry:

menuentry "Flysoft RESTORE" {
  search --set -f /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 noprompt ocs_prerun="mount /dev/sdb2 /mnt" ocs_prerun1="mount --bind /mnt/images /home/partimag/" ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -j2 -k -scr -batch -p reboot restoredisk ask_user sda" keyboard-layouts="de" ocs_live_batch="yes" locales=de_DE.UTF-8 vga=788 ip= nosplash net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  $initrd_cmd /live/initrd.img
}

Most important sections

ocs_prerun="mount /dev/sdb2 /mnt" ocs_prerun1="mount --bind /mnt/images /home/partimag/" mounts /dev/sdb2/images as image repo

ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -j2 -k -scr -batch -p reboot restoredisk ask_user sda" restores image to /dev/sda and reboots

Full example of grub.cfg

#
set pref=/boot/grub
set default="0"

# Load graphics (only corresponding ones will be found)
# (U)EFI
insmod efi_gop
insmod efi_uga
# legacy BIOS
# insmod vbe

if loadfont $pref/unicode.pf2; then
  set gfxmode=auto
  insmod gfxterm
  terminal_output gfxterm
fi
set timeout="30"
set hidden_timeout_quiet=false

insmod png
if background_image $pref/ocswp-grub2.png; then
  set color_normal=black/black
  set color_highlight=magenta/black
else
  set color_normal=cyan/blue
  set color_highlight=white/blue
fi

# Uncomment the following for serial console
# The command serial initializes the serial unit 0 with the speed 38400bps.
# The serial unit 0 is usually called ‘COM1’. If COM2, use ‘--unit=1’ instead.
#serial --unit=0 --speed=38400
#terminal_input serial
#terminal_output serial

# Decide if the commands: linux/initrd (default) or linuxefi/initrdefi
set linux_cmd=linux
set initrd_cmd=initrd
export linux_cmd initrd_cmd
if [ "${grub_platform}" = "efi" -a -e "/amd64-release.txt" ]; then
  # Only amd64 release we switch to linuxefi/initrdefi since it works better with security boot (shim)
  set linux_cmd=linuxefi
  set initrd_cmd=initrdefi
fi

insmod play
play 960 440 1 0 4 440 1

# Since no network setting in the squashfs image, therefore if ip=, the network is disabled.

menuentry "Flysoft RESTORE" {
  search --set -f /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 noprompt ocs_prerun="mount /dev/sdb2 /mnt" ocs_prerun1="mount --bind /mnt/images /home/partimag/" ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -j2 -k -scr -batch -p reboot restoredisk ask_user sda" keyboard-layouts="de" ocs_live_batch="yes" locales=de_DE.UTF-8 vga=788 ip= nosplash net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  $initrd_cmd /live/initrd.img
}

menuentry "Clonezilla live (Default settings, VGA 800x600)" --id live-default {
  search --set -f /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
  $initrd_cmd /live/initrd.img
}

submenu 'Other modes of Clonezilla live' {
  menuentry "Clonezilla live (Default settings, VGA 1024x768)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=791 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
    $initrd_cmd /live/initrd.img
  }
  
  menuentry "Clonezilla live (Default settings, VGA 640x480)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=785 ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
    $initrd_cmd /live/initrd.img
  }
  
  menuentry --hotkey=K "Clonezilla live (Default settings, KMS)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=791 ip= net.ifnames=0  splash
    $initrd_cmd /live/initrd.img
  }

  menuentry --hotkey=R "Clonezilla live (To RAM, boot media can be removed later)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 toram=live,syslinux,EFI,boot,.disk,utils ip= net.ifnames=0  splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
    $initrd_cmd /live/initrd.img
  }
  
  menuentry "Clonezilla live Safe graphic settings (vga=normal)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" ip= net.ifnames=0 nomodeset vga=normal nosplash
    $initrd_cmd /live/initrd.img
  }
  
  menuentry "Clonezilla live (Failsafe mode)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp ip= net.ifnames=0 nomodeset vga=normal nosplash
    $initrd_cmd /live/initrd.img
  }
}  

menuentry "Local operating system (if available)" --id local-disk {
  echo "Booting first local disk..."
  # Generate boot menu automatically
  configfile /boot/grub/boot-local-efi.cfg
  # If not chainloaded, definitely no uEFI boot loader was found.
  echo "No uEFI boot loader was found!"
  sleep 15
}

#menuentry "memtest"{
#  search --set -f /live/memtest
#  linux16 /live/memtest
#}

#menuentry "FreeDOS"{
#  linux16 memdisk
#  initrd /live/freedos.img
#}

menuentry "Network boot via iPXE" {
  search --no-floppy --set=root -f /live/ipxe.efi
  chainloader /live/ipxe.efi + 1
}

menuentry 'uEFI firmware setup' 'uefi-firmware' {
  echo "Entering uEFI firmware setup..."
  fwsetup
}

menuentry "Clonezilla live 2.7.0-10-amd64 info"{
  echo Clonezilla, the OpenSource Clone System.
  echo NCHC Free Software Labs, Taiwan.
  echo clonezilla.org, clonezilla.nchc.org.tw
  echo \* Boot menu for EFI machine
  echo \* Clonezilla live version: 2.7.0-10-amd64. (C) 2003-2020, NCHC, Taiwan
  echo \* Disclaimer: Clonezilla comes with ABSOLUTELY NO WARRANTY
  sleep --verbose --interruptible 10
}
Chiggiddi
  • 542
  • 1
  • 8
  • 26
  • 4
    [Official Clonezilla documentation for preseed options](https://clonezilla.org/show-live-doc-content.php?topic=clonezilla-live/doc/05_Preseed_options_to_do_job_after_booting) – Jack Jul 26 '21 at 17:11
  • 1
    Does this also work for To RAM method? I have tried it but I'm getting a kernel panic at boot, after choosing the Grub Custom entry. Same command without ```toram=live,syslinux,EFI,boot,.disk,utils``` in it works perfectly. – Sebastião Nov 26 '21 at 13:56
1

Thanks for the tips (although: weird way to blog via a StackOverflow question - but it worked!)

These extra pointers might help others:

  • I used Rufus running on Windows to generate my Clonezilla bootable USB drive (https://rufus.ie/en/)
  • Rufus lets you add a "persistent partition" where you can store your recovery image(s)
  • If you just store your recovery images (actually directories containing various image files) in the root of the partition (not inside the /images/ subdirectory), then you can skip the 2 ocs_prerun/ocs_prerun1 sections along with the bind-mount and just have ocs_prerun="mount /dev/sdb2 /home/partimag/"
  • If your machine has an MMC boot drive, the target disk is probably mmcblk0, not sda.
  • If your machine has an NVM/e boot drive, the target disk is probably nvme0n1
  • If your machine has and NVM/e or MMC boot disk (or basically some thing "not /dev/sda"), then your source drive might be /dev/sda and thus your source image partition is probably /dev/sda2
M0les
  • 111
  • 1
  • 5
0

First off - Thank you very much for this article. Quite informative. I'm offering a a tweak or two for someone who wants to do it slightly differently.

I made my USB stick with only one partition using the CloneZilla zip file. I made it bootable with the makeboot.bat (very carefully) per their instructions. The idea for me was to create a "Make it how it was the day I sold you this PC" boot stick that would only ask the user to say yes a couple times. I'm building a few older laptops with Mint/Cinnamon and am selling online and feel a need to ship with a rescue disk.

I wound up dropping my image in the USB stick's /home/partimag directory, thinking I could lose your ocs_prerun entries. A few grey hairs later, I would up doing this to make it find the image:

ocs_prerun="mount --bind /run/live/medium/home/partimag /home/partimag"

Throwing in quiet loglevel=0 noswap (the loglevel=0 stops a whole slew of WiFi errors that you don't care about.

No need for a ocs_prerun1 entry. Of course my ocs_live_run line was a little different as I used what CloneZilla gave me for the way I wanted it.

Thanks again, Mikey

Mikey
  • 1
  • I think you might be a little hazy about the concepts of StackOverflow. But the question in combination with the existing answer here is quite misleading, so you are not to blame. And your post happens to sufficiently match [answer]. But just to clarify any possible misconception, please read that and [ask] and the [tour]. Have fun. – Yunnosch Jan 22 '23 at 16:42