Clonezilla

From Leo's Notes
Last edited on 14 June 2020, at 23:33.

Clonezilla is a disk imaging Linux distribution that can be live booted from a USB, CD, or network.

USB

For other ways to set up a Clonezilla USB drive, see http://clonezilla.org/liveusb.php.

To set up a USB key with Clonezilla manually, partition a USB drive with one FAT32 partition. If using fdisk to partition, set the partition type to 'b' and make it bootable with 'a'.

# fdisk /dev/sdg
Command (m for help): p
Disk /dev/sdg: 28.9 GiB, 31004295168 bytes, 60555264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x10cfca7b

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdg1  *     2048 60555263 60553216 28.9G  b W95 FAT32

## Format the drive
# mkfs.vfat -F 32 /dev/sdg1

Download the Clonezilla zip archive, then extract it to the USB drive.

# wget http://gigenet.dl.osdn.jp/clonezilla/68244/clonezilla-live-20170829-zesty-i386.zip
# mount /dev/sdg1 /mnt/usb
# cd /mnt/usb
# unzip ~/clonzilla*zip

Install the MBR on the USB drive using the included script. This requires the mtools package installed.

# cd /mnt/usb/utils/linux
# bash makeboot.sh /dev/sdg1
This command will install MBR and syslinux/extlinux bootloader on /dev/sdj
Clonezilla files are assumed to be on /dev/sdj1
--------------------------------------------
Machine: :
Model: Lexar USB Flash Drive (scsi)
Disk /dev/sdj: 16.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  16.0GB  16.0GB  primary  fat32        boot

--------------------------------------------
Are you sure you want to continue?
[y/n] y
OK! Let's do it!
--------------------------------------------
File system of /dev/sdj1: vfat
--------------------------------------------
Do you want to install MBR on /dev/sdj  ?
[y/n] y
OK! Let's do it!
Running: cat "/mnt/usb1/utils/mbr/mbr.bin" > /dev/sdj
--------------------------------------------
Do you want to install the syslinux boot files on /dev/sdj1  ?
[y/n] y
OK! Let's do it!
A filesystem supporting Unix file mode for syslinux is required. Copying syslinux to /tmp/linux_tmp.nZyNzV
'/mnt/usb1/utils/linux/x64/syslinux' -> '/tmp/linux_tmp.nZyNzV/syslinux'
Running: "/tmp/linux_tmp.nZyNzV/syslinux" -d syslinux -f -i "/dev/sdj1"
//NOTE// If your USB flash drive fails to boot (maybe buggy BIOS), try to use "syslinux -d syslinux -fs /dev/sdj1", i.e. running with "-fs".
syslinux ran successfully in installation mode.
Done!

Network Boot / NFS

Clonezilla can be booted via PXE over NFS. First, download the Clonezilla zip package and extract it to a directory that is exported via NFS. Then, add the following menu entry to the pxelinux.cfg menu:

LABEL ClonezillaAlt
  MENU LABEL ClonezillaAlt
  kernel boot/clonezilla
  append initrd=boot/clonezilla.img nfsroot=X.X.X.X:/data/pxe/clonezilla-alt union=aufs netboot=nfs ocs_live_keymap boot=live vga=788 noswap ocs_live_batch=no ocs_live_extra_param ocs_lang ocs_live_run=ocs-live-general live-config  hostname=ClonezillaAlt domain=local.lan suite=generic26
  IPAPPEND 2

Replace X.X.X.X with the NFS server hostname/IP address and ensure that the NFS path leads to the zip contents.


Automated Imaging

You can automatically image a drive or restore an image by using the ocs_live_run option that is passed to the kernel on boot. This will work with PXE or USB.

To do this on a USB stick, create a boot entry in syslinux/syslinux.cfg that contains the restore (or imaging) command specified by the ocs_live_run parameter. On an EFI system, you will want to edit /EFI/boot/grub.cfg instead.

To restore an image located in /partimag, create a boot entry similar to the one below:

...
# simple menu title
MENU TITLE clonezilla.org, clonezilla.nchc.org.tw

# Automatic Restore for display-v1.1
label Clonezilla restore display
  # MENU DEFAULT
  # MENU HIDE
  MENU LABEL Clonezilla Restore Display v1.1
  # MENU PASSWD
  kernel /live/vmlinuz
  append initrd=/live/initrd.img boot=live union=overlay username=user hostname=zesty config  components noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -icds -j2 -p reboot restoredisk ../../lib/live/mount/medium/partimag/display-v1.1 sda" 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
  TEXT HELP
  Automatically images from USB for the TTuff 1U computer
  ENDTEXT

label Clonezilla live
...

If you want the entry to boot by default, uncomment the MENU DEFAULT line and then comment out the one that is.

Troubleshooting

TFTP Boot Issues

Clonezilla 1.2 does not boot from a TFTP server running on FreeBSD (9.0-RELEASE). Everything seems to boot fine until it tries to fetch the root filesystem. Below is what is seen on the console during the boot process:

IP-Config: eth0 complete (dhcp from 10.1.1.9)
 address: 10.1.1.55   broadcast: 10.1.1.255   netmask: 255.255.255.0
 gateway: 10.1.1.1    dns0     : 10.1.1.9     dns1   : 0.0.0.0
 domain : home.steamr.com
 rootserver: 10.1.1.9 rootpath:
 filename  : /pxelinux.0
Creating /etc/resolv.conf
Begin: Trying tftp -g -b 10240 -r /images/clonezilla/live/filesystem.squashfs -l /images/clonezilla/live/filesystem.squashfs 10.1.1.9 ... ^M /images/clonezilla/l   0% |
tftp: timeout
 
 .''`.
: :'  :   BOOT FAILED!
`. `'`
  `-      This Debian Live image failed to boot.
 
Please file a bug against the 'live-boot' package or email the Debian
Live mailing list at <debian-live@lists.debian.org>, m aking sure to note
the exact version, name and distribution of the image you were attempting to boot.
 
< snip >
 
BusyBox v1.20.1 (Debian 1:1.20.0-4) built-in shell (ash)
Enter 'help' for a list of built-in commands.
 
/bin/sh: can't access tty; job control turned off
(initramfs) _

The tftpboot pxelinux.cfg/default configuration file contains:

label 3
        menu label ^3. Clonezilla Live CD (x86)
        kernel images/clonezilla/live/vmlinuz
        append initrd=images/clonezilla/live/initrd.img boot=live config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=788 nosplash noprompt fetch=tftp://10.1.1.9/images/clonezilla/live/filesystem.squashfs

Obviously, tftp works. This is evident by the fact that Clonezilla managed to boot and the fact that I was greeted by the pxe boot menu. Furthermore, if I typed in tftp -g -r /images/clonezilla/live/filesystem.squashfs 10.1.1.9, I am able to retrieve the filesystem.squashfs file without issue.

Checking the logs on the FreeBSD machine, I see:

Oct  3 04:42:34 nas tftpd[38727]: send_packet: Message too long
Oct  3 04:42:34 nas tftpd[38727]: Cannot send DATA packet #1, trying again
Oct  3 04:42:34 nas tftpd[38727]: DATA block 1, attempt 0 failed (Error 40: Message too long)
Oct  3 04:42:35 nas tftpd[38727]: DATA block 1, attempt 1 failed (Error 40: Message too long)
Oct  3 04:42:37 nas tftpd[38727]: DATA block 1, attempt 2 failed (Error 40: Message too long)
Oct  3 04:42:38 nas tftpd[38783]: DATA block 1, attempt 4 failed (Error 40: Message too long)
Oct  3 04:42:41 nas tftpd[38727]: DATA block 1, attempt 3 failed (Error 40: Message too long)

So, obviously, the transfer block size is causing some sort of issue. I spent easily over an hour trying to get it to work using different parameters and different tftpd servers to avail.

Possible Packet Size + MTU Cause
A friendly guy named Torsten mentioned that the TFTP command used by Clonezilla uses a maximum packet size of 10240 bytes which exceeds most ethernet MTUs. The TFTP server most likely defaulted to a 65464 byte MTU which was the cause of this issue. If you run into this issue again, try changing the TFTP server's maximum packet size to MTU - 32 bytes. Run tcpdump and see what sizes these network frames are.


Alternatively, use NFS. Change the configuration to match the following:

/etc/exports:

/tftpboot/images/clonezilla  -network 10.1.1 -mask 255.255.255.0    # or whatever network address you're on. I'm on 10.1.1.0/24

/tftpboot/pxelinux.cfg/default:

label 3
        menu label ^3. Clonezilla Live CD (x86)
        kernel images/clonezilla/live/vmlinuz
        append initrd=images/clonezilla/live/initrd.img boot=live live-config noswap <strong>union=aufs netboot=nfs nfsroot=10.1.1.9:/tftpboot/images/clonezilla</strong> ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=788

Then, re-export or restart/reload NFS:

# kill -HUP `cat /var/run/mountd.pid `

Try booting Clonezilla again. If everything's good, you should be able to boot into it.