Tutorial: Triple-boot Win XP, Linux and OS X on an Intel Mac

Leigh Dyer | Jun 8, 2006 4:24 PM
Leigh Dyer arrives in OS heaven with a triple-booting Intel Mac.
Moving your entire product line of both hardware and software from one CPU architecture to another isn't an easy job, but given its progress so far I'd say that Apple could write the book on it. In the last few months Apple has released Intel versions of its iMac and Mac mini systems, as well as the remarkable MacBook Pro, finally answering those that criticised Apple's failure to bring a PowerBook G5 to market.

Apple's biggest surprise so far though has been Boot Camp -- the official but unsupported method of installing Windows XP on Intel-based Macs. Apple had said on several occasions that it would do nothing to prevent running alternative operating systems, but it certainly came as a surprise to me to see the company actively encouraging it. But why can't Intel Macs boot XP in the first place, and what does Boot Camp do to allow it to work?

Welcome, soldiers
Boot Camp is actually a collection of technologies. The key is in the firmware upgrades that Apple has released for each of its Intel systems. Intel Macs use the Extensible Firmware Interface (EFI), a modern, but incompatible, replacement for the age-old BIOS. Intel has been touting EFI for many years, but until now it has been seen mainly on Itanium systems.

The firmware updates add a Compatibility Support Module (CSM) to Apple's EFI that can boot non-EFI-aware operating systems. It's designed to boot XP from a local hard drive partition, or El Torito-style bootable CD like OS installers to live CDs, but in theory it should be capable of booting just about any standard PC operating system.

Along with the firmware upgrade, Mac OS X 10.4.6 includes support for safely resizing OS X (or specifically, journalled HFS+) partitions, and the Boot Camp Assistant helps you repartition and burns an XP driver CD for you.

Unsurprisingly, opinions on Boot Camp are mixed, but now that it's out there I think it's a smart move. Apple is, after all, a hardware company, and if Linux and Windows users can now buy Macs safe in the knowledge that they can use both their favourite OS and Mac OS X, or perhaps even all three, on their new machine, they may well see greater adoption in the marketplace.

I don't think we'll see any big migration of Windows users to Macs running Windows though. Intel Macs are more comparable to PCs in terms of secifications than any previous Macs, and for many Windows users, the extra cost for Apple's machines will be hard to swallow, especially when the cost of a Windows licence is added. For some users, though, Boot Camp is a dream come true -- developers and support engineers have access to a universal machine that can run Linux, Windows, and Mac OS X, all with full performance.

Linux on Intel Macs
I do have a bit of a vested interest in Apple's Intel systems because I have one myself: a 1.83GHz MacBook Pro. I've had a 1GHz Powerbook G4 for about three years now for out-of-office work, but it's looking a little dated these days and I was delighted when Apple revealed that one of their first Intel systems would be a replacement for its aging PowerBook line.

Linux already runs nicely on the MacBook Pro once it's installed.
Linux already runs nicely on the MacBook Pro once it's installed.


The MacBook Pro runs Linux surprisingly well, given that it has only been available for a couple of months. Having a lot of Intel hardware in there helps -- basic chipset features like USB and SATA are well supported, as is the Core Duo CPU and its Enhanced SpeedStep for frequency control. Networking is also supported, using the sky2 driver in recent kernels for the Marvell Ethernet chip, and the third-party Madwifi drivers (www.madwifi.org) for the Atheros 802.11a/b/g chip. There's even accelerated 2D/3D support for the Radeon Mobility X1600 video chip using ATI's latest drivers.

Not everything is perfect though. The on-board Intel HD Audio drivers load, but doesn't produce a sound, and ACPI doesn't seem to handle sleeping yet, though it does report the battery state. There are some minor annoyances as well, such as emulating the system's missing mouse buttons, and convincing the page up/down function keys to work.

The real show-stopper is in installation. You can boot your favourite Linux install CD easily enough using Boot Camp (just hold down option and alt at boot), but creating a bootable Linux install is no easy task, particularly if you want to triple-boot with XP. The problem lies in the rather fragile hybrid partition table needed to make XP's MBR partition table co-exist on a hard drive with the GPT partition table used by Mac OS X. The partition resizing tools that Apple added in OS X 10.4.6 can create a hybrid GPT/MBR partition table, and the EFI boot loader can chain-load a BIOS-style boot loader from the start of one of those hybrid partitions. It's a neat solution to a complex problem, but it's designed only with an XP dual-boot setup in mind.

You can create a third partition to install Linux on to, but you must ensure that you don't alter the partition table at all during the Linux install. No Linux partition tools handle MBR/GPT hybrid partition tables, but many Linux installers will re-write the table even if you don't change anything. There are also issues with video handling in the emulated BIOS, with only certain VGA and VESA modes working.

After a failed attempt using Ubuntu, which left me needing to rebuild the entire system, I grabbed a Gentoo live CD (www.gentoo.org) and used it to install Gentoo 2006.0. I don't normally use Gentoo, but Linux is Linux, and Gentoo ran nicely. Its manual installation leaves low-level details like formatting partitions and installing the boot loader up to the user -- perfect for this install.

To re-create my setup on your MacBook Pro, or another Intel Mac, follow these steps:

1) Install the Mac OS X 10.4.6 update, and the firmware update for your system.

2) Partition the drive using Apple's 'diskutil' command under Mac OS X. This assumes that your drive has a single partition dedicated to OS X, which is resized to fit some extra partitions -- one for Linux and one for XP.

sudo diskutil resizeVolume disk0s2 60G Linux linux 5G "MS-DOS FAT32" winxp 8G

3) Insert your XP CD, reboot, and hold down option and alt to make it boot the device selector. Boot from the CD, and run through the installer. At the partitioning screen, select the drive labeled 'C:'. On each reboot during the installation, make sure you hold down the option/alt key again and boot from the Windows drive.

4) Boot from the Gentoo live CD, and once it has logged in to X, open a terminal. Format the Linux partition you created earlier, which will be "/dev/sda3":

sudo mke2fs -j /dev/sda3

5) Configure networking using the sky2 Ethernet driver and install the Gentoo base system, following the guide on the Gentoo website. When installing a boot loader, make sure you install LILO, configured to write its boot sector to the start of your Linux partition, rather than to the start of the drive.

6) Even with the boot loader on the partition, Apple's boot drive selector won't allow you to boot from it. The easiest workaround is to chain-load the Linux boot sector from NTLDR, the XP boot loader. Mount the Windows drive and copy the boot sector in to a file on it:

sudo mkdir /mnt/windows
sudo mount -t vfat /dev/sda4 /mnt/windows
sudo dd if=/dev/sda3 of=/mnt/windows/linux.mbr bs=512 count=1


Now, edit the boot.ini file on the Windows drive and add this line:

C:\linux.mbr="Gentoo Linux"

7) Reboot the system, and hold down option and alt on boot, selecting the Windows drive. When the XP boot menu appears, select the "Gentoo Linux" option, and then hit Enter at the LILO prompt. Gentoo should boot and drop you at a console login prompt.

I hadn't used Gentoo for a few years until this experiment, and I'm glad to see that it's still coming along well. It's relatively unique among Linux distributions, though similar to the BSDs, in that it builds software on your system as it's installed instead of using binary packages. It automatically pulls in dependent packages and builds them as well, so you can, for instance, build an entire GNOME desktop with a simple 'emerge gnome' command.

Some people use this source-level packaging as a way to apply outlandish compiler optimisations to their entire install to improve performance, though its effects can vary. The real advantage is the level of customisation it offers through its so-called 'USE flags', which let you enable or disable optional features on a system-wide basis. For instance, if you're not a GNOME fan, you can disable optional GNOME GUIs in any built packages. All this compilation takes time, but thankfully, compilers scale very well across multiple CPUs (or CPU cores), so the Core Duo in the MacBook Pro is a perfect CPU for Gentoo.


Parallels Workstation offers a glimpse at a virtualised future
Parallels Workstation offers a glimpse at a virtualised future
Future trends

Most people agree that dual-booting is not an ideal solution -- it would be much better to use virtualisation technologies to run multiple operating systems at the same time. The CPUs in every Intel Mac support Intel's Virtualisation Technology (VT), codenamed Vanderpool, which opens up new levels of performance and compatibility for VMware-style applications. In fact, the first for Mac OS X has appeared: Parallels Workstation, a low-cost application that does run quite nicely. Hopefully we'll soon see some open-source competition from QEMU as well.

If I was a betting man, I'd say that Apple may ship virtualisation technology as part of their next OS update, Mac OS X 10.5 (Leopard).

It will still take some time for virtualisation to be the standard way to running multiple desktop OSs though, because little is currently virtualised above the CPU itself. Emulation techniques for storage and networking work well enough, but emulated video simply can't handle the demands of gaming, or 3D accelerated desktops like those Mac OS X, Xgl on Linux, or Vista, and virtualising the video hardware may be as big a task as virtualising the CPU.

This article appeared in the July, 2006 issue of PC Authority.