Hack 65 Running Linux on an iBook

figs/expert.giffigs/hack65.gif

This hack tells the story of a switch to Mac hardware without switching operating systems. It includes some handy hints and tricks picked up along the way while installing Debian Linux on an iBook.

It feels a bit like a homecoming. After years wandering in the cranky wilderness of mix-and-match PCs, I'm working again on a computer that feels like it has a soul. The reason I feel like this? I switched from an Intel-based laptop to an iBook.

However, this story is different from the recent Mac conversion you may have heard about (http://www.macdevcenter.com/pub/a/mac/2002/03/05/mac_community.html). My day-in, day-out operating system of choice isn't Windows; it's Linux. To be precise, Debian GNU/Linux (http://www.debian.org/). And on my new iBook, it's still Debian. This hack tells the story of why I switched to Mac hardware and how the installation process went. It includes some handy hints and tricks I picked up along the way and, finally, my verdict on the hardware.

65.1 The Decision

As both a writer and programmer, my needs are pretty diverse. I spend quite a lot of time traveling to conferences and plenty of time working from my home office, too. For the last two years, my faithful companion in these activities has been a Dell Latitude CPiA laptop. Although not especially light, it's a compact, good-looking machine. For about a year and a half I've been using it with Debian GNU/Linux as its operating system; running the GNOME desktop gave me a good environment to work in, for both writing and programming needs. Unfortunately, the Dell developed an awkward fault that caused the screen to be unusable, so it was time to look for a new machine.

I spent a lot of time looking at options for replacing the ailing machine. Small size was an important factor, as was low weight. Unfortunately, it seems that to get that these days you must also pay through the nose. As a reasonable price was also very important, this made things difficult. One of the most frustrating things about current PC hardware is that it is overfeatured. Manufacturers are endlessly pushing the latest-greatest this or that into the machines, keeping the prices high and bundling stuff you will never need. For a Linux user, latest-greatest hardware is generally a bad sign: it more than likely means something won't work quite right for you.

I was complaining about how expensive small laptops were when a friend mentioned that he thought iBooks were cool. I'd never considered this before but headed over to the Apple site to check them out. I specced out a 12.1" screen 500MHz iBook with the sort of features I required, and it came out at a pretty favorable price compared to the Intel-based laptops I'd been looking at. There were several particularly attractive features: the small size, the long battery life, and Apple's sane approach to memory pricing.

My interest was piqued, but I was still a little skeptical. I spent some days researching whether Linux would run on iBook hardware. In particular, I was pleased to find that my current OS, Debian, ran just fine on an iBook. Eventually I was satisfied and decided to order the machine. Friends were definitely surprised.

After all, a lot of the fuss about the new Mac centers on the beauteous Mac OS X as much as anything. Did I intend to run Mac OS X? No. Isn't that a little odd? Well, umm, I guess . . . it just turned out to be the best and most economic decision. It seemed odd to people that buying Apple was purely a hardware-based choice.

65.2 Partitioning and Bootstrapping

It took seven days from ordering my iBook (12.1" screen, 384MB, 30GB disk, CD/DVD, AirPort card) until its arrival on my doorstep. I was slightly annoyed when it came, as it arrived at 3:00 p.m. and we had guests that evening. A lovely new toy and I wouldn't be able to play! Nevertheless, I switched the computer on that afternoon.

Before I could do anything, I had to feed the machine four system-restore CDs, which appeared to install a complete disk image onto the hard disk. That took about 45 minutes, after which I was free to start Mac OS X. As I knew I would shortly trash and repartition the hard disk, the wait was moderately frustrating. I had chosen to proceed with a network-based install of Debian. There are two other prominent PowerPC-based Linux distributions, Yellowdog and SuSE, but as I've been a Debian user for some years, it made sense to continue with a system I was familiar with.

I paddled around in Mac OS X awhile, not having time to do anything more. I could see why it is winning many converts. I was slightly amused by the vacuum-suction effect when you minimized a window, but in general found the system pleasant to use. It did what I needed finding a network connection quickly and without fuss.

When our guests had gone, I avoided going to bed and decided to make a start on the Debian install. The best resource for this is Branden Robinson's Installing Debian 3.0 onto an Apple iBook page (http://people.debian.org/~branden/ibook.html). Branden's page gives instructions for installing Debian in a Debian-only; Mac OS X and Debian; or Mac OS 9, Mac OS X, and Debian configuration. I knew I didn't need Mac OS 9 but thought that it might be handy to have Mac OS X around, so I pursued the second option.

The first thing to do was repartition the hard disk. This meant junking the current setup and booting from the Mac OS X setup CD. You can then launch the disk configuration tool from the first screen of the install process. I set up a 20GB partition for Linux and a 10GB one for Mac OS X. The Linux partition is a placeholder Mac OS X tools don't know about Linux filesystems, so you just set up a partition to delete later and fill it in properly. I made both partitions of type Mac OS X Extended. Branden suggests that using UFS for the Mac OS X partition might work too, but this caused problems for me later in the install process. Figure 5-25 shows the Debian login screen on my iBook.

Figure 5-25. iBook showing Debian login
figs/xh_0525.gif

The final step was to install Mac OS X into its new home. I reflected at this point how wonderful it was to have a full install CD for the operating system, in contrast to the current trend from PC manufacturers to give you some poxy restore disk-only solution. Apple should be thanked for not trying to lock you out of using alternative operating systems on its hardware.

Typical Debian installations proceed by means of a bootstrap floppy disk that loads enough to get your machine on the Net; from there, you can download the rest of the operating system. The iBook has no floppy disk. Instead, there's a nifty program called yaboot. You download the image of the boot floppy onto your Mac OS X partition, then you use the machine's Open Firmware to instruct it to start up from that image. I had no idea Open Firmware existed, but it can be entered by holding down a magic key combination at boot time. It reminded me of the boot managers of Sun Sparc workstations. Doubtless, there are many magical and strange things it can do, but I stuck to doing what I was told!

Once you've booted into the Debian install image, things proceed more or less as they do when installing on x86-based machines. The only real difference is in using the partition editor. Before you can install Linux, you need to create a boot partition, a swap partition, and as many Linux filesystem partitions as you need. Under Debian PowerPC, there's a specialized tool for this, mac-fdisk. As Branden notes, this is a cruel introduction to Debian. Happily, his installation notes enabled me to sail through this process.

The second quirk is that, rather than running the normal "make operating system bootable," you must drop into the command line to configure the yaboot boot manager for your machine. The effect of installing the boot manager is to give you a short menu screen when you switch your iBook on. You can press L to boot into Linux, X to boot into Mac OS X, or C to boot into a CD-ROM. If you press nothing, the machine boots into your chosen default (for me, Linux) after a few seconds.

65.3 Installing Debian

I won't document the ins and outs of a Debian install: they're described in detail in other places (http://www.debian.org/releases/stable/powerpc/install). I will describe, however, the quirks that are specific to the iBook.

Debian is often criticized as being difficult to set up. In part, this is due to the poor user interface at the package-selection stage. My personal policy is to select as little as possible for installation during the install process and install the software I need later. In particular, selecting the laptop-specific package isn't much use for the iBook, as it has a different style of power management and doesn't have any PCMCIA devices (even if you have an AirPort card, it does not use PCMCIA).

The machine booted the first time with a Debian 2.2.x series kernel. One of my first steps was to install a 2.4.x series kernel (Debian PowerPC currently has 2.4.16). I then proceeded to try and configure as much as I could. I had read that to get the most from the iBook you needed to compile your own kernel, but I intended to see how far I could get with the standard kernel as provided in Debian.

I had no problems at all with the built-in Ethernet port, screen, USB ports, or CD-ROM drive. They all worked just fine. Even configuring X Windows turned out to be easy enough: just run dpkg-reconfigure xserver-xfree86 and answer the questions. Figure 5-26 shows the Debian desktop on my iBook.

Figure 5-26. Debian desktop
figs/xh_0526.gif
65.3.1 Getting AirPort to take off

Setting up the AirPort wireless access was a little more difficult. For users accustomed to using wireless PCMCIA cards on Intel laptops, there are some differences. The main one is that there's no wireless.opts file that you can edit to set up your wireless network configuration, so when the machine enables the AirPort card, it can't find which network to join. I set up a simple workaround for this, after installing the wireless tools package.

In /etc/network/interfaces, I added:

iface eth1 inet dhcp pre-up /usr/local/bin/inet_wireless.sh eth1

and created the /usr/local/bin/init_wireless.sh script:

#!/bin/bash IFACE=$1 iwconfig $IFACE nick MyMachineName mode Ad-Hoc iwconfig $IFACE rate Auto iwconfig $IFACE essid MyNetworkName iwconfig $IFACE enc on iwconfig $IFACE enc s:MyNetworkPassword iwspy $IFACE 00:02:2D:02:9D:9D

It would be easy to adapt this script for your own needs and, indeed, write some housekeeping scripts so you can easily change between wireless networks. Note that I run an ad hoc network, rather than owning a base station. That iwspy line enables me to keep a log of the signal strength to the machine I'm using as a gateway to the rest of my network.

Support for the AirPort can be started either manually, by running modprobe airport as root, or by adding airport into your /etc/modules file.

As soon as the AirPort card worked, I breathed a sigh of relief: the rest of the configuration could take place from the comfort of my armchair!

65.3.2 Installing a new kernel

One major physical difference with the iBook is that the trackpad has only one button. To do the install, I plugged in a USB mouse to circumvent this problem. However, a more permanent solution needed to be found. Another issue was that I had no access to sound, either. Investigation on both of these scores led me to conclude that the time had come to compile a new kernel.

The hero of the PowerPC Mac Linux scene is Ben Herrenschmidt (http://penguinppc.org/~benh/). He maintains a version of the Linux kernel with all the latest toys in it, as well as some other useful tools. I followed the directions on his page to obtain a copy of his kernel. Compiling a new kernel for Linux isn't really that scary, and it went without pain for me. I was helped along the way by following the excellent instructions at iBookLinux:

http://www.ibooklinux.net/plain_page.php?caller=ibooklinux.php+record=79

The only additional information I required to enable sound I found in a posting at iBookLinux:

http://www.ibooklinux.net/php/ibooklinux_g_h.php3?single=68+index=1

This showed me which options I needed. I added i2c-core, i2c-keywest, i2c-dev, soundcore, dmasound_core, and dmasound_pmac lines to /etc/modules, rebooted, and was away.

Adding second and third mouse button emulation was quite simple. The latest "benh" kernel sets up an easy way to get Linux to interpret keyboard keys as mouse keys. I simply had to run these commands in order to make F10 work as the middle button and F11 as the righthand button:

% echo "1" > /proc/sys/dev/mac_hid/mouse_button_emulation % echo "68" > /proc/sys/dev/mac_hid/mouse_button2_keycode % echo "87" > /proc/sys/dev/mac_hid/mouse_button3_keycode
65.3.3 Every silver lining . . .

I got everything I've mentioned so far done within 24 hours, even managing a little sleep. However, there was one fly in the ointment. According to all the newsgroup posts I'd read, there should be no problems using the iBook's internal modem. However, I had no joy.

Further scouring of newsgroups turned up the suspicion that Apple had recently changed to using a software modem inside the iBooks, as they had done recently with the PowerBooks. Repeating the steps one of the posters had gone through confirmed that I, too, had a software-based modem. Resourceful though the Linux community is, it's highly unlikely that a driver will emerge for this modem for some time, if at all.

This left me with an obvious problem, as a modem connection while travelling is important to me. A search of the Linux USB hardware-compatibility charts (http://www.qbik.ch/usb/devices/index.php) turned up some likely options. I particularly liked the look of the Multi-Tech MultiMobileUSB modem (http://www.multitech.com/PRODUCTS/MultiMobileUSB/), as it was tiny. It is also quite expensive, so I had a quick look through eBay. I managed to find that modem's bigger brother (http://www.multitech.com/PRODUCTS/MultiModemZBA/) for a fraction of the price and settled for that. It's still smaller than an average paperback book, so won't add too much to my luggage especially as it's USB bus-powered and doesn't need an external power adapter. The modem works fine with the iBook, using the ACM driver.

65.4 Handy Toys

To get the best from owning your iBook, you can install several useful packages.

65.4.1 Power management

The iBook uses a different power-management architecture from PC laptops. Whereas PCs use APM, iBooks use PMU. I installed the pmud and pmud-utils packages from Debian. Power management controls what happens when you close your iBook lid in order to put it to sleep and when to spin down the hard disk to save power. I was really happy with the way power management worked: sleep and resume were nearly instantaneous and a lot more reliable than with my old Dell laptop.

65.4.2 Special keys

The iBook has keys for adjusting the volume and screen brightness, as well as ejecting the CD. With a "benh" kernel install, the brightness keys worked but neither of the others did. Stefan Pfetzing has written a small program called ikeyd (http://www.dreamind.de/ikeyd.shtml) that makes the other keys work as advertised with a minimum of pain for the user.

65.4.3 Hot plugging

Since most of the devices I will plug into my iBook are USB based, I don't want to be manually configuring all the kernel modules I need to drive these devices. Instead, I installed the hotplug system. Hotplug implements plug-and-play and loads the correct device drivers when you plug in the devices. This also keeps your /etc/modules file down to a short and manageable size.

So far, I've verified compatibility with a USB mouse, my Frontier NEX II MP3 player, and Kodak DC3400 digital camera; all work just the same as with the PC.

65.5 The Verdict

Buying the iBook for its hardware alone turned out to be an excellent decision. It is, however, a big change for PC laptop users. There are no mouse, parallel, serial, or docking ports. Instead, you get two USB ports, a FireWire port, a mini-VGA port for external monitor (adapter provided), and a speakers/headphone jack. The biggest difference is probably the lack of PCMCIA slots. This inevitably means that if you own any PCMCIA cards, this investment will be lost if you move to an iBook. This also puts you more at the mercy of whatever hardware Apple decides to put into the machine.

One of the iBook's best features is the screen, which is rock solid, bright, and very sharp. I was a little worried that such a small screen would be a problem, but my fears turned out to be unfounded, even at the maximum resolution of 1024 x 768 pixels. The keyboard is easy to type on and feels satisfying to use. The sound through the built-in speakers works surprisingly well: a lot less tinny than I had expected.

The iBook is very portable. Although not the world's lightest laptop, at just over 2kg it's eminently totable and appears pretty rugged in its construction. It also runs at a pretty cool temperature, so you can use it resting on your legs for prolonged periods. Putting the iBook to sleep by closing the lid works just fine, and waking it up again takes next to no time. Both Windows and Linux have problems doing this reliably on many PC laptops, so I was delighted to find how well it worked on the iBook.

Visually, the iBook is a winner. It has some great little touches, such as the LED indicator on the power cord that shows whether the battery is being charged. The machine's simplicity is very appealing. With other PCs, there's a trend to add many blinking lights and extra keys to the keyboard: Apple has chosen the minimalist route with great success. There are some cute surprises too: the first time I put the iBook to sleep, it was late at night and dark in my office. I nearly fell off my chair when I noticed the book breathing in its sleep with a little white light next to the lid clasp slowly pulsating.

There was one disappointment, however: Apple changed the modem inside the iBook to one that wouldn't work with Linux. As described earlier, I've got a remedy, but I'd love to see native support for the internal modem.

All in all, I'm exceedingly happy. The iBook feels, both inside and outside, as though it was designed to be a whole. It is a pleasure to work with: so much so, that I'm considering replacing the Windows PC on my home network with an iMac. Modem troubles aside, the iBook makes a fine platform for running Linux.

Edd Dumbill



Mac OS X Hacks
Mac OS X Hacks: 100 Industrial-Strength Tips & Tricks
ISBN: 0596004605
EAN: 2147483647
Year: 2006
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net