# Restore a partimage to a smaller disk

Image credit: WindowsReport

Sometimes; when working with partimage, someone can create a backup of a 1TB partition which contains -for example- only 10GB of data; in this case, when we want to restore it, partimage will fail if the restore disk does not have enough space (1TB in this case).

I faced this problem and here the trick I used to restore the backup image to a smaller disk image.

1. Create an image file with the right size (with seek, we don’t need to actually have the whole space):
# Make sure that the seek=[SIZE] is sufficient
dd if=/dev/zero of=disk_image.img bs=1 count=1 seek=1TB

1. Make the image looks like a disk, by making it as a loopback device.
sudo losetup /dev/loop0 disk_image.img

1. Restore the backup image to the loopback device.
sudo partimage restore /dev/loop0 backup.partimage.000

1. Done, now you can mount /dev/loop0 or delete the loopback device and mount the disk_image.img directly!
sudo losetup -d /dev/loop0 # delete loopback device

mount disk_image.img /mount/point


This was a trick which I want to share with you.

##### Abdelhak Bougouffa
###### Ph.D. Student | R&D Engineer

My research interests include robotics, state estimation, data fusion, AI, and embedded systems.