Cloning partitions with Clonezilla

Introduction

Clonezilla is a Debian-based, open-source cloning/imaging alternative to commercial products such as Symantec/Norton Ghost, Acronis, etc. It can be found either as a stand-alone, bootable CD, or as part of the PartedMagic Linux live CD that also includes tools like GParted to manage partitions.

What does CZ provide that a regular live distro doesn't?

Creating a bootable Clonezilla USB key

  1. Download the Clonezilla Live Zip file

    Note: The Alternative image is based on Ubuntu instead of Debian, the reason being that the development of Debian moves slower than Ubuntu, so Ubuntu supports more hardware. On the other hand, the alternative Ubuntu version might not work, so try both.

    Also, the Ubuntu version takes longer to start up after the menu screen, so just wait: If you take a look at its LED, you'll notice the USB key is actually being read, so just wait about 30s for the next step.
     
  2. Extract the contents of the Clonezilla Live Zip to your USB Flash Drive
  3. From the USB Flash Drive (important!), navigate to utils\win32 and run makeboot.bat (WARNING: Do NOT run the original makeboot.bat sitting on your hard-drive!)
  4. Restart your computer setting your BIOS or Boot menu to Boot from USB and then boot from your Clonezilla USB

Note: If a USB keydrive doesn't boot, try using the open-source and up-to-date Rufus utility to format and burn the ISO file. Alternatively, there's the HP USB Disk Storage Format Tool; As of August 2012, the latest release seems to be 2.2.3.

Setup

  1. Create a bootable Clonezilla USB key (faster and quieter than a CD/DVD)
  2. At the first opportunity, choose to go to the command line, and type "sudo -s" to switch to root, possibly followed by "loadkeys XX" to use a different keyboard layout (eg. "fr" for France, etc.)
  3. Once root, you can run commands such as "fdisk -l" to list partitions, or "dd if=/dev/zero of=/dev/sda bs=440 count=1" to remove the Master Boot Loader from the Master Boot Record (MBR) while preserving the Partition Table within
  4. Clonezilla includes an OpenSSH server. To connect to it from a remote host, just run "service ssh start". If the network isn't up, run "dhclient eth0" and check with "ifconfig" that Clonezilla got an IP from the DHCP server
  5. On an empty drive, the Windows installer (Only 7, or does Vista also do it?) will create two partitions: One 100MB to hold boot files, and a second to hold the rest of the install. The only way seems to be to let it create the two, delete the second partition, and increase the size of the 100MB partition
  6. Before saving a Windows partition, it's a good idea to defragment it. Also consider SID, sysprep, etc.
  7. If you intend to use Clonezilla to restore images on the same disk from one partition into the other, use fdisk to create a simple layout such as /sda1 to hold an OS and /sda2 to hold the images
  8. If you intend to use Grub as the Master Boot Loader, ie. put Grub in the MBR, format this second partition in eg. ext2, and copy the /boot/grub/ directory from the Clonezilla USB/CD into /sda2
  9. Make sure the directory tree is identical, and edit /sda2/boot/grub/menu.lst thusly:

    default 0
    timeout 30

    title Windows
        #Set /sda1 partition ID as NTFS in case was left as Linux 0x83
        parttype (hd0,0) 0x7
        #OS located in first partition
        rootnoverify (hd0,0)
        #Windows master boot loader loads OS in active partition
        makeactive
        #Run boot loader in /sda1
        chainloader +1
     
  10. If you want to add a section to load Linux, and prefer to use version-agnostic information so you can update the kernel without updating menu.lst, start Linux, create two symbolic links to point to the actual binaries, and edit menu.lst thusly:

    title Linux
        root (hd0,0)
        #vmlinuz and initrd.img are symlinks to the actual files
        kernel /boot/vmlinuz ro root=LABEL=/
        initrd /boot/initrd.img
        
  11. In case you want to install Grub in the MBR, start Linux, run "grub" as root, and type the following commands:

    #To tell Grub that its configuration file is located in /sda2
    root (hd0,1)
    #To tell Grub to install itself as Master Boot Loader in the MBR
    setup (hd0)
    quit
     
  12. Once done, simply run "clonezilla" to resume the Clonezilla session
  13. To save whatever OS is in /sda1 into an image file in /sda2, choose "save-parts"

Options

More information on important options (-g, -t, -j, etc.)

Clonezilla Peeves

Tips

To create a partition on a specific start sector, use "fdisk -u /dev/sdX". cfdisk (also part of util-linux 2.19.1) only prompts for total size in MB.

Q&A

[restore] How to restore to a smaller partition?

By default, Clonezilla refuses to proceed. Even using the -idcs Expert option won't work.

A work-around is to delete and re-create the target partition. Maybe it's just not a good idead to restore an image to a smaller partition even if you know there's enough room:

  1. fdisk -l /dev/sda, and write down the start/end sectors for sda1
  2. fdisk -u /dev/sda, delete sda1, re-recreate it with the right start/end sector infos, write, and sync a couple of times
  3. launch CZ, and use Expert Mode to enable the "-idcs" option (otherwise, it'll still complain that the target partition is smaller than the source)
  4. Reboot

Bunch of GRUB-related errors ("Warning! Found grub partition (/dev/sda1) file system is ext4! Not all version of grub 1 supports file system ext4!") and won't boot: "mkfs.ext4 /dev/sda1" and trying again made no difference.

FYI, partition infos as kept in /mnt/sda2/<name of partition image>/sda-pt.parted.

 

The image is start=2048, end=102402438, FS=ext4. "df -T" confirms that sda1 is ext4. So why the GRUB failure?

Used fdisk to mark sda1 as bootable, restored image, and rebooted: still stuck in "grub>" prompt.

Next, mkfs.ext3 /dev/sda1 and told CZ to restore: same error.

Next, wiped out MBR, CZ : same error.

Next, tried restoring Mint instead of Ubuntu: OK.

[restore] What happens if target partition has a different name?

eg. used to be /dev/sda1 but, for some reason, is now /dev/sdb1 after booting Clonezilla?

[restore] What happens if target partition doesn't exist or is bigger?

Clonezilla will gladly restore the image, but Windows may not like it: "Windows failed to start. A recent hardware or software change might be the cause."

To solve this, enter the shell, and resize the target partition to match its original size thusly:

  1. Mount the partition where you saved the Clonezilla images
  2. Cd into the directory where the image lives, and "cat sda-pt.parted"
  3. Note down the start/end settings of the target partition where you want to restore the image
  4. Next, perform the following steps to delete/recreate the target partition:
    1. Run "fdisk -u /dev/sda"
    2. Delete the current partition
    3. Recreate it using the "start" and "last sector" parameters from the previous step
    4. Write changes
    5. Exit fdisk
  5. Run "partprobe"
  6. Relaunch fdisk
  7. Set the target partition with ID="NTFS" and "Boot flag=enabled", or Windows won't even try booting it up.
  8. Exit fdisk and reboot
  9. Run Clonezilla to restore the Windows image

Steps to make before cloning Windows?

  1. Download and apply all the Windows updates
  2. Defragment the partition
  3. SysPrep (only needed when restoring on a different host)

How to connect to a Windows host?

In case you need to send/receive files from the Clonezilla host to a Windows host, one of the ways is to mount a Windows partition thusly:

mount -t cifs //192.168.0.1/"C" /mnt/my.xp -o username=joe,password=mypasswd

Does Linux care about partition type + bootable?

No. I restored a Ubuntu 11.04 image in a partition marked as NTFS/HPFS, and it booted OK.

Next, I removed the boot switch for that partition, and Ubuntu booted OK anyway.

Only Windows cares that a partition be marked as bootable and its type be NTFS/HPFS.

Getting files from a Clonezilla host

In case you need download files from a host booted up with Clonezilla:

  1. apt-get update
  2. apt-get install lighttpd
  3. vi /etc/lighttpd/lighttpd.conf

    #So that Lighttpd can access the whole drive
    server.document-root        = "/"
    dir-listing.activate = "enable"
     
  4. service lighttpd restart

Alternativaly, you can compile and use the single-EXE Mongoose.

When starting SSH: "Could not load host key: /etc/ssh_host_ecdsa_key"?

Just ignore the error, and try to connect to the Clonezilla host through SSH.

Clonezilla ships with SSH, but you must run /etc/init.d/ssh start to start it.

Make sure Clonezilla includes the driver for your network adapter, though...

Does Clonezilla stable (ie. Debian) have an FTP client?

lftp

How to enable eth0?

To get the eth0 to receive an IP configuration from the DHCP server:

dhclient eth0

How to restore to a different partition?

By default, Clonezilla will try to restore to the same partition (eg. /dev/sda1) and will stop if that partition doesn't exist because something happened since you cloned that partition.

Using fdisk /dev/sdaX, delete the partition, reboot, recreate the partition with the right number, restore the image

1/2, and 5 used. Chose 3, then 4: "No free sectors available"

mkdir

I want to wipe out the Master Boot Loader from the MBR

fdisk -l

dd if=/dev/zero of=/dev/sda bs=440 count=1

Taking screenshots?

  1. sudo -i
  2. Configure the network through "ocs-live-netcfg"
  3. apt-get update; apt-get install screen

Can't boot after restoring Windows 7

Laptop just displays "Prepare boot to OS" for a split second, then blinking cursor.

-t1 option?

Make sure the partition is typed as "NTFS" instead of "Linux" and is marked as bootable.

"No unmounted disk are found! To use clonezilla to save or clone a disk, the source disk must be unmounted! "

If you deleted a partition, just reboot and try again.

How to reinstall the Windows boot loader?

If it boots through GRUB, let Windows boot, and download and run MbrFix to put the Windows boot loader back in the MBR, effectively removing GRUB.

Alternatively, boot with Clonezilla, and try the "-t1" option ("Client restores the prebuilt MBR from syslinux").

If Windows still doesn't boot, reboot with its CD and run the "fixmbr" command.

What's the difference between Partclone.ntfs and ntsfclone?

Partclone is an improvement over ntfsclone.

How do Partclone and Partimage differ?

Partclone is said to be much better than Partimage + ntfsclone.

Is CloneZilla the live CD, or an application?

Based on the names, it appears that PartClone is done by the same people who do Clonezilla (Steven Shaiu and the NCHC Free Software Labs in Taiwan.)

So Clonezilla is a live CD with a text-based front-end to Partclone.

What do these restore options (-g auto, -t, -t1, -j1, -j2, -k, -k1, -j0, -r...) actually do?

Read this.

Does Clonezilla restore the boot loader in the MBR?

It does, when performing a disk-to-disk cloning.

When restoring a partition from a file in a second partition (source), by default, Clonezilla will restore the bootloader that it saved when making an image of a partition, although it's possible to tell it to only restore the partition and leave the MBR alone.

Here's more information on the relevant options:

-t (default: enabled) Client does not restore the MBR (Master Boot Record): Do NOT restore the MBR (Mater Boot Record) when restoring image. If this option is set, you must make sure there is an existing MBR in the current restored harddisk. Default is Yes, ie. Clonezilla will restore the MBR (where "MBR" = "bootloader")

-t1 (default: disabled) Client restores the prebuilt MBR from syslinux (For Windows only): If this option is set, the MBR is overwritten by prebuilt one which chainloads Windows. Use this option if you have to restore Windows and make it bootable, but don't have the original MBR or backup of it.

-g (default: enabled) auto Reinstall grub in client disk MBR (only if grub config exists): Causes Clonezilla Live to reinstall GRUB into the Master Boot Record of the disk if at least one partition contains GRUB config file (/boot/grub/menu.lst). The option is enabled by default and shouldn't cause any harm. However, it should be disabled if you for example have another bootloader in MBR and chainload GRUB with it.

-j1 (default: disabled) Write MBR (512 B) again after image is restored. Not OK for partition table differ: When a disk image is restored, the partition table must be updated to reflect the actual partitions in the disk. If you don't want it to happen, enable this option. Then the Master Boot Record (including the partition table) is restored again after restoring the image. Note that using this option can destroy all the data in the target drive.

-j2 (default: enabled) Clone the hidden data between MBR and 1st partition: If this option is set, the 15 hidden sectors between Master Boot Record and the first partition are restored. This area usually contains some data necessary for booting. The option is enabled by default and should be kept enabled if you are cloning a bootable disk.

-r (default: enabled): "Try to resize the filesystem to fit partition size".

Note: In the options above, depending on the context, "client = Clonezilla" or "client = target partition on which to restore image"...

Error 0xc0000225 or 0xc00000e

Unlike previous versions of Windows, it appears that Vista/Windows7 identify each partition with a unique ID, and aren't happy when restoring images.

The solution is to start Windows, edit the Registry, head for the HKLM\System\MountedDevices\ section, remove all entries except "Default", and then save this partition using CloneZilla.

More information:

"Autochk Program Not Found" when rebooting with Windows (XP, at least)

This error message can be displayed after restoring a Windows image, and the computer will enter an endless reboot cycle.

Boot with Clonezilla, enter the command prompt the first chance you have, "sudo -s" to su to root, and use fdisk to check the partitions: If the partition where you restored Windows contained Linux previously, Clonezilla may have left its ID to "Linux" instead of changing it to "NTFS/HPFS". If that's the case, use the "t" option in fdisk to change the ID, save, and reboot.

Is there a GUI-based version of Clonezilla?

www.redobackup.org, but it only images partitions and ignores the MBR, so Redobackup is more limited than Clonezilla.

There are two other projects, but they seem abandonned:

Does GRUB need its configuration files?

In case Clonezilla leaves the GRUB bootloader in the MBR after restoring a Windows partition, and provided the Windows partition is marked as "active"... is GRUB able to just start Windows even though the partition obviously doesn't contain the GRUB configuration files (/boot/grub/)?

Is there a way to avoid all those steps?

The boot parameters for Clonezilla live

Preseed options to do job after booting

Flashing 4GB Kingston USB keydrive

Laptop BIOS displays as "USB HDD: KingstonDT 101 G2"

From ZIP

Makeboot

Basic

Quick Windows Format

Unzipped, makeboot

Boots OK

Flashing 4GB EMTEC USB keydrive

Laptop stuck as F2 to enter Setup, F12 to change boot device

Desktop: USB ZIP/FDD/CDROM ignored, boots from hard disk

Flashing 4GB Ryval USB keydrive

Laptop BIOS displays as "USB FDD: General USB Flash Disk"

Desktop: USB ZIP/FDD/CDROM ignored, boots from hard disk. Failed updating BIOS with BIOS_R03-B0.zip_R03-B0_A_A.zip "OnBoard BIOS Not Award BIOS !"

From ZIP (Linux)

dd if=/dev/zero of=/dev/sdb bs=512 count=1

mkfs.vfat -n linux -F 32 -v /dev/sdb1

sfdisk -c /dev/sdb 1 b (to set partition ID to W95 FAT32)

fdisk -l /dev/sdb

mkdir /mnt/usb

mount /dev/sdb1 /mnt/usb/

cd /tmp

wget -c ???? (Check http://clonezilla.org/downloads/alternative/iso-zip-files.php)

mv ???? cz.zip

(apt-get install unzip)

unzip cz.zip -d /mnt/usb

cd /mnt/usb/utils/linux

bash makeboot.sh /dev/sdb1

COULD BE DUE TO NEWER PARTEd /dev/sdb1: this doesn't look like a valid FAT filesystem

parted -s /dev/sdb1 print

umount /dev/sdb1

From ZIP (Windows)

Makeboot

Basic

Full Windows Format

Unzipped, makeboot

STUCK SYSLINUX 4.05

With syslinux -sfmar H:

Full Windows Format

Unzipped, makeboot

syslinux -sfmar H:

STUCK SYSLINUX 4.05

From ISO

UNetBootin 568

Universal USB Installer 1.8.8.4

Tuxboot 39

linuxmint-12-gnome-cd-nocodecs-32bit.iso

clonezilla-live-20120127-oneiric.iso

QF = Windows Quick Format, FF = Windows Full Format

IF = Internal format

Format

Application

File

Result

QF

UNetBootin

Mint

Stuck. SYSLINUX 4.03

QF

UnivUSB

Mint

OK

QF

UnivUSB

CZ

Stuck. SYSLINUX 4.04

QF

TuxBoot

Mint

Stuck. Blinking cursor.

QF

TuxBoot

CZ

Stuck. SYSLINUX 4.04

IF

UnivUSB

PartedMagic

OK

IF

UnivUSB

CZ

OK

Bottom line:

Resources