I created unallocated space for my each partition of my drive to copy it smaller hard drive. But my image is still 240 gb because sectors are still starts from old locations before unallocation process.

fdisk -l backup.img

Disk backup.img: 223.6 GiB, 240057409536 bytes, 468862128 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
Disklabel type: gpt
Disk identifier: 8778A8D2-18DA-4F2F-B73D-DEAE0B8DBDCF

Device          Start       End  Sectors  Size Type
backup.img1      2048   2000895  1998848  976M Linux filesystem
backup.img2   2000896  10000383  7999488  3.8G Linux swap
backup.img3  10000384  62480383 52480000   25G Linux filesystem
backup.img4 170000384 230143999 60143616 28.7G Linux filesystem

Is there any way to merge sectors one after the other one? or just truncate this parts from my image file? So I can truncate empty space. Because this image should be about 60gb but because there are blank sectors between each partition it looks like 240gb at the moment.

1 Answer 1


you can't edit the image. you will have to restore each partition one at a time, shrink it, then make a new image. once you have the size needed, yo can restore them all to the new drive.

PS be sure you are making partition images not drive images.

  • what if I create new partition with unallocted space and remove it from image ? Jun 28, 2017 at 7:28
  • if you have already made partitions small enough on the old drive, then make partition images of each. or even directly copy partition to partition
    – ravery
    Jun 28, 2017 at 7:30
  • I gonna use it on virtualbox so it has to be only one partition. Can I make partition images from disk image ? Jun 28, 2017 at 7:33
  • Yes, you can edit an image. Just open it with parted / gparted and edit. Worked fine for me. Oct 28, 2017 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.