如何创建自动化和无人值守的 Clonezilla Restore 解决方案

How to create an automated and unattended Clonezilla Restore solution

我想为所有正在寻找自动 Clonezilla 还原选项的人提供一个简短的教程。

假设

我愿意

  1. 从 U 盘启动
  2. Auto-select 并启动自定义 Clonezilla 还原选项
  3. 从 U 盘自动加载图像存储库
  4. 用户select要恢复的图片
  5. 从 selected 图像自动恢复到 SSD
  6. 恢复成功后自动重启

步骤

在您的 Clonezilla USB 记忆棒中使用文本编辑器打开 /boot/grub/grub.cfg。在以下文本后 Since no network setting in the squashfs image, therefore if ip=, the network is disabled. 添加以下内容以使其成为第一个 Clonezilla 默认条目:

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
}

最重要的部分

ocs_prerun="mount /dev/sdb2 /mnt" ocs_prerun1="mount --bind /mnt/images /home/partimag/" 挂载 /dev/sdb2/images 作为镜像仓库

ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -j2 -k -scr -batch -p reboot restoredisk ask_user sda" 将图像恢复到 /dev/sda 重新启动

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
}