Introduction

This article is dedicated to documenting methods of imaging partitions. Typically when one looks for information on the internet for free and open source drive imaging solutions, they find information on partition imaging, described in a way to suggest this is drive imaging, but it is not. Drive imaging is imaging the entire drive (not just one partition if the drive has multiple partitions), for an easy backup, and restoration of an entire drive (all partitions, where the partitions reside on the disk, etc.).

Gathering drive partition information for restoration

If the intention of performing a partition clone, is to either restore that partition to another drive, or to the same drive after changing the filesystem structure, one would want to gather the filesystem metadata. Otherwise, feel free to skip this section.

GPT formatted drive

Warning /!\ These instructions assume your drive is partitioned in the GPT format. For more this, please see the UEFI specification here.

MBR formatted drive

This is common for a Windows partition (ex. Windows 8.1 with one main partition, and one boot partition).

sudo parted /dev/sda print
Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  368MB  367MB  primary  ntfs         boot
 2      368MB   225GB  225GB  primary  ntfs

sudo fdisk -l

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x99218dc1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      718847      358400    7  HPFS/NTFS/exFAT
/dev/sda2          718848   439554047   219417600    7  HPFS/NTFS/exFAT

sudo sgdisk -D /dev/sda

***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. 
***************************************************************

2048

Clone a partition with partclone

partclone provides utilities to save and restore just the used blocks on a partition. Partclone supports ext2, ext3, ext4, hfs+, reiserfs, reiser4, btrfs, vmfs3, vmfs5, xfs, jfs, ufs, ntfs, fat(12/16/32), and exfat.

An example of cloning an NTFS drive:

partclone.ntfs -c -d -s /dev/sda1 -o sda1.img

Restore an MBR formatted partition

sudo parted /dev/sda
mklabel
msdos
sudo fdisk /dev/sda
n
p
1
2048
718847
n
p
2
718848
439554047
a
1
i
0x99218dc1
t
1
7
t
2
7
w
sudo partclone.restore -d -s sda1.img -o /dev/sda1
sudo partclone.restore -d -s sda2.img -o /dev/sda2

Windows caveat

While this restoration method will work for Windows 8.1, Windows may temporarily prevent one from using BitLocker. One may fix this issue by booting into the Windows Recovery Environment and executing in a command prompt: }}} bootrec /fixboot }}} For more on this, please see here.

Links

PartitionImaging (last edited 2015-05-29 10:28:24 by 34)