Semi-automatic clonezilla boot stick

2015-03-02 ยท 806 words ยท 4 minute read

I use clonezilla a lot to load images onto computers or create backups of them and it was always a hassle to enter the same values into the diolog over and over again. Unfortunately the documentation is not the very best.

Anyway, with a lot of googling and trail and error i finally got a semi automatic configuration.

You have to modify 3 files for booting EFI machines as well as BIOS based ones.

EFI: /EFI/boot/grub.cfg ๐Ÿ”—

 1et prefix=/EFI/boot/
 2set default="0"
 3if loadfont $prefix/unicode.pf2; then
 4  set gfxmode=auto
 5  insmod efi_gop
 6  insmod efi_uga
 7  insmod gfxterm
 8  terminal_output gfxterm
 9fi
10set timeout="5"
11set hidden_timeout_quiet=false
12
13if background_image $prefix/ocswp-grub2.png; then
14  set color_normal=black/black
15  set color_highlight=magenta/black
16else
17  set color_normal=cyan/blue
18  set color_highlight=white/blue
19fi
20
21menuentry "Clonezilla live, ::: Restore :::"{
22  search --set -f /live/vmlinuz
23  linux /live/vmlinuz boot=live username=user config quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=ch ocs_live_extra_param="" ocs_prerun1="/lib/live/mount/medium/utils/mount.sh" ocs_live_batch=no ocs_live_run="ocs-sr -g auto -e1 auto -e2 -c -r -j2 -p true restoredisk ask_user ask_user" vga=791 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 
24  initrd /live/initrd.img
25}
26
27menuentry "Clonezilla live, ::: Backup :::"{
28  search --set -f /live/vmlinuz
29  linux /live/vmlinuz boot=live username=user config quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=ch ocs_live_extra_param="" ocs_prerun1="/lib/live/mount/medium/utils/mount.sh" ocs_live_batch=no ocs_live_run="ocs-sr -q2 -c -j2 -z1p -i 2000 -p true savedisk ask_user ask_user" vga=791 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 
30  initrd /live/initrd.img
31}

As you can see i preset the locales to US-english (en_US.UTF-8), but the keyboard-layouts to swiss-german (ch). Furthermore i set ocs_prerun1 with a path to a bashscript where i configure the ethernet and mount a samba share where my images are located. (I show the script later because its the same for EFI and BIOS)

BIOS: /syslinux/isolinux.cfg, /syslinux/syslinux.cfg ๐Ÿ”—

I have no idea why there are two identical cfg files, but i modified both in the same way and that works for me:

 1default vesamenu.c32
 2timeout 50
 3prompt 0
 4noescape 1
 5MENU MARGIN 5
 6 MENU BACKGROUND ocswp.png
 7# Set the color for unselected menu item and timout message
 8 MENU COLOR UNSEL 7;32;41 #c0000090 #00000000
 9 MENU COLOR TIMEOUT_MSG 7;32;41 #c0000090 #00000000
10 MENU COLOR TIMEOUT 7;32;41 #c0000090 #00000000
11 MENU COLOR HELP 7;32;41 #c0000090 #00000000
12
13# MENU MASTER PASSWD
14
15say **********************************************************************
16say Clonezilla, the OpenSource Clone System.
17say NCHC Free Software Labs, Taiwan.
18say clonezilla.org, clonezilla.nchc.org.tw
19say THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK! 
20say **********************************************************************
21
22# Allow client to edit the parameters
23ALLOWOPTIONS 1
24
25# simple menu title
26MENU TITLE clonezilla.org, clonezilla.nchc.org.tw
27
28label Clonezilla live, ::: Restore :::
29  MENU LABEL Clonezilla live, ::: Restore :::
30  kernel /live/vmlinuz
31  append initrd=/live/initrd.img boot=live username=user config quiet noswap edd=on nomodeset locales=en_US.UTF-8 keyboard-layouts=ch ocs_live_extra_param="" ocs_prerun1="/lib/live/mount/medium/utils/mount.sh" ocs_live_batch=no ocs_live_run="ocs-sr -g auto -e1 auto -e2 -c -r -j2 -p true restoredisk ask_user ask_user" ocs_live_batch=no vga=791 ip=  nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
32
33label Clonezilla live, ::: Backup :::
34  MENU LABEL Clonezilla live, ::: Backup :::
35  kernel /live/vmlinuz
36  append initrd=/live/initrd.img boot=live username=user config quiet noswap edd=on nomodeset locales=en_US.UTF-8 keyboard-layouts=ch ocs_live_extra_param="" ocs_prerun1="/lib/live/mount/medium/utils/mount.sh" ocs_live_batch=no ocs_live_run="ocs-sr -q2 -c -j2 -z1p -i 2000 -p true savedisk ask_user ask_user" ocs_live_batch=no vga=791 ip=  nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1

The changes are the same as for the EFI grub.cfg.

custom mount script: /utils/mount.sh ๐Ÿ”—

As is said before, i call a custom mount script because i wanted to automate a few things and doing that inline is just ugly as hell :-)

 1#!/bin/bash
 2
 3# import configuration 
 4source "/lib/live/mount/medium/config.sh"
 5
 6dhclient -v eth0
 7
 8addr0=$(ifconfig eth0 | grep "inet addr")
 9
10if [ "$addr0" == "" ]
11then
12    dhclient -v eth1
13fi
14
15addr1=$(ifconfig eth1 | grep "inet addr")
16
17if [ "$addr0" == "" ] && [ "$addr1" == "" ]
18then
19    echo "Error: no IP received!"
20    read -p enter
21    reboot
22fi
23
24# mount samba share
25mount -t cifs //$sambaserver/$sambapath /home/partimag -o user=$user,password=$password,domain=$domain

I first import a config script that is located in the root of the boot stick. Then i try to get a DHCP lease for eth0, if that fails i try the same for eth1. If none of the two interfaces get a DHCP lease, i throw an error and reboot after the user confirms by pressing ENTER (or any other key).

Last but not least, i mount the Samba server.

configuration: config.sh ๐Ÿ”—

And finally the config file with the parameters, that makes it easy to adjust the scripts in case the servername or password changes.

1#!/bin/bash
2
3sambaserver="hostname"
4sambapath="clonezilla/images" #note, no leading slash!
5user="username"
6password="password"
7domain="MyDomain"

And thats it, the script does everythin autmatically, except for choosing the image and the disk to restore/backup. Thats why i call it semi-automatic. In case you want to have a fully automatic script, you can simply replace the ask_user parameters in the grub.cfg files with imagename and sda for example.