Linux on Mac: a POWER programmer's primer

Your favorite operating system isn't only for x86

Even though most Linux users have treated Linux as an operating system for their x86 white boxes, Linux runs equally well on PowerPC machines. David looks at Linux on the PowerPC and the appealing range of PPC machines produced by Apple, where the option of using Linux is of great value to many users.

Share:

David Mertz, Developer, Gnosis Software, Inc.

David Mertz is owner and chief consultant for Gnosis Software, Inc. whose corporate slogan is "We Know Stuff!" (and we do). You can reach David at mertz@gnosis.cx; you can investigate all aspects of his life at his personal Web page. Suggestions and recommendations on past or future columns are welcome. Check out his book, Text Processing in Python.



20 January 2004

About PowerPC

The POWER architecture describes a family of RISC CPUs that arose out of a consortium of IBM, Apple, and Motorola. Within this chip family, higher-end POWER4 chips are used in various IBM mid-range machines (see Resources for links to more information on IBM iSeries and pSeries hardware and software); at a personal computer, workstation, or workgroup-server level, the PowerPC branch of POWER chips are used in widely-used consumer machines from Apple Computer. Chips in the PowerPC family -- especially those from Motorola -- are also used in various embedded and specialized systems, including PCs from smaller manufacturers such as the phoenix-like current incarnation of Amiga.

The interrelations among various POWER architecture chips are similar to those in the x86 world -- for the most part, later generations of chips provide backward compatibility with earlier ones while also offering new and enhanced capabilities. Within the PowerPC family branch, five-year-old Apple machines used 601, 603, and 604 model chips. The current models have phased out the G3 but continue to use the similar G4, both 32-bit chips, running at various clock speeds; the recently introduced G5 is a 64-bit IBM chip that mostly adds some multimedia-specialized instructions to the POWER4 chip models.

The bottom line on all these chips, from a Linux developer's perspective, is that they all run Linux happily and well. For the PowerPC branch of the chips, excellent consumer-friendly distributions are available and offer commercial customer support. IBM also installs Linux for customers of its high-end POWER4 machines.


So you want to run Linux -- Why buy a PowerPC machine?

The "default" systems for running Linux are unquestionably x86 machines. Whether based on CPUs from Intel, AMD, Cyrix, Transmeta, or smaller makers, the x86 architecture is well known and makes up the large majority of personal computers, workstations, and small servers. It is certainly safe to go with the majority.

For many Linux users, the best reason to buy a PowerPC machine will be, quite simply, the range of well engineered and reasonably priced machines available from Apple. Admittedly, the G4 lines -- bottom line -- do not quite keep up with comparably priced x86 machines in CPU power. The G4s do not lag that far behind, but they do a little. However, Apple makes some of the best laptops available from an ergonomic, aesthetic, battery-life, and weight perspective. All of those features are far more important to me, for a laptop, than raw number-crunching. On the desktop, the G4 models differentiate themselves mostly on an aesthetic or ergonomic perspective -- for example, in the compactness of Apple's cantilever-mounted flat-panel iMacs. All of Apple's machines, moreover, have a good reputation for durability and reliability -- including their rack mount servers, which are nice for clusters and server arrays.

At the high-end, Apple's G5 towers are comparable in speed to the fastest x86-derived CPUs and systems; in other words, the Intel Itanium and AMD Athlon64. Benchmarks among the three contenders are a mixed bag, but all three chips obtain quite similar performance (all are remarkably fast, and suitable for intensive number crunching applications). Moreover, on price, Apple's G5 towers seem to sell for less than comparably configured systems from x86 vendors such as Dell, Gateway, HP, and other well-known PC retailers (contrary to Apple's reputation for imposing a price premium). It is worth noting that Apple has contributed optimizations to GCC3+ that bring its generation of PPC object code to a quality similar to that of Intel's ICC or IBM's VisualAge C++ compilers for x86 (which are arguably better than GCC on x86).

At the end of the day, the differences between Linux/x86 and Linux/PPC are remarkably minimal. This article will cover a bit more detail on distributions below, but generally, on Linux/PPC you can use the same window managers, run the same utilities, host the same servers, and so on, as you might on any x86 box. Unless you look at the physical hardware -- or are a rare user with a need for precise performance characteristics of various operations (for example, your application is specially designed around particular vector extensions) -- you will not even know which architecture you are running Linux on. The screen will look exactly the same, most configuration files will contain the same settings, and the same bytes will go out over the wire.


So you own a Mac -- Why run Linux?

To a surprising degree, operating systems (other than those from the highly-proprietary Microsoft) have become commodities. What this means is that most vertical applications are a mere recompilation away from running equally well on Linux, FreeBSD, SunOS, Irix, AIX, or indeed on Mac OS X; in some cases even this step is not necessary, since ABIs (application binary interfaces) support foreign binaries.

If you bought an Apple machine in the last few years, it came preinstalled with a high-quality Unix-derived operating system called OS X. OS X has a kernel and collection of base utilities called Darwin, which is under a Free Software license and is derived (in part) from FreeBSD -- the only proprietary elements are in the GUI (Aqua) and in the collection of end-user and system-administration applications that come bundled with OS X. Even X11 (specifically XFree86, despite what the name implies) is supported on OS X, in either full-screen or rootless modes; "rootless" here means that X11 applications run side-by-side with native Aqua ones. You can run Apache on OS X; you can run NcFTP server; you can even run GIMP or KOffice. Why bother installing Linux?

There are a number of scenarios where it makes more sense to run Linux on your Apple machine than to run OS X. A first situation -- one that will appeal much more to hobbyists than to corporate users -- is when the Mac in question is an older machine. OS X is either entirely unsupported, or at least quite sluggish, on older Macs: 603s, 604s, or even early G3s. Linux can be quite snappy on these older systems; and Linux is a lot more useful as a server, or in many cases even as a desktop, than is the Mac OS 9 (or earlier) that came with those older machines. Still, the hobbyist segment is fairly narrow, or at least does not need to look here for advice.

A more important situation where Linux is worthwhile as an operating system for G3, G4, or G5 machines from Apple is when you want to assure a uniform system/user interface across machines. Many enterprises, hosting companies, schools, or research facilities will have a mixture of x86 and PPC systems that it provides to users. While you can recompile most specific Linux applications for OS X, doing so does not bring the systems all the way to having a uniform GUI, configuration files, directory structure, and build environment between the various maintained machines. "Linux everywhere" assures a much greater degree of consistency.

One thing in particular that can be confusing to Linux developers about OS X is its overlay of two distinct directory organizations -- the traditional /etc/, /usr/local/, /sbin/, and so on of Linux/Unix systems, and the /Application/, /Library/, /System/ from Mac OS 9. The /sw/ hierarchy fink creates, additionally, is almost like a third overlay. Moreover, even though OS X has an X11 server built in, I have still found a variety of minor glitches (redraws, key bindings, etc.) in using X11 applications there -- Linux with a good window manager such as KDE or GNOME is a much more seamless environment in this case.

Apart from developers who might use PPC desktops or laptop machines, Web-hosting companies would like to present a predictable system to its customers who maintain sites via SSH, FTP, or Web-based interfaces -- regardless of whether a domain is hosted on PPC or x86 chips. Considering servers further, Linux offers several advantages over OS X, even over the server version of OS X. One major strength of Linux is the variety of filesystems that have been developed for it or ported to it: ext2, ext3, ReiserFS, IBM's JFS, SGI's XFS, etc. Each of these has its own strengths, often specific to particular usage scenarios (Web host, streaming multimedia server, RDBMS, etc.). While the server version of OS X supports an enhanced version of HFS+ with journaling and optional filename case-sensitivity, it cannot match Linux's range of filesystem options. Also, I should mention -- but not overemphasize -- the little matter of cost: An unlimited-client version of Mac OS X Server will cost you US$1000 per machine, whereas Linux is free of cost (and even a support contract from a distribution vendor is much cheaper than this). The caveat here is that if OS X Server's administration tools save your IS staff even a little work each day, that kilodollar outlay can quickly pay for itself.


Distributions

For this article, I installed and evaluated four distributions of Linux for PowerPC machines: Debian, Knoppix, Yellow Dog, and Mandrake. All were installed and tested on a G4 iMac. I found two of the distributions to be well polished and easy to use, right on par with the best x86 Linux distributions; the other two I would have to describe as "not ready yet." A few other distributions exist as well -- and more will certainly be created over time. I was not aiming to provide a thorough comparison of every distribution readers might choose to use, but simply to get a sense of the "state of the art" -- no slight is intended towards those distributions I did not look at.

The two distributions that I found less that compelling were Debian (Woody) and Knoppix. The latter is an interesting creature that I've found useful on x86 machines. Knoppix uses a "live boot" CD -- that is, booting from the Knoppix CD gives you a working Linux environment with KDE, OpenOffice, and a good collection of utilities. Using Knoppix, there is no need to create any partitions or boot setup on a PC, and you can carry the Knoppix CD between various machines to have a uniform configuration on each. Unfortunately, testing on three separate systems, Knoppix/PPC never managed to boot quite right: KDE would not load, and the fallback was a crude TWM shell that did not get the video mode quite right (colormap and sizing problems). Networking, including wireless, however, seem to be recognized correctly; so you can use the command-line tools. Once Knoppix/PPC gets some more polish to it, it -- or something like it -- will be a very useful way to run Linux non-destructively on existing Mac OS X machines. (See Resources for links to full articles on Knoppix.)

The problems I had with Debian/PPC are probably similar to what dedicated Debian users most love about their distribution to start with. Installation is strictly a text-mode affair, with no options for changing configuration once a fatal "Y" or "N" has been pressed. As long as you make no mistakes and read each installation screen carefully, installation proceeds well enough. It even automatically finds on the network any modules that do not happen to be on the installation CD(s). Many installed utilities and applications -- GCC, Python, the kernel, OpenOffice, etc., lag quite a few versions behind the most current ones, but most widely used tools are available as Debian packages (and hence fetchable using the wonderful apt-get). However, the killer problem I found with Debian/PPC was my inability to get X11 working on it -- the installation seemed wholly unaware of any remotely relevant video card models, and some post-installation attempts at configuration proved fruitless, too. I am certain that there are Debian/PPC users who have worked out the configuration issues, but compared to the ease of installation of other distributions, I have trouble recommending Debian to many users.

Both Yellow Dog (Sirius/3.0.1) and Mandrake (Bamboo/9.1) have quite slick Linux distributions for PowerPC. Overall, I would recommend Yellow Dog over Mandrake to most users, but each have some strengths and weaknesses. The fact that Yellow Dog's maker, Terra Soft Solutions, specializes in PowerPC systems probably leads them to pay somewhat greater attention to the small details of tuning Linux for PPC. On the other hand, for enterprise users aiming at a thorough consistency might choose Mandrake for both x86 and PPC machines.

Yellow Dog and Mandrake both use attractive and friendly installation GUIs; perhaps a slight edge functionally goes to Mandrake for its list of pending and completed steps to the left of the dialog area, but I nonetheless prefer the aesthetics of Yellow Dog screens. Both systems come with a large collection of applications and utilities: Gnome/KDE, OpenOffice, XFree86 4.3, Mozilla, Mac-on-Linux, various servers. For most applications and utilities (and the kernel), Yellow Dog ships with slightly more recent versions, but generally only a micro-release difference, not a whole minor version. In any case, neither Yellow Dog nor Mandrake had any difficulty recognizing my network, graphics card, partitions, mouse, keyboard, and so on. However, I did experience a glitch with Yellow Dog's first attempt to reboot into X11 -- I needed to run /usr/X11R6/bin/Xautoconfig once to clear up the problem.

A few differences between Mandrake and Yellow Dog stand out. The menu organization and theme are a bit different under the KDE window manager that I selected (the default for both), but both systems were very reasonable (and configurable once the system is installed, in any case). And the package selection presets contained a similar set of "personal," "server," and "workstation" options (with customization allowed). I really liked Mandrake's DiskDrake tool for partition management. This graphical utility lets you add, delete, non-destructively resize, format, and otherwise manipulate partitions (but no non-destructive resize on HFS+). Among other things, DiskDrake let me choose the format for my Mandrake partition(s) during installation, rather than simply defaulting to ext3 as Yellow Dog did (but I could still add an extra ReiserFS partition easily enough later under Yellow Dog). And I am generally very impressed with Mandrake's Control Center, on both x86 and PPC, not because it does anything unique, but because it unifies configuration tasks under one interface.

Despite Mandrake's advantages, my ultimate reason for preferring Yellow Dog is its package management system. Yellow Dog seems to be something of a hybrid system: it uses RPMs during installation, but it also installs apt-get for later updates to the system. I have not looked at the internals of the setup, but I could type apt-get install OpenOffice at one line, and have every dependency resolved correctly, the whole 350 megabytes (after expansion) of files downloaded, and the links added to my KDE menu without restarting X11. After wasting many hours wrestling with RPM dependencies, this was a marvel to behold. Of course, I've been spoiled by using fink under Mac OS X, which does the same thing (and is based on apt-get).


Partitioning, multi-boot management, and emulation

Linux/PPC has an important disadvantage relative to Linux/x86: As of this writing, no tools yet exist for non-destructive repartitioning of HFS+ partitions (at least none that are post-alpha and can run from OS X or Linux). Unfortunately, this means that you cannot easily configure a multi-boot system from an existing Mac OS X system; most recent Linux/x86 distributions provide an analogous capability to add Linux to an existing Windows system. It is simple enough to destructively partition an existing drive, then reinstall OS X to one of those new partitions; but doing this means losing your existing data and system configuration (backup/restore might work, but can be tricky to get right). Of course, if you simply want a dedicated Linux machine, this is not something you need worry about.

Partitioning and bootstrapping work a bit differently on Apple machines compared to x86 ones. Specifically, Apple's Open Firmware (an enhanced version of the BIOS Linux users know from x86 PCs) relies on a small "Apple Bootstrap" partition (hda2) to load the subsequent operating system from one of the regular partitions. The partition map also occupies hda1, so the first partition in which you will install any operating system is numbered at least hda3. During machine startup -- using the multi-boot tool yaboot -- your boot process goes through two stages, rather than the one-level x86 MBR boot loaders such as lilo and grub use. At the first stage, you have a choice of booting from, for example, harddisk, CD-ROM, or to Open Firmware; assuming you proceed to the harddisk, you might have the option of booting various operating systems/versions that live on normal partitions.

Configuring yaboot is generally similar to working with lilo. A file called /etc/yaboot.conf contains options for various systems, kernels, partitions, and so on; the format is mostly the same as in lilo.conf. When you have configured yaboot.conf properly, you load yaboot onto the bootstrap partition using the command ybin (as root, of course). To find partition information, you must use the tool pdisk rather than the traditional fdisk on x86 Linux systems. Again, the interface is similar but not quite the same, between the tools. For Mandrake users, the tool DiskDrake is a much friendlier and more flexible GUI-based tool to do the same thing. Using yaboot, you can choose among multiple Linux distributions and/or MacOS versions at boot time.

One nice thing about running Linux on PPC machines is that you can run the Free Software tool Mac-on-Linux this way. This works much like the commercial VMWare does on x86 machines. An entire Mac OS system (either OS X, or an earlier version such as Mac OS 9) runs inside a window within a Linux/X11 display. In fact, you can run multiple Mac OS versions simultaneously, each in their own virtual display window. The Mac OS lives in a kind of "sandbox" where it cannot see its Linux environment, but PPC instructions nonetheless run at full native speed. Assuming you have enough memory to run such a sandbox, Mac-on-Linux gives you a nice way to continue using your Mac OS applications while running Linux -- even proprietary applications for which you have no source code. No need for recompilation as is needed to move Linux applications to an OS X environment.

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Linux on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=11372
ArticleTitle=Linux on Mac: a POWER programmer's primer
publish-date=01202004