Other How to shrink a GPT disk image?

I have a 64GB GPT disk image file with multiple partitions. I shrank the last (and the largest) partition and now have a free space of 32GB at the end.

Now I'd like to shrink the entire image file. If I simply run truncate -s 32g disk.img, gpart doesn't like it and reports "No such geometry", although I hoped I could use gpart recover ....

Probably I can create another (dummy) GPT disk image of 32GB, create the same partitions as on the original one, make a backup (with gpart) and then run gpart restore ... on the original image using the backup data from the dummy image. Not an elegant way (and requires additional disk space).

Am I missing something obvious?
 
Have a look at:
Code:
man mdconfig
It will give you a device from a file. On that device you can run "gpart"
Also have a look at:
Code:
man mdmfs
As this can be interesting.
 
Of course, I do use mdconfig disk.imggpart won't operate in plain files.
However, it doesn't help in shrinking in any way. mdmfs looks interesting, but is irrelevant here as well...
In this particular case I just truncated the file, and since it was a Windows 7 disk image I hoped that Windows is smart enough to fix it at boot. It did fix it ― another not-very-elegant way (-;
 
Back
Top