如何截斷具有多個分區的映像中未分配的部分


0

我為驅動器的每個分區創建了未分配的空間,以將其複製到較小的硬盤驅動器中。但是我的映像仍然是240 GB,因為在取消分配過程之前,扇區仍然是從舊位置開始的。

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

有什麼辦法可以將一個扇區接一個扇區合併嗎?或只是截斷我的圖像文件中的這部分?這樣我就可以截斷空白空間。因為此映像應約為60gb,但由於每個分區之間都有空白扇區,因此目前看起來為240gb。

0

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.