cloning partitions (windows 8) with gpt table from linux kubuntu acronis


 

WARNING
I DO NOT TAKE ANY RESPONSIBILITY FOR LOSS OF DATA AND PARTITIONS. THIS ARTICLE IS PUBBLIC BUT IT’S MADE FOR MY OWN USE ONLY.

IF YOU LOST DATAS AND PARTITIONS IT’S NOT MY FAULT, THIS ARTICLE IS NOT FOR NOOBS, PLEASE BE CAREFULL WITH DD .

All the article it’s just based on these commands :

BACKUP

sudo dd if="/dev/sdXY_INPUT_DEVICE" of="OUTPUTFILE" bs=4096 conv=notrunc,noerror

RESTORE

sudo dd  if="INPUT_FILE_NAME" of="/dev/sdXY_OUTPUT_DEVICE"

so for example if you don’t trust my code do :

BACKUP sdb1 partition

sudo dd if="/dev/sdb1" of="$HOME/sdb1_image.img" bs=4096 conv=notrunc,noerror

RESTORE sdb1 partition

sudo dd  if="$HOME/sdb1_image.img" of="/dev/sdb1"

NOWARDEV BASHRC RESTORE AND BACKUP FUNCTIONS

now i am lazy so i have created my own bashrc with nice progress bar (that require pv program )

backup_partitions

THIS IS MY OWN EXPERIENCE SO IF YOU ARE DOING THE SAME STUFF I AM NO RESPONSIBLE OF ANY DATA LOST

i have created 2 bashrc functions to help me to backup and restore

backup_partition
restore_partition

to use these functions you need of :

pv
dd

pv it’s only to monitor dd work and to print % but probably you are missing it so :

sudo apt-get install pv

1)put this code on ~/.bashrc file that it’s in your home

backup_partition(){

#Copyright (C) 2015 nowardev nowardev@gmail.com

#This file is part of kde-peace-settings.

#kde-peace-settings is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

if [[ "$1" == -* ]]; then
	case "$1" in
		-h) echo "backup_partition input_dev ouput_dev" ; return ;;
	esac
fi
echo
if [[ ! -z $(ls /dev | grep "${1##*/}") &&  -d  "$2"  ]] ; then
	if [[ ! -z $(grep "$1" /proc/mounts) ]]; then
		echo $"$1 it's mounted please umount it before."
		return
	else
		date="$(date +"%d-%m-%y")"
		outname="$2/${1##*/}_$date.img"
		outname=${outname/\/\//\/} #remove potential // problem
		echo $"do you want execute \"sudo dd if=\"$1\" of=\"$outname\" bs=4096 conv=notrunc,noerror\" (y\n) ?"
		read
		echo "$REPLY"
		case "$REPLY" in
			[yY]|[yY][eE][sS])

				sudo pv -p -t "$1" | dd  of="$outname" bs=4096 conv=notrunc,noerror

			;;

			[nN]|[nN][oO])
				echo $"user exit"
				return
			;;
		esac

	fi
else
	echo $"$1 it's a valid partition ? and $2 it's really folder ?"

fi
}

restore_partition(){
#Copyright (C) 2015 nowardev nowardev@gmail.com

#This file is part of kde-peace-settings.

#kde-peace-settings is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

if [[ "$1" == -* ]]; then
	case "$1" in
		-h) echo "restore_partition  output_device  INPUT_FILE" ; return ;;
	esac
fi

if [[ ! -z $(ls /dev | grep "${1##*/}") &&  -e  "$2"  ]] ; then
	if [[ ! -z $(grep "$1" /proc/mounts) ]]; then
		echo $"$1 it's mounted please umount it before."
		return
	else
		echo $"doing sudo dd of="$1" if="$2" ?  (y\n) "
		read   

		echo $REPLY
		case "$REPLY" in

		[yY]|[yY][eE][sS])

		sudo pv -p -t "$2" | dd   of="$1"  

		;;

		[nN]|[nN][oO])
		echo $"user exit"
		return
		;;
		esac

	fi
else
	echo $"$1 it's a valid partition ? and $2 it's really a file ?"

fi

}

2)do , in a terminal , where you will perform every commands:

source ~/.bashrc 

ok now you are ready to clone yours partitions in files :

if you type

backup_partition -h

or

restore_partition -h

you will get help :

backup_partition input_dev ouput_dev
restore_partition output_device INPUT_FILE

so let me show you my miserable partitions table with lsblk , i know my partition table and i know that 605GB it’s the folder where i store my files and the 54GB it’s the windows partition , instead sdb1 it’s the uefi stuff .

sdb      8:16   0 698,7G  0 disk
├─sdb1   8:17   0   260M  0 part
├─sdb2   8:18   0   1,5G  0 part
├─sdb3   8:19   0   260M  0 part
├─sdb4   8:20   0   128M  0 part
├─sdb5   8:21   0  54,6G  0 part
├─sdb6   8:22   0 605,4G  0 part
└─sdb7   8:23   0  27,1G  0 part

BACKUP A PARTITION WITH MY BASHRC FUNCTIONS

so now i will use sdb6 to store every sdb1 sdb2 …. etc partitions . i will mount the partition sdb6 into a folder so :

sudo mkdir /media/sem/myownbackuppart

now my sdb6 it’s formated into ntfs so i will use :

sudo mount -t ntfs-3g /dev/sdb6 /media/sem/myownbackuppart

now i will backup the partition with this : MAKE SURE TO SET LIKE FIRT ARGUMENT THE DEVICE !

backup_partition /dev/sdb1 /media/sem/myownbackuppart/

this command will generate a file called sdb1_31-12-14.img here /media/sem/myownbackuppart/

now we will do the same thing for every partition

RESTORE THE PARTITION

restore_partition /dev/sdb1 /media/sem/myownbackuppart/sdb1_31-12-14.img

and you have done , i have tested this method in my computer and it works i hope it will work for you too .

now the bashrc functions that lets you to clone a partition in an img file :

Here i will save the informations to bakcup and restore the partition table

BACKUP PARTITION TABLE GPT

sgdisk -b - /dev/sdb > /mnt/sdb6/gpt-table-windows_hdd

RESTORE PARTITION TABLE GPT

sgdisk -l - Gg /dev/sdb < /mnt/sdb6/gpt-table-windows_hdd

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: