While I spend most of my time these days in Mac OS X, there are times when working with Windows in a VM just isn’t good enough. (For example, when needing to run the Windows 8 Phone simulator.) So in my most recent upgrade, I got a 500GB SSD in my new MacBook Air 13" to make sure I had room for multiple boot partitions.
Googling for a while on the best approach to create multiple partitions with boot camp, I ended up following the instructions on “MBA13/2012: OSX + Win7 + Shared exFAT” as they made the most sense to me. (There does seem to be a bit of confusion on the topic1.)
It all worked fine. I’d originally set my “data” partition to use the exFAT file system with the intention that I could write to it easily from the different operating systems. However, I later reformatted it as HFS+ as the vast majority of the time it’s used from Mac OS X. The boot camp drivers in Windows allow read-only access to HFS+ volumes so I could still access the data as need be. I figured I could copy the files into the Windows partition if I needed to make changes.
A surprise came when I noticed that when I booted into Windows I could see the primary Mac OS X partition, but not the additional data partition. It was shown as “unallocated” space. Clearly the revised (“hybrid”) MBR I’d created had missed the volume out. So I booted back into Mac OS X to resolve.
$ sudo gptsync /dev/disk0 Current GPT partition table: # Start LBA End LBA Type 1 40 409639 EFI System (FAT) 2 409640 156659639 Mac OS X HFS+ 3 156659640 157929175 Mac OS X Boot 4 157929472 314439679 Basic Data 5 314441728 938305535 Mac OS X HFS+ 6 938567680 977104895 Basic Data Current MBR partition table: # A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 409640 156659639 af Mac OS X HFS+ 3 156659640 157929175 ab Mac OS X Boot 4 * 157929472 314439679 07 NTFS/HPFS
There it was. On the four partitions in the MBR the rescue partition was there, instead of the “data” partition I’d created. I tried
$ sudo gptsync /dev/disk0 2-af 5-af 4-07which created the partitions I actually wanted (with the Windows partition in the same position) except the 4th partition wasn’t bootable. Thus when I rebooted the machine, Windows wasn’t shown as a boot option in the boot camp menu. So a little more Googling and researcing hybrid MBRs2,3 led to me to gptfdisk4.
$ brew install gptfdisk $ sudo /usr/local/sbin/gdisk /dev/disk0 GPT fdisk (gdisk) version 0.8.7 Warning: Devices opened with shared lock will not have their partition table automatically reloaded! Partition table scan: MBR: hybrid BSD: not present APM: not present GPT: present Found valid GPT with hybrid MBR; using GPT. Command (? for help): r Recovery/transformation command (? for help): h WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one, just hit the Enter key at the below prompt and your MBR partition table will be untouched. Type from one to three GPT partition numbers, separated by spaces, to be added to the hybrid MBR, in sequence: 2 5 4 Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): Y Creating entry for GPT partition #2 (MBR partition #2) Enter an MBR hex code (default AF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #5 (MBR partition #3) Enter an MBR hex code (default AF): Set the bootable flag? (Y/N): N Creating entry for GPT partition #4 (MBR partition #4) Enter an MBR hex code (default 07): Set the bootable flag? (Y/N): Y Recovery/transformation command (? for help): o Disk size is 977105060 sectors (465.9 GiB) MBR disk identifier: 0xDA825D62 MBR partitions: Number Boot Start Sector End Sector Status Code 1 1 409639 primary 0xEE 2 409640 156659639 primary 0xAF 3 314441728 938305535 primary 0xAF 4 * 157929472 314439679 primary 0x07 Recovery/transformation command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/disk0. Warning: Devices opened with shared lock will not have their partition table automatically reloaded! Warning: The kernel may continue to use old or deleted partitions. You should reboot or remove the drive. The operation has completed successfully.
Job done.
P.S. Except - I could have skipped the gptfdisk step if I’d read the gptsync docs more carefully instead5:
type is an MBR partition type code; prefix with ‘0x’ if you want to enter this in hexadecimal. The separator between partition and type may be ‘+’ to make the partition active, or ‘-’ to make it inactive; only one partition may be active. If both the separator and type are omitted, then the partition will be inactive.
So I could have just run
$ sudo gptsync /dev/disk0 2-af 5-af 4+07where the + would have marked the partition as bootable.
P.P.S. Note that I didn’t resize any of the partitions. I’d only try that if I was willing to restore everything from backups as it’s very easy to stuff up a partition table.
P.P.P.S. Yes, there’s a small partition reserved for Linux. Haven’t used it yet, it’s on my list for when I have some significant free time for a change.
——
[1] Macbook Air + Lion + Windows 7 Boot Camp + shared partition
[2] Hybrid MBRs: The Good, the Bad, and the So Ugly You’ll Tear Your Eyes Out
[3] Bootcamp Partition Lost Repairing Mac Partitions
[4] Obtaining GPT fdisk
[5] Command: gptsync device [partition[+/-[type]]] …