Sunday, October 28, 2012

Customizing clonezilla iso for creating automatic backup image


This is part-1 of "Nightly clonezilla backup imaging for ubuntu server".

This tutorial explains how to create customized clonezilla iso image.


Clonezilla is an open source disk cloning tool, I assume you already know enough about clonezilla.

If you startup your system with this result iso file, you will get an compressed harddisk backup image in the target partition you want.
This can be used as a snapshot, so you can restore your server if there is any problem.

Unlike the other method, this does not require any key input , when everything is finished, it will be rebooted automatically.


To make this, you will need,

 - Clonezilla iso image (http://clonezilla.org/downloads.php)
 Stable releases 1.2.12-67 is used in this tutorial

 - ISO Master (http://www.littlesvr.ca/isomaster/)
 This is for edit ISO file. you can install in on Ubuntu Software Center.

 - Two files : isolinux.cfg, mystartup.
 will be created in this tutorial

 1. Prepare clonezilla live ISO file.

http://clonezilla.org/downloads.php


 2. Install ISO master.

 Find and click install in Ubuntu Software Center.
 or just type "sudo apt-get install isomaster" in terminal.

 3. Define source and target partition.

yananet@server:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1        35G  6.0G   27G  19% /
udev           1000M  4.0K 1000M   1% /dev
tmpfs           403M  1.1M  402M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none           1007M  332K 1007M   1% /run/shm
/dev/sda1       459G  367G   69G  85% /media/MEDIA1
/dev/sdb3       193G   79G  105G  44% /media/EXT1

My home server has 3 partitions.
Ubuntu server 12.04, lubuntu-desktop, all server daemons are installed in /dev/sdb1.
What I want to do is to make clone image of this partition, and save this on /dev/sda1.

  • src_part=sdb1
  • tgt_part=sda1

The actual size of image file is about 3~4G.
The backup image will be stored in /clone of sda1

 4. Create mystartup script.

After clonezilla is started, this script will be excuted.
Most important part of this script is following.

ocs-sr -q2 -j2 -z1p -p command saveparts "$_filename" "$src_part"

ocs-sr is one of Clonezilla's command which enables you to save or restore a partition or whole disk.

All of option is explained here.


Make sure that you need to modify your own src_part and tgt_part.
This is based on /opt/drb1/samples/custom-ocs in clonezilla live.

 #!/bin/bash  
 # Author: Steven Shiau <steven _at_ nchc org tw>  
 # License: GPL  
 # Ref: http://sourceforge.net/forum/forum.php?thread_id=1759263&forum_id=394751  
 # followings are essential for initial startup  
 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"  
 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions  
 . $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf  
 . $DRBL_SCRIPT_PATH/sbin/ocs-functions  
 [ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf  
 ask_and_load_lang_set en_US.UTF-8  
 # From here, you can write your own scripts.  
 # functions  
 decide_sda_or_hda() {  
 # define your source and target parition  
  src_part=sdb1  
  tgt_part=sda1  
 }  
 action_backup() {  
  mkdir -p $ocsroot  
  part_fs="$(LANG=C ocs-get-part-info /dev/$tgt_part filesystem)"  
  case "$part_fs" in  
   ntfs) ntfs-3g /dev/$tgt_part $ocsroot   
      RETV=$? ;;  
   *) mount /dev/$tgt_part $ocsroot  
     RETV=$? ;;  
  esac  
  if [ "$RETV" -eq 0 ]; then  
   # define target directory name  
   _now=$(date +"%m_%d_%Y")  
   _filename="/clone/img_$_now"  
   # If you want to run it in batch mode, add option "-b" in the ocs-sr command  
   # For more options about ocs-sr, run "ocs-sr -h"  
   # or http://allthatnetwork.blogspot.jp/2012/10/clonezilla-ocs-sr-options.html  
   ocs-sr -q2 -j2 -z1p -p command saveparts "$_filename" "$src_part"  
  else  
   [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE  
   echo "Fail to mount /dev/$tgt_part as $ocsroot!"  
   echo "Program terminated!"  
   [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL  
  fi  
  umount $ocsroot &>/dev/null  
 }  
 ##################  
 ###### MAIN ######  
 ##################  
 # Find the device and partition  
 decide_sda_or_hda  
 # Start backup  
 action_backup  
 # Force restart (no key input required for restart)  
 reboot -f  


 5. Extract and modify isolinux.cfg file

the syntax of isolinux.cfg is very simular with grup configration.
This setup creates new menu entry in clonezilla live, and runs mystartup script you just created before.

First, extract isolinux.cfg file from clonezilla live iso file.

ISO master can do this or Ubuntu Archive Manager also can do this easily.

isolinux.cfg is under /isolinux.

Second, open it with a text editor, find following block.
This is the default boot option of clonezilla live.


 label Clonezilla live  
  MENU DEFAULT  
  # MENU HIDE  
  MENU LABEL Clonezilla live (Default settings, VGA 800x600)  
  # MENU PASSWD  
  kernel /live/vmlinuz  
  append initrd=/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 ip=frommedia nosplash  
  TEXT HELP  
  * Clonezilla live version: 1.2.12-67-i686-pae. (C) 2003-2012, NCHC, Taiwan  
  * Disclaimer: Clonezilla comes with ABSOLUTELY NO WARRANTY  
  ENDTEXT  


Comment out "MENU DEFAULT".

 MENU DEFAULT  

Finally, add your new boot option as following.

 label Clonezilla customize  
  MENU DEFAULT  
  # MENU HIDE  
  MENU LABEL Clonezilla customize (Default settings, VGA 800x600)  
  # MENU PASSWD  
  kernel /live/vmlinuz  
  append initrd=/live/initrd.img boot=live config noswap nolocales edd=on nomodeset ocs_live_run="/live/image/live/mystartup" ocs_live_extra_param="" ocs_live_keymap="NONE" ocs_live_batch="yes" ocs_lang="en_US.UTF-8" vga=788 ip=frommedia nosplash  
  TEXT HELP  
  * Clonezilla live version: 1.2.12-67-i686-pae. (C) 2003-2012, NCHC, Taiwan  
  * Disclaimer: Clonezilla comes with ABSOLUTELY NO WARRANTY  
  ENDTEXT  


Find full isolinux.cfg in here.
If you correctly create this file, clonezilla will show you following menu at the begin of boot up process.



6. Create new clonezilla ISO image

Open clonezilla ISO file with ISO master.

Copy myscript to /live
Delete the original and copy isolinux.cfg to /isolinux
Save ISO file as new name.



That's it!

You may use this ISO file to make CD or bootable USB or whatever you want.
This ISO file will make snapshot of your server automatically.


In my next post, I will explain how to backup your server in specific night time by using grup2 and crontab.


4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. i have been having a hard time figuring out how to do this over the network. Most of the automated stuff are done locally - but i realize that some commands like: mount does not work well in the ocs-live environment.

      Would you please help me create a customized menu with a remote location not sdb1(local)?

      Please reach me at klauss_21@yahoo.com. Thx

      Delete
  2. Hello, I love your blog. An easy to use CD/DVD ISO image editor. Basically you can use this program to extract files from an ISO, add files to an ISO, and create bootable ISOs - all in a graphical user interface. ISO images are great for distributing data files, software, and demos online. thanks~ Nadia T.

    ReplyDelete
  3. Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. ISO 27001 toolkit

    ReplyDelete