how to truncate a disk image file of unused space without corrupting GPT partition table (end pointer)
GPT includes both a main partition table at the start of the disk and a backup partition table at the end of the disk. (Literally the end of the disk -- the final few sectors of the disk.) Thus, when you truncated the disk image, you removed the backup partition table. What's more, some of the pointers and metadata in the main partition table became invalid, since they were pointing past the end of the (virtual) disk. That's most of what the v
command in gdisk
was complaining about.
None of this means that the disk is completely trashed. So long as the main partition table's data is valid, gdisk
(and most other GPT partitioning tools) can recover. In gdisk
, you would type x
to enter the experts' menu, then type e
to move the backup partition table data to the new end of the disk, and then type w
to write the changes to disk. (I'd recommend typing v
again before w
in case I've overlooked another problem; also, see below....)
Note, however, that there is one more problem: Your disk image is 6,755,395 sectors in size, according to gdisk
; but the final sector of the last partition is at sector 6,755,394. This doesn't leave enough space for the backup partition table (it consumes 33 sectors, by default). If you can re-do the whole process, you should probably shrink the disk image by a smaller amount. If not, try expanding the disk image by 33*512 (16,896) bytes before re-creating the backup partition table with gdisk
.