A while back, I split my MacBook Pro hard drive into three partitions so I could have a small FAT32 partition for sharing files between Windows and Mac OS X. After getting a dedicated Vista system, I wanted to delete the extra partitions I created and get all my disk space back. The only problem is that Boot Camp refuses to work on a disk that is partitioned this way, and the command-line tools are complex. I finally got up enough courage to give them a whirl.
This stuff is tricky, and I expected there was a very good chance I’d make a mistake that would force me to restore from backups. If you decide to give this a try, be careful.
I used SuperDuper to clone my Mac hard drive (in case I screwed up big time) onto an external disk drive, booted into the cloned operating system (your Mac OS X install disc should work too), and got a list of gpt partitions:
$ sudo gpt show rdisk0
gpt show: /dev/rdisk0: Suspicious MBR at sector 0
start size index contents
0 1 MBR
1 1 Pri GPT header
2 32 Pri GPT table
34 6
40 409600 1 GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
409640 142270944 2 GPT part - 48465300-0000-11AA-AA11-00306543ECAC
142680584 262144
142942728 10485760 3 GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
153428488 41680896 4 GPT part - 48465300-0000-11AA-AA11-00306543ECAC
195109384 262151
195371535 32 Sec GPT table
195371567 1 Sec GPT header
To delete the 5GB and 20GB partition, I used this command:
$ sudo gpt remove -i 4 rdisk0
gpt remove: /dev/rdisk0: Suspicious MBR at sector 0
gpt remove: /dev/rdisk0: 1 partition(s) removed
$ sudo gpt remove -i 3 rdisk0
gpt remove: /dev/rdisk0: Suspicious MBR at sector 0
gpt remove: /dev/rdisk0: 1 partition(s) removed
Using the original output of gpt, I calculated the disk space I had to work with (10485760+41680896)/2=26083328K and restored my original bootcamp config:
$ sudo diskutil resizeVolume disk0s2 72842723328B \
"MS-DOS FAT32" Windows 26083328K
Started resizing on disk disk0s2 Macintosh HD
Verifying
Resizing Volume
Adjusting Partitions
Formatting new partitions
Formatting Disk
100% ..
Finished resizing on disk disk0
Then I rebooted from my internal hard drive, used Boot Camp Assistant to restore the Mac to a single partition, and it reclaimed all that disk space.