Tuesday, May 8, 2007

在Mac上装Linux

So you want to run Linux -- Why buy a PowerPC machine?
http://www-128.ibm.com/developerworks/linux/library/l-pmac.html

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.

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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home