Menu

Again - Restore to Different Partition

Help
plmlbn
2013-07-31
2013-08-05
  • plmlbn

    plmlbn - 2013-07-31

    The reason that I added 'Again' was I am sure that this has been asked before in some form.

    Using 15gb /dev/sda1 EXT4 (primary) on Kubuntu 12.04 LTS -
    trying to clone to 22gb /dev/sdb5 (extended)


    I have used Clonzilla for a long time and I am currently using 9Jul13 / 2.12.-20. Up to this point I have restored to the same partition as was cloned. No problems.

    I am trying to update my hard drives and I went from 3 partitions (primary) to 5 partitions (extended). Restoring has been to say the least problematic.

    I tried to get directions from searches but it appears that at one time Clonezilla did not restore to a different partition then it changed to sometimes it can be done to now whatever now maybe. I do not know if I am relying on new or old info. Such things as remove all windows items, bit by bit copy, remove MBR option, restore to other partition script were all encountered.

    I have copied all the files over using fsarchiver but I need a clonezilla backup image.

    Can someone please point me to the guaranteed latest docs on restoring to a different partition, primary to extended.

    Thank You, appreciate it.

     
  • Fuchs

    Fuchs - 2013-08-04

    For you a program that can help you I hope.

    I think you have made
    -a backup of your important data
    -a CD with 'Boot Repair', look for 'Restoring partition image results in "grub rescue" prompt' (Clonezilla help)
    -a new partition e.g. sda5 ext4 25 GB 'U12.04-new' with gparted [live].

    Myself then I have used later to find the right version with:
    '# Post-Restoration Commands
    Once the user can boot to a working system,
    the following commands may prove useful in locating and/or fixing the problem.

    sudo update-grub # To refresh the available devices and settings in /boot/grub/grub.cfg (*important !)
    (grub-probe -t device /boot/grub # To look for the bootloader location.(/dev/sdXY )

    sudo grub-install /dev/sda # To install GRUB 2 to the sdX drive's MBR or boot sector(sda,sdb,..) (*important !)
    # copies GRUB images into /boot/grub, and uses grub-setup to install grub into the boot sector.
    (sudo grub-install --recheck /dev/sdX # To recheck the installation. (sda, sdb, ..)

    ( https://help.ubuntu.com/community/Grub2/Installing#GRUB_Legacy_Upgrades_and_Downgrades )

    '# And now the script 'diffpart.sh' you can added in the upper directory of a USB [flash] drive
    (tested with clonezilla-live-2.1.1-7-i686-pae):

    !/bin/bash

    # Author: Fuchs, ..
    # License: GPL
    # The script is used to restore an image to another partition as the original partition
    # from a ntfs/ext.. formated repository (not vfat,msdos)
    # It is developed for 'Clonezilla live' based on
    # http://drbl.org/faq/fine-print.php?path=./2_System/102_restore_image_to_different_partition.faq#102_restore_image_to_different_partition.faq
    # The script will embeded as e.g. 'ocs_prerun7="/live/image/diffpart.sh"' in syslinux.cfg, isolinux.cfg or grub.cfg
    # When the script is ready, you can run 'clonezilla start' normally in Beginner or Expert Mode without any interruption.
    #
    # Begin of the script:
    #
    echo -e '\nRestoring to a different partition\nfrom a ntfs/ext.. formated repository (not vfat,msdos)\n'
    echo "The new partition (sdx1-sdx9) should be equal to or greater then the original partition !"
    echo -e "You can make this one e.g. with 'gparted live'.\n"
    echo 'Insert USB [flash] drive and wait 5 sec, then press Enter to continue'
    read

    #~~OrgImageChoice~~\
    repPart=""
    while true; do # continue execution until we are forcibly interrupted (with kill or Ctrl+C).
    [ "$repPart" != "" ] && sudo umount -l $devPart

    sudo blkid -o list
    echo
    blkid | grep -vw 'swap' | grep -vw 'loop0' | sed -r 's/^\/dev\/(.): [^\"]\"([^\"]).$/\1\t\2/g' # table: part label/UUID
    allParts=$(blkid | grep -vw 'swap' | grep -vw 'loop0' | sed -r 's/^\/dev\/(.): .$/\1/g' )
    echo
    read -n4 -p "repositoryPart: $> " repPart
    [ "$repPart" = "" ] && exit # without choice -> END

    repPart=echo $allParts | grep -ow $repPart # one word only
    [ "$repPart" = "" ] && echo -e "\n $repPart does not exist\n" && sleep 4 && continue

    i=$( blkid -o list | grep $repPart | awk '{print $2}' ) #without (vfat)
    [ "$i" = "vfat" ] && repPart=""
    [ "$repPart" = "" ] && echo -e "\t($i) can not be used !\n" && sleep 4 && continue

    label=$(blkid | grep $repPart | awk -F"\"" '{print $2}' ) # device exist

    mntPoint="/media/$label" # /media/repository
    blkid -o list | grep "/live/image" >/dev/null
    [ $? -eq 0 ] && mntPoint="/home/partimag" #clonezilla ("/mnt") ("./" #-> /root)

    echo
    devPart="/dev/$repPart"
    mount | grep "^$devPart"
    [ $? -gt 0 ] && sudo mkdir -p $mntPoint && sudo mount $devPart $mntPoint

    mPwd=$(mount | grep "^$devPart" | awk '{print $3}' ) # mntPoint exist
    echo -e "\n$devPart\t$mPwd" && cd $mPwd
    while true; do
    ls -B --color=auto
    echo && read -p "orgImage $> " orgImg
    [ "$orgImg" = "" ] && break
    ls -lB "$mPwd/$orgImg/Info-packages.txt" | grep -q "^l" && echo "Use an orginal directory." && sleep 5 && continue
    ls -B --color=auto "$mPwd/$orgImg/" >/dev/null && [ $? -eq 0 ] && break # directory exist
    done
    [ "$orgImg" = "" ] && continue # return to beginning for an other partition

    #~~newPartition~~~~~~~\
    echo && blkid -o list
    echo
    while true; do
    read -n4 -p "The new partition for the new Image /dev/____ $> " newPart
    [ "$newPart" = "" ] && exit
    echo
    echo $newPart | grep "^sd[a-z][1-9]" >/dev/null && break
    done

    blkid -o list | grep -owq $newPart
    [ $? -gt 0 ] && echo "Partition $newPart should be exist before." && sleep 3

    #~~~newImage_with_newPartition_link~~~~\
    newImg=$orgImg"_"$newPart
    mkdir -m o+rwx $newImg 2>/dev/null
    [ $? -gt 0 ] && echo "NewImageDirectory does exist already" && read -n1 -p "overwrite ?[Yn] " i && [ "${i,,}" = "n" ] && continue

    echo -e "\nWait a moment .."
    ln -fs $mPwd/$orgImg/* $newImg #-s symbol link -f, --force

    cd $newImg
    #~~~choice_orgPart~~~~~~~~\
    allParts=$(cat parts) #sda5 sda6 e.g. from file 'parts'
    orgPart=$allParts
    echo $allParts | grep -owq "[a-z0-9] [a-z0-9]" && read -n4 -p "orgPart: $allParts $> " orgPart #choice if more parts exist
    orgPart=echo $allParts | grep -ow $orgPart #one word only
    [ "$orgPart" = "" ] && exit

    #~~~correction of partition folders~~~
    # sda5 ->sda9 e.g.
    # sda6 ->rm -r
    for i in $allParts; do
    if [ "$i" = "$orgPart" ]
    then ls $orgPart
    | sed "s/^($orgPart)(.)$/mv -f '\1\2' '$newPart\2'/g" | bash #mv '' '' (rename)
    else rm -r $i

    fi
    done

    #~~~correction of 'parts'~~~
    rm parts && echo $newPart > parts
    break
    done # while

    sudo umount -l $devPart
    echo "The image is ready" && sleep 5

     
  • Fuchs

    Fuchs - 2013-08-04

    A correction. The first line of the script begins with #!/bin/bash

     
  • Fuchs

    Fuchs - 2013-08-05

    It's very difficult to transfer right. I am using now a pdf file.

     

Log in to post a comment.