Tuesday, November 7, 2017

OpenBSD on a G4 Cube

I just finished installing OpenBSD on my Power Mac G4 Cube and wanted to write down my steps to success in case anybody else out there ever runs into the same issues I had. For the tl;dr version, skip down to the "NFS Success" section.

First, some back story. I've had my Cube for several years now, though I did not buy it new. When my Cube first arrived, I ordered it a brand new 200GB IDE hard drive. I found a 200GB Maxtor that was not quite as cheap as I'd been hoping since by that time SATA had taken over and IDE drives were getting a bit difficult to find. On a side-note, I discovered that people are making IDE SSDs which is just wild. Must. resist. temptation. to. put. SSD. in. my. Cube...

When I began my Cube experience, Apple's planned obsolescence was well into effect and the latest version of Mac OS X had dropped support several years prior. Happily, the FOSS community continues to support these older machines even now. The first OS I installed on my Cube was Debian Linux. I derive some kind of perverse joy from running current software on a computer that came out in 2000 and whose original vendor has long since discontinued support. It's just cool -- sort of like sticking it to the man. It shows the power of FOSS. Nobody can make a computer obsolete when it's running an open source operating system. It also shows why Intel has such a vested interest in proprietary software. If some start-up were to arrive on the scene with a new, better CPU, there would be nothing to stop the market from shifting away from Intel if the world ran on FOSS. But I digress.

I had actually not been using the Cube for the past few years. It had crashed (though, I now believe this was a freak, one-off occurrence), and it scared me since the Cube was hosting my production Subversion installation. So, I moved Subversion over to a more modern computer and put the Cube on a shelf. But, then, about a month ago, I saw this: <cue the ominous music> Debian GNU/Linux 9 "Stretch" to Drop Support for the PowerPC (PPC) Architecture. Well, I couldn't abide that. My Cube may not have been powered on, but I always knew that, with an internet connection and a couple commands, I could have it back online and updated. So, I began looking into my options.

In the intervening years since I first installed Debian on the Cube, my favorite FOSS operating system has become OpenBSD. I actually ran it on my primary work machine for about 6 months which was a fun challenge. (and the subject of another post some day). Happily, OpenBSD still officially supports PowerPC Macs. Moreover, OpenBSD hasn't bloated up like Linux has in recent years (<cough>... systemd ... <cough>), so it figured to actually run reasonably well on the Cube.

The Task at Hand

If you haven't installed OpenBSD before, it's normally a very straight-forward process. I wouldn't recommend it for novices, but if you understand Un*x-like operating systems, disk partitioning, and you read through the awesome OpenBSD documentation, it's really a cinch. Normally. As I came to discover, my Cube wasn't going to provide me with a typical OpenBSD install experience.

The first sign that there were going to be bumps along the road was when I stuck the new newly-burned install CD into the Cube's CD-ROM drive. Sadly, the Cube's CD-ROM drive has gone up to the big computer part bin in the sky. This is especially sad because the CD-ROM drive was a show-stopper in Steve Jobs's original G4 Cube keynote address. But also sad because OpenBSD doesn't support booting PowerPC Macs from USB thumb drives. According to the documentation, you can boot OpenBSD/macppc in one of the following ways:

  • CD-ROM
  • FFS partition (i.e. an existing OpenBSD installation)
  • HFS partition (i.e. an existing MacOS installation)
  • Remote NFS partition
  • HTTP

That last one is a bit misleading. You can download the install sets from HTTP, but you can't boot from HTTP. CD-ROM was out. FFS was out since you have to have OpenBSD already running. HFS was out since the machine had been running Linux, not MacOS. So that left me with NFS. And, ominously, the documentation gives this notice to those who wish to use NFS:

NOTE: This method of installation is recommended only for those already familiar with using BSD network configuration and management commands. If you aren't, this documentation should help, but it is not intended to be all-encompassing.


Not to be deterred, I proceeded on anyway. There is a scant amount of documentation on NFS booting in the install instructions as well as some more in the diskless(8) man page, but the later is not macppc-specific. I was ultimately successful booting NFS, but not before I tried many, many unsuccessful alternatives.

Fail #1

This actually occurred after several failed NFS attempts, but I'm going to take these out of order, like I'm Quentin Tarantino. At my office, there is a room that is basically a PC graveyard with all sorts of defunct hardware. One of the things in there was an old Dell tower -- old enough to have an IDE hard drive and, more importantly, an IDE CD-ROM drive. My first idea was to try and attach the Dell's CD-ROM drive to the Cube's IDE ribbon cable and try booting from that. After a 24-hour delay for ordering a Torx T10 screwdriver off Amazon, I was in business. Except that it wouldn't boot. I'm still not sure why. I tried switching the drive's jumper switch from cable select to slave and that seemed to get the drive to show up in OpenFirmware, but it wouldn't boot.

Fail #2

My next brilliant idea was to install OpenBSD on the Dell, hook up the Cube's IDE drive to the Dell, format the drive FFS and copy the PowerPC bootloader and install files to the Cube's hard drive and try and boot from the internal hard drive. The instructions mention that the installer creates a 1MB DOS partition for the bootloader when a Mac hard drive is single-booting OpenBSD. So, I went and looked at the source code for the OpenBSD/macppc install script and found the line where the partition is created

echo -n "Creating a 1MB DOS partition and an OpenBSD partition for rest of $_disk..."
dd if=/dev/zero of=/dev/r${_disk}c bs=1m count=1

I ran that command, formatted the partition (newfs -t msdos $wd1i), copied the bootloader over. I then created an OpenBSD disklabel partition, and an FFS partition and copied the kernels and tarball sets across. I then patted myself on my back for being so clever.

Of course, that didn't work either. The Cube was able to load the bootloader, but I couldn't get it to find the bsd.rd kernel on the FFS partition. One of the commenters at misc@openbsd.org thinks this was because the FFS partition was formatted on a Little Endian (i386) machine and the PowerPC is Big Endian. So, yeah...

NFS Fail

So, back to NFS. NFS was actually the first thing I tried since it is an officially supported installation method. I didn't (yet) have a second OpenBSD machine to use, so I installed NFS on my laptop which is running Debian. My mistake is that the Debian implementation of NFS didn't cooperate with OpenFirmware. Might have been user error, but, regardless, setting NFS up in Linux is quite a bit more complex than it is in OpenBSD, especially considering OpenBSD's great instructions.

NFS Success

But that's enough about what didn't work. I finally stumbled onto a winning formula. First of all, booting NFS on OpenBSD/macppc requires three components. (The documentation doesn't make this entirely clear, especially if you read through diskless(8).)

  1. DHCP (/BOOTP)
  2. TFTP
  3. NFS

The DHCP server gives the Cube its IP address, it then loads the bootloader (which is a file called 'ofwboot') via TFTP. And then it points the bootloader to an NFS share which contains the kernel. I knew DHCP and TFTP were working on my Linux laptop since I was able to get into the bootloader. DHCP and TFTP need to be running on the same server, but NFS can be elsewhere. As soon as I moved my NFS server to my OpenBSD Dell, things started working for me. If I was starting from scratch, I would run everything from an OpenBSD server.

Here is my dhcpd.conf: (/etc/dhcpd.conf) I was running Linux isc-dhcp-server, but the configuration is the same for OpenBSD dhcpd:

allow booting;
allow bootp;

host cube {
    next-server x.x.x.x;
    option subnet-mask;
    option routers x.x.x.x;
    option root-path "/srv/obsd62";
    fixed-address x.x.x.x;
    hardware ethernet xx:xx:xx:xx:xx:xx;

'next-server' is the IP address of the NFS server. 'routers' is the IP of your internet gateway (you'll need this if you want to download anything from the internet during the installation process). 'root-path' is the path to the NFS share (should match your share in your exports file). 'fixed-address' is the IP you want to assign to the computer running the install. And, finally, 'hardware ethernet' is the MAC address of the Mac's ethernet card (which you can look up in OpenFirmware:

0 > dev enet
0 > .properties
    local-mac-address ......

You'll then need to set up TFTP (which is honestly just as simple as creating a directory (e.g. /tftpboot) and running "tftpd /tftpboot" as root). Copy the bootloader (ofwboot) into your tftp share and everything else from the macppc distribution folder to your NFS share. (As of version 6.2, all of the files in: http://ftp.openbsd.org/pub/OpenBSD/6.2/macppc)

I should mention before you get started that you should make sure there is only one DHCP server running on your network. In other words, if you network is like almost any network, you should probably disconnect your OpenBSD server and the Mac from the rest of the network until the OpenBSD install kernel is booting so you don't have competing DHCP servers. Once the kernel is booting, you can shut down the DHCP server (rcctl stop dhcpd) on the server and hook the machines back into the network if you need Internet access during the install.

Once you've booted into OpenFirmware (hold down Cmd-Option-O-F after powering on the computer), you just need to type:

0 > boot enet:,ofwboot /bsd.rd

and you'll be booting. Everything else you need is covered in the excellent INSTALL.macppc instructions.

The OpenBSD/macppc Experience

I'm really happy that I've gotten OpenBSD running on my G4 Cube. That said, before you launch into a big project, there are some things you should be aware of. First, not all of the ports that are available for OpenBSD/amd64 or /i386 are available on PowerPC. A couple big ones are missing... Firefox, Thunderbird, GIMP, LibreOffice, Gnumeric. None of those run. Since Chrome's V8 javascript engine has some x86-specific code, Chome (and Chromium) is out as well. As far as I'm aware, there is no webkit or gecko-based web browsers that run at all on OpenBSD/macppc. The best thing I've found so far is Netsurf which has its own rendering engine. Netsurf is a currently-maintained project, but it's a far cry from webkit and gecko-based browsers.

But, if you're like me, this is OK because I plan to primarily run the Cube as a server and all of the server programs I've looked for are there and functional. If you like hacking on things, be sure to join the ports@openbsd.org mailing list and start working on Firefox!


Alex Perez said...

Debian didn't technically "drop" PowerPC. It just got demoted from being a *release architecture*. There are still active builds of Debian for ppc32 and ppc64 available via Debian Ports.

Daniel said...

Yeah I'm aware. I wanted to move to a OS that still treated PowerPC as a first tier release. You could argue that PowerPC is still stronger in Debian-land than in OpenBSD, given that you can probably still run Firefox, GIMP, Libreoffice, etc over there. But I also feel like Linux has become less well suited for running on older hardware as time goes on whereas the base OpenBSD install actually has gotten better over time.

Ten years ago, OpenBSD included Apache and Sendmail, but now runs their home-grown httpd and OpenSMTPD.

Dev said...

Thanks for writing this. I am in your exact same situation with a broken cdrom drive on my PPC Mac Mini. I'll have to give this a try

Spacewolf Jr. said...

I believe you can boot a PowerMac via USB but you need to do so from OpenFirmware (I've experimented with OpenBSD on PPC for eons and I seem to recall doing this).

Mark said...

Just went through the same issues. I have a Powerbook G4 and so far OpenBSD is the only OS that works - I use it as a travel computer.. NetBSD seems to have the most binaries already compiled including Firefox and MPlayer, but there is an issue with the kernel crashing on the G4 during boot loadl. After much research, I found that it is a known issue since 2010 and they have not resolved it yet. FreeBSD 10 works, but they also broke the kernel on 11 and 12 and it kernel hangs during boot. Also a known issue since 2010. FreeBSD 10 is still maintained, but there are no binaries compiled. You must compile every bit of software of FreeBSD. After spending 14 hours compiling Xorg just to find that it failed made an easy decision to leave them.

OpenBSD used to maintain browsers and video players until 5.8. They have since removed many of the ports and can't be compiled anymore. Other than modern browsers and video players being removed (netsurf doesn't work at my company website), OpenBSD is has been easy to install and configure. Wifi works out of the box (unsupported on FreeBSD and NetBSD)

It will be a very sad day when I have to retire my 15 year old laptop because it outlived all OS's. The macppc is an engineering marvel.

Vince said...

I'm running 6.1 on a ppc mac mini, it's working fine. I tried usb booting, but if I remember it needed a newer version of open firmware that I had. I think I netbooted it with dhcp/bootp+tftp but I don't think I needed nfs. I'll setup 6.2 when I get some free time. Openbsd rocks!

Daniel said...

Spacewolf Jr -- I've heard this is possible and found a person that claimed to have success on a bondi blue iMac G3, but I was not able to get it working myself. My understanding is that it is not an officially supported OpenFirmware boot method which is why OpenBSD does not mention this in their documentation.

Daniel said...

Dev -- let me know if you are able to get it working!

Daniel said...

Mark -- I've read through some of the discussion on the OpenBSD ports mailing list and the problem with Firefox etc. appears to be related to a dependency on llvm which evidently doesn't compile. One person suggested removing the dependency since it should be possible to compile several of those packages with gcc, the idea being that that would be simpler than fixing llvm. Hopefully, someone will make some progress on that front. I'm a developer myself, but I don't have the chops to debug that kind of thing.

Daniel said...

Vince-- where did you boot your kernel from if not NFS?

The great thing about finally getting the system running is that I'll never have to do any of that again (unless the hard drive dies or something). Just download the 6.3 install kernel (when it comes out) and boot from that.