How to re-size partitions in a complete hard drive image

block-deviceddfilesystemsgpartedstorage

I have taken a complete image of a hard drive using:

dd if=/dev/sda of=/home/user/harddriveimg bs=4M

It would seem to me, that I should be able to re-size the partitions within it after suitably mounting it.

As I am less than familiar with the command line parted, I tried:

gparted /home/user/harddriveimg

While this loaded the partition table, it couldn't find the partitions themselves, e.g. harddriveimg0.

Is it possible to modify an image file like this, without writing it back to some disk, and if so how? I would be perfectly happy with a solution that uses only terminal commands.

Best Answer

You need to associate a loopback device with the file:

sudo losetup /dev/loop0 /home/user/harddriveimg

Then run gparted on that.

Related Question