Resize Disk Image with Protective MBR and GPT table
0
votes
1
answer
386
views
I've got a disk image that I need shortened slightly (long story - but it deals with variances in flash drive sizes). The partitions are *already* short enough, but the drive size is not.
Basically, I have a disk image that is 15678308352 bytes (30621696 sectors). I'm wanting to reduce the disk image size to 15678292992 bytes (30621666 sectors). The last sector being used by any "real" partition is 30621662 (I'm fine ending there, too, but I padded it by 4 sectors just to be safe). In any case, I'm wanting to resize the partition tables, but I don't really know how, especially since the GPT table is inside a "protected MBR".
Here's the output of fdisk showing the protected MBR:
fdisk mydisk.img
Disk: mydisk.img geometry: 1906/255/63 [30621696 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: EE 0 0 2 - 1023 255 63 [ 1 - 30621695]
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
Here's the output of gdisk showing the GPT info:
GPT fdisk (gdisk) version 1.0.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk mydisk.img: 30621696 sectors, 14.6 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): BD99B4B8-8070-0648-AEA4-B28BCD949EB7
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 30621662
Partitions will be aligned on 2048-sector boundaries
Total free space is 18398 sectors (9.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 8192 249855 118.0 MiB 8300 primary
2 260096 30621662 14.5 GiB 8300 primary
As you can see, I have plenty of room to shrink the disk but I just don't know how.
I tried manually editing the MBR partition size in hexedit, but then I got all sorts of warnings on the GPT partition.
Any ideas?
Asked by johnnyb
(101 rep)
Jul 10, 2024, 05:02 PM
Last activity: Aug 5, 2024, 07:54 PM
Last activity: Aug 5, 2024, 07:54 PM