Tuesday, November 11, 2008

OpenSolaris on a Macbook

I have a Macbook.

*jeers from the audience*

Just for the record it's the white model with 2Ghz CPU's and Wireless-N ( which makes it a Merom, I think )

I decided to install OpenSolaris on it. It being Apple, it has to be more obtuse and difficult than any other PC on the market.

Ultimately, a Mac is just like any other PC so there shouldn't be a whole lot of problem except for one thing: EFI.

EFI is Intel's BIOS replacement, because even though OpenFirmware/OpenBoot have been around forever, work well, and are open, it wasn't invented there. Nothing really boots off EFI yet except Linux, OSX, and the various HP operating systems. GRUB doens't work with EFI, for example, which leads to a number of problems getting OpenSolaris installed.

So, what the prospective OpenSolaris user will need to do is this:

Step 1: install a first stage EFI bootloader. This almost certainly means downloading and installing rEFIt. rEFIt is really easy to install, you just run the installer in the disk image.

Step 2: Toggle rEFIt's on switch. Open a terminal ( /Applications/Utilities/Terminal.app ) and type this:

/efi/refit/enable-always.sh

Step 3: You need to use Disk Utility to give yourself a free partition. Set it up as an MS-DOS (FAT) volume.

Step 4: Now, because the partition is marked as a DOS partition, OpenSolaris isn't going to want to install on it, so you'll need to mark it as a Solaris partition. This is done roughly the same way you'd do it anywhere else, that is to say, you'll be using fdisk. Open a terminal window and open fdisk on your drive, typically disk0. The -e flag makes it an interactive session.

$ fdisk -e /dev/disk0

It being Apple, the syntax is different from any of the other fdisk's you're likely to have seen. Find your partition in the list ( it'll be the one not marked HFS+ ) and to change it use:

setpid <partition number>

It'll prompt you for a type number in hex without the leading 0x. You'll be using type number 'BF' for Solaris2 ( because 0x82: Solaris was stolen for Linux swap... ). Then just 'write' to write the table, 'quit' to exit out of fdisk.

Step 5: Insert your CD, and reboot. You'll not get the familiar grey apple logo, instead you'll be presented with a rEFIt menu. Since rEFIt doesn't really know about the partition table well enough to present the operating system with anything sane, use the Partition Tool to set things up. Just use the defaults that it asks you about. Once that's written to disk, back in the rEFIt menu there'll be an option to boot OSX, or the CD. Choose the CD.

Step 6: Now you're running the OpenSolaris livecd, play around, do whatever you're going to do with it. Networking won't work because myk isn't installed. When you decide to install, there's some considerations. First off, you can't write to the partition table, rEFIt doesn't allow it (and it doesn't make much sense anyways). Since the installer really, really wants to write to the partition table ( bug 6413235 ) you'll need to trick it.
First off, you need to create a new file in your home directory named 'fdisk'. It should contain this:

#!/bin/sh
echo "$*" | grep -- "-F" > /dev/null
if [ $? = 1 ] ; then
/sbin/fdisk $*
fi

( Thanks to Jim Walker for the script )

make it executable

$ chmod 755 ./fdisk


and rather than running the installer icon on the desktop, you'll need to trick it in to using this new fdisk script with $PATH.

$ PATH=$PWD:$PATH pfexec

it'll do it's thing, fill out the information, click Next> a half dozen times. When it prompts you where to install, don't muck about with the partitions, there should be one Solaris partition that it'll try to install on by default, just click Next> through that screen. Now it's installing

Step 7: Reboot. rEFIt will present you with the option to boot OSX or Linux. rEFIt is dumb and thinks anything that uses GRUB is Linux. Let's ignore this slight for now, but bide our time and destroy everyone and everything they love, leaving them a sad hollow shell wandering the wasteland wishing for death, later. Choose the not-Linux Linux option, and OpenSolaris will boot. ( check here later for instructions on how to change the icon if it bothers you )

Step 8: Networking doesn't work. Pick up Murayama's myk driver. Put it on a USB stick. It comes with a Readme.txt, but you can ignore most of it. All you really need to do is this part:

$ pfexec make install
$ pfexec ./adddrv.sh
$ pfexec devfsadm -i myk
$ pfexec ifconfig myk0 plumb

at this point NWAM should realize that a new NIC exists, and do it's thing accordingly.

Now, wired networking works. Wireless does not because the new ath binary blob hasn't been integrated so the wireless-N chipsets are left in the cold. Sound is hdaudio, and the single button mouse is annoying, so I reccomend using an external one.

Other than that though, you're all good, up and running. Enjoy.

(and to all the other mac-heads that works on OpenSolaris or in marketing for it... now you have no more excuse ;) )