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.
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.