I'm a genius.
Or an idiot monkey with a typewriter and lots of spare time.
I've finally figured out, or rather, chanced upon, the right combination.
The Objective:
I wanted a USB stick that I could boot on a macbook to install/repair OS X Lion.
I also wanted the stick to be able to boot on a PC (or a mac), and install crunchbang, or run as a live image.
I also wanted to use the unused space (either in the Live FAT partition, or in a dedicated partition) as a general data-shuffling drive, which means it must be accessible on windows.
The Problem:
Macs won't boot from an MBR partitioned disk, they require GPT partitions. If you partition a USB disk in mac os X, It uses the GPT partitioning scheme, and it also creates a "dummy" MBR containing single a "protective" entry, type 'EE', covering the entire disk.
This entry seems to confuse windows, which then can't read or write partitions on the disk, or rather, more dangerously, it gets confused about which partitions are which and writes the wrong one.
If you remove the MBR entry, or even the entire MBR, the mac will no longer boot the disk.
It's also possible to create a "hybrid MBR",whereby every partition defined in GPT has a corresponding entry in the MBR. I used gptdisk to do this.
Doing this allows the mac to boot, and in theory the disk looks like an ordinary MBR disk too. For example, my USB stick, contains the following partitions in GPT:
Number Start (sector) End (sector) Size Code Name
1 40 409639 200.0 MiB EF00 EFI System Partition
2 409640 8612767 3.9 GiB AF00 OS X Lion Install
3 8876032 15771647 3.3 GiB 0700 Live
And the hybrid MBR gets created as:
Number Boot Start Sector End Sector Status Code
1 40 409639 primary 0xEF
2 409640 8612767 primary 0xAF
3 * 8876032 15771647 primary 0x0B
4 1 39 primary 0xEE
However, this STILL confuses windows, whether you include the 'EE' protective entry or not, or whether it's defined as the first or last partition in the MBR table. Perhaps windows borks on the EFI partition type 'EF, or the mac os 'AF''. Perhaps it borks on any partition type it doesn't support.
The solution
I created a hybrid MBR with the partitions in reverse order. This way, windows sees the FAT partition as the first entry in the partition table. If it gets confused by the other entries, that happens after it has read the correct details for the FAT partition. So the hybrid MBR is:
Number Boot Start Sector End Sector Status Code
1 * 8876032 15771647 primary 0x0B
2 409640 8612767 primary 0xAF
3 40 409639 primary 0xEF
4 1 39 primary 0xEE
Now, this USB stick:
Boots on macbook, to install/repair OS X
Boots on PC into crunchbang live (or install)
The vFAT Live parition can be read/written from windows (there is 2G free space there)
Yes, the easy solution is to have 2 USB sticks, one for the mac, one for PCs, or one for boot and one for storage.
But easy rarely leads anywhere interesting. Actually, this exercise has led into EFI / legacy BIOS boot territory, which is a twisty maze of dank passages all alike, with lots of dead ends, wrong turns and pitfalls. not a pleasant trip, but you win some, you lose some.
Astute (or bored) readers will note that the stick doesn't yet boot linux on the macbook, and there is 150M free on the disk. Next, I plan to add another EFI partition, FAT formated, and install EFI grub on there, to boot linux in EFI mode on the macbook. I'm not sure yet why the BIOS-mode Live partition isn't showing up as a boot choice on the mac. I may also experiment putting the GPT entries in reverse order, so the MBR and GPT numbers match.