linux os

Can I Run Linux/Unix on My Mac?

You can’t run any old linux distro on a PowerPC mac. This is because of three fundamental reasons

  • The PowerPC CPU uses a totally different instruction set from x86. You simply can’t run an x86 binary on PowerPC, and nor can you run a PowerPC binary on x86.
  • Byte order. PowerPC uses what is known as ‘little endian’ byte order, while x86 uses ‘big-endian’. In English, this means that, in a byte, binary 1 is stored on PowerPC as: 10000000 and on x86 as: 00000001
  • Hardware interfaces – Apple Macs use different busses, ports and other hardware (sound & graphics architecture) than x86 PCs.

Compile Linux programs on Mac

All of these problems (and a few others, but these are the main ones) must be solved before you can run software written for x86 on PowerPC.

The C compiler should, by rights, take care of points a and b. The Linux kernel is written in standard C, and can be compiled to run on the PowerPC without a problem. (This is because the source is available, and has been written and modified with the aim to run on multiple platforms). The PowerPC gcc compiler knows about the byte order it needs to use, and has been written specifically for the PowerPC architecture by the good folks at GNU.

Problems with byte order crop up in higher level programs that have been written assuming they will be compiled on x86 – this problem is most apparent when bit-masks are heavily used to manipulate data. e.g.

(Heavily fictional and hypothetical example) I use a bitmask to control what permissions are set on a file. I make a byte like 00000111 and use the rightmost 3 bits (bits 1 to 3 on x86) to correspond to Read, Write and Execute permissions. This will work great on x86, but on PowerPC, the byte is stored as: 11100000. If I use the rightmost 3 bits (bits 5 to 8 on PowerPC) of the byte, without first checking what byte order the system uses, I will end up setting all my permissions to ‘off’ when they should have been on. As you can imagine, if you haven’t made any allowances for different byte orders, you have a big problem getting your program to compile on multiple systems.

Modern compilers take care of this problem to some extent, but a lot of software, especially drivers, graphical software and some other types are written only with x86 in mind and need to be modified heavily to run on PowerPC for this reason.

Hardware support (problem c) is a thorny issue – While the OS can run quite happily on PowerPC, it needs to know how to communicate with the devices attached to the CPU – i.e. to display text and graphics on a Macintosh graphics card, which were until recently quite different from a PC SVGA card. Newer PCI Macs are making steps towards solving this problem, but sound hardware, SCSI drivers, USB drivers and all the other bits that make a Mac a Mac (as opposed to another PowerPC based machine like an IBM RS/6000) need to be supported by the OS.

Yellow Dog Linux (and MkLinux etc.) are major engineering feats, kudos to them.

Once you have the OS running on the hardware, compiling software is easy, provided that software is written knowing about the byte order problem. You can simply recompile the application from source and get a Linux PowerPC binary which will run happily.

Problems show up when programs are available only as binary – i.e. the current Windows/Macintosh software distribution model supplies programs only as binaries, and you can’t run an x86 binary on PowerPC. This is a problem that needs to be addressed by the software manufacturer – they need to recompile their program for PowerPC (possibly modifying it heavily to fix byte order problems) and redistribute it for PowerPC users. A big task that many see as not worth the effort.

Run Open Source programs

Open Source programs do not have this problem to such a large degree, precisely because the source is available. You can recompile it for PowerPC, and if it has problems, fix them yourself or find a good natured Linux hacker (sometimes the program author will do this for you, if they find PowerPC users want to run their program) to fix them for you.

Most UNIX CLI tools should run happily on LinuxPPC, as long as the source to them is available, and you have PowerPC versions of the libraries they depend on – Again, if the libraries’ source code is available, you can recompile them for the PowerPC architecture too.

Yellow Dog should come with lots of software that has been recompiled for LinuxPPC already.

GUI apps are a slightly different kettle of fish, since they often rely on complex libraries that are not easily ported across platforms, but I imagine that KDE and GNOME/GTK are available for PowerPC, and this should mean that you will be able to run a reasonable amount of X (GUI) software too.

In fact, looking at Yellow Dog’s page, it looks like they ship something similar to the RedHat 6.2 Package, which means you’ll have most of the tools you need (web browser (Netscape), image manipulation (GIMP) plus hundreds of other utilities) out of the box.

The rule of thumb is that if the source is available, the software will run. If the software is binary only, you’re often out of luck.

With regard to MacOS X, it is based on BSD UNIX, which is largely compatible with Linux source, and in fact has Linux binary compatibility as well. You’ll still need a PowerPC-compiled binary, but a lot of Linux software should run unmodified on MacOS X, as long as Apple doesn’t do anything stupid to make it difficult.

Theoretically, you could run X Windows and X apps alongside MacOS X (Carbon and Cocoa) applications, but I don’t know whether Apple would allow this to happen, as it would result in significant ‘dilution’ of their GUI environment.

It should also be possible to create some kind of Aqua-GTK binding which would let GUI Linux apps run on MacOS X, but Apple would probably need to release specs and maybe source for this to happen so I’m not holding my breath.