How can I convert a MBR partition to GPT without loss of data?

I partitioned my volume as MBR and was able to install Windows 7 + Mac OS X. Unfortunately, Disk Utility in Mac OS X cannot resize the Mac partition now because it's not a GPT volume. I also cannot upgrade to Mountain Lion because it requires a GPT volume. How can I safely convert the volume to GPT without data loss so that I can resize my volumes?


Solution 1:

I ended up using gdisk to convert the partition. I issued:

sudo gdisk /dev/disk0

And I was greeted with this warning:

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present

***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATON IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************

Command (? for help):

After backing up my data, I wrote the partition table with the changes gdisk made automatically, quit (w, then q), and rebooted.

Booting into Lion was normal, but when I tried to resize my partition table with Disk Utility, I saw that I had a minor volume header error.

Verifying volume "Mac OS X"
Performing live verification.
Checking Journaled HFS Plus Volume.
Checking catalog file.
Checking multi-linked files.
Checking extended attributes file.
Incorrect number of extended attributes
(It should be 245871 instead of 245862)
Checking volume bitmap.
Checking volume information.
The volume Mac OS X was found to be corrupt and needs to be repaird
Error: This disk needs to be repaired...then use Disk Utility to repair this disk

Well, I rebooted and used -s to boot into single user mode. From there, I issued a trusty:

/sbin/fsck -fy

Now all is well. I have a happily resized Mac OS X volume, and I can proceed with my Mountain Lion upgrade.