Installing Gentoo/Linux on the TiBook 1Ghz

Here is a little document I wrote because I had the time to do it, needed to type something to get used to my new dvorak keyboard, and felt I might as well try to do something even remotely useful. It's about installing Gentoo GNU/Linux on an Apple Powerbook, the 15" model with a 1Ghz G4 CPU, 60Go hd, radeon 9000 with 64Mo RAM, and no superdrive but only the cd-burner. Before this laptop, I had no experience whatsoever with apples, but had been using linux for about a year. And guess what, I really liked what I got out of this little marvel. What follows is mostly about gentoo, but most of it can be translated into another distribution's technical jargon, although you might be better off with a more specific document in that case. Anyway, all the gentoo-only stuff has been regrouped in the last section. Have fun!
And please don't be too harsh on my English, I'm French after all, so I had to let a few mistakes slip through, to honour tradition, you know...
Oh, and just to make you drool a little bit, or at least show you it's worth the effort, a (big) screenshot of my kde desktop, with slicker-cvs and a pseudo-dock using superkaramba/kroller.

Updates



Contents


Why ?

Three whys, actually. If you're not interested in philosophy and the whole advocacy thing, and only want to get that bloody laptop up and running, just skip this and jump to the next section.
First of all, why the PowerBook? Well, if you are reading this, you probably either own one or are considering buying one (cheers!). If not, you probably took a wrong turn somewhere on the www... Overall, the Powerbook is in my humble opinion one of the best linux laptops around. Let's take a quick look at its pros and cons:
Pros:
Cons:
A second question could be: Why run linux when you've already got OS X? The short answer would then be: because I can do it, and I like it better. To go into the details, although mac osx is a POSIX-compliant UNIX of tremendous worth, and a lot of software that run on linux can be used on OS X thanks to the fink distribution, I still do not find it as powerful as the good old linux, even on this not native platform. A few explanations:
Lastly, one could wonder: why a gentoo? Of course, that's the distribution I'm currently using, but I've also given debian and mandrake a go on that same laptop, and liked both very much (more preciselly, I installed a debian woody that I immediately upgraded to sarge and bits of sid, and mandrake 9.1 -still in beta at the time - both giving me the same amount of support as gentoo). But I still don't find that they give me nearly as much flexibility as a gentoo. Portage, gentoo's package manager, is a notoriously powerful and advanced tool that, combined with a few gentoo utilities such as etc-update or virtual runlevels, gives you the means to build exactly the system you want at a minimal cost for your free time, provided you are ready to let the computer work for you during your sleep. The wide range of possibilities it offers makes gentoo more a kind of revolutionary (well, Linux-From-Scratch came first...hum) meta-distribution than just another distro. I actually found that, knowing what I wanted out of my system right from the start, gentoo brought me to a point were I was satisfied with it in less time (I'm talking about time actually spent in front of the computer, not compile time of course) than any of the others. Sure it is in part because of my greater familiarity with gentoo, but I have also used debian and mandrake quite a lot, and think I know enough to make them work.
But Portage and the related tools are only a not-so-big part of what makes gentoo great. Its users community plays, I feel, a greater part in that, combining excellent tools, like irc channels or the ever faithful gentoo fora, and excellent people, both devs and mere users, to give you the answers you need asap. And the documentation from the gentoo website is plainly excellent as well.

PS: No, I'm not selling gentoos for a living. I'm just in L...er, no, shouldn't tell that to anyone but my psychiatrist ;-)

All considered, the choice of a distro is more a question of want you want to make of your computer, and how. Mandrake should please both beginners and people who want to be up and running asap with a pretty standard config, while gentoo and debian target users that are a tad more experienced with linux already and want to get the best they can manage while learning more. While gentoo's learning curve can be seen as the steepest, it's really a pleasure to go and tackle it. I might give debian another chance if I ever find my way to the level of arcane knowledge of some debian gurus I've met, but I just don't have the time right now.

Back to top

Basic configuration

The very first step for would-be gentoo-ppc users is to get the ppc installation guide from http://www.gentoo.org, and print it if possible, it's really helpful even from a non-gentoo point of view. Although the current guide is still marked as gentoo-1.2, it also applies to 1.4.

Filesystem

Partitioning a macintosh is a bit trickier than a x86. You have to keep in mind the facts that the first partition is for the partition table, and that you need a 800k hfs bootstrap partition for yaboot, the ppc bootloader. You may also need more micro-partitions at the start of the disk, for the mac os9 extensions, should you choose to retain "Classic" support in mac OSX. Thus it is a good idea to install OSX first, then linux, and take extra care if you ever have to reinstall mac os (in case you have to do that one day, I'd advise you to do it from linux, by booting off the install cd/dvd in mol - startmol --osx --cdboot).
For the linux filesystem, you should make it ext2/3 rather than reiser, which does not really support ppc at the moment. If you intend to use your powerbook on battery a lot, you might want to stick with ext2, as, combined with the noflush daemon, it will limit your disk accesses.
You may also need a shared partition which both mac os and linux can access read-write (linux only has limited read support for OSX's hfs+, and OSX has no support whatsoever for ext). Although the very old hfs filesystem also works, the best solution still is FAT32, which you can create from linux using the mkdosfs utility from dosfstools, and mount as vfat in linux and with "mount_msdos" on OSX. If you only need limited sharing and intend to use mainly linux, you can also do it with mol and any combination of scp/ftp/nfs.
Update: there is now a new kernel hfs+ module from Ardistech, which supports reading OR writing at a very decent speed (as fast as FAT, if not more) on hfs+ volumes, and also provides support for file permissions and ownership, definitely a plus over FAT. This doesn't work with the benh stable (2.4.20) branch, but it has already made its way into the instable branch (2.4.21pre), which is available only by rsync (from rsync.penguinppc.org::benh-devel)or bk. The lucky gentoo users will only have to emerge the latest ppc-sources (>=2.4.21-r1) to get it. It seems to be quite reliable, I've only heard of one incident when it messed up a partition on a 2Gb write.

Kernel configuration

You will have to use a benh kernel to get all the functionalities of your powerbook to work, or any kernel with the benh patch (2.4.20-benh-9 or newer will do for sleep support). I wouldn't recommend combining it with any other patch you're not sure of , especially the more experimental ones (do not even try to meddle with the 2.4 preemptible stuff!), as those probably won't add anything useful, and are more likely to bork everything.
To get a benh kernel on gentoo, just do "emerge ppc-sources-benh", and you'll find the patched source tree in /usr/src/linux. On other distributions, you should also be able to get it in a similar way (apt-get install kernel-patch-benh on debian), although this will sometimes (e.g. on debian) only download the patch, leaving it up to you to apply it ("patch -p1 < /path/to/patch" in /usr/src/linux). You may also download it from http://kernel.org.
Then you should go through the kernel configuration and compilation like this:
#make menuconfig
#make dep && make clean vmlinux modules modules_install
Things that you need to remember more specifically for the configuration are: For a quick start or reference, you can take a look at my own .config file, but be aware that there is some stuff in it, like more support for packet filtering, that is not necessary for everyday use. Once you have built it, copy the vmlinux to /boot with the apropriate name, edit /etc/yaboot.conf accordingly, and run ybin -v to update your bootblock (or mkofboot -V if you need to set up a new bootblock, on a fresh install or after (re)installing Mac OS).

USB and firewire support

USB support gives no issues at all. You only need usb-ohci support in your kernel, plus specific drivers for what you want to do with the usb. For example, I use my usb for a cd-burner, a mouse and occasionaly a usb key, and my kernel config looks like this, with scsi generic and cdrom support on top of it.
Firewire works all right too, as far as I can tell, but its usage can be a bit trickier. I use firewire for an external hd, so I have enabled "IEEE 1394", "OHCI 1394" and "SBP-2" support in my kernel, along with "sd_mod" (scsi disk support, the hd actually appears as a scsi device, as usual). But you have to remember that firewire is definitely not hot-pluggable on linux, and doesn't get along too well with some other stuff, such as PMU sleep. Thus you will want to leave these functionalities as modules. Here is an init script I wrote to mount/unmount the firewire filesystem on mine. Don't know why I have to modprobe sbp2 twice in a row, though, since the scsi device never registers after the first modprobe.

Sound issues, Alsa

I have encountered a few issues with the oss sound driver for the powerbook, dmasound_pmac. The sound would get all borky for no obvious reason from time to time, leaving me with no solutions but to manually unload and reload the module. The playing would regularly skip as soon as I tried something a little CPU-intensive. And mplayer had a hard time using oss output properly, which resulted in a sound output that skipped every few seconds. That last problem could be solved independantly by using "ao sdl" instead of "ao oss", but anyway I've found the alsa sound driver (that is the "powermac" driver for the powerbook) to be much more reliable.
Although I've got oustanding issues with just alsa per se, like a crackling noise on mp3 playback, which is not exceptional on ppc, alsa with OSS API emulation works flawlessly for me, and is on the whole much better than the original OSS driver. To get alsa sound drivers on gentoo with OSS emulation, just do:
# ALSA_CARDS="powermac" emerge alsa-driver alsa-utils alsa-oss
then edit the /etc/modules.d/alsa file to have it look like what follows, then run modules-update.
alias char-major-116 snd
# OSS/Free portion
alias char-major-14 soundcore
## ALSA portion
alias snd-card-0 snd-powermac
## OSS/Free portion
alias sound-slot-0 snd-card-0

# OSS/Free portion - card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss

options snd cards_limit=1
Alsa sound can then be started with the init script /etc/init.d/alsasound, provided the oss sound modules aren't already loaded. You may have to adjust the output and maybe unmute the speakers with alsamixer/aumix. To get alsasound at boot, just remove the oss modules from /etc/modules.autoload if necessary, and run "rc-update add alsasound boot".
As a side note, I've had mixed experiences with alsa support of pmu sleep, wich sometimes throws me a kernel "Oops" on snooze. So I usually switch back to dmasound_pmac before putting it to sleep.

Miscellaneous


Back to top

Xfree

The radeon 9000, aka M9, is now supported by Xfree-4.3, and there is still a way to get it to work with Xfree-4.2 thanks to Michel Daenzer's xfree-drm-trunk. Yet the stock Xfree install (actually it's more a kernel issue for 4.3) still won't give you dri (resulting in very poor 3D performance), thus you will need to update your drm modules with Michel Daenzer's patched code. On gentoo, all it takes is
# USE="radeon" emerge xfree-drm
Once again, this package is kernel-dependent, and will have to be reemerged like alsa-driver for every new kernel.
The xfree driver is called "ati", and must be used with the kernel radeon framebuffer interface. On top of this, if you use the dri extension and want support for the PMU "snooze" (sleep) function, you will need to force the agp mode to 4x. Thus the "driver" section of my XF86Config file is as follows:
Section "Device"
Identifier "Accel"
Driver "ati"
Option "UseFBDev" "true"
Option "DRIReinit" "true"
Option "AGPMode" "4"
BusID "0:16:0"
EndSection
Notice that the "UseFBDev" option is necessary to get a working display, and that at the moment this means that you cannot use the dvi port to connect an external monitor. It is theoretically possible to do that by commenting out the "UseFBDev" part, but it means that the display on the built-in lcd would get irretrievably messed up, and probably nothing short of a reboot would clear that borkiness. See this for more info on external monitors on the powerbook.

The built-in trackpad is a one-button traditional Apple mouse, which is pretty disturbing under X. But there is a way around this, using keyboard shortcuts. To map a second and third buttons for the mouse you will need to add these lines to /etc/sysctl.conf (in this case I mapped F10 and F11):
dev.mac_hid.mouse_button_emulation=1
dev.mac_hid.mouse_button2_keycode=68
dev.mac_hid.mouse_button3_keycode=87

The last issue I had with xfree was about keymaps, as I wanted to use one that supported French specific characters, and xfree's French keymaps didn't fit the powerbook's down-sized keyboard. I thus resorted to writing my own keymaps from bits grabed on the internet, and ended up with what is mostly a French azerty keymap, with Alt mapped on the "Apple" keys and mode_switch (for special chars) on the original "Alt", plus a few useful add-ons and some limited changes that make it more fit for coding. You can grab it here if you're interested, along with the dvorak X keymap, built on the same model, that I have switched to recently. The Xfree keymaps must be put in /usr/X11R6/lib/X11/xkb/symbols/macintosh/ , and configured like this in your XF86Config:
Section "InputDevice"
Identifier "Keyboard0"
Driver "keyboard"
Option "Protocol" "Standard"
Option "AutoRepeat" "250 30"
Option "XkbLayout" "dvorak-mod"
Option "XkbModel" "macintosh"
Option "XkbRules" "xfree86"
EndSection

Since then, Claas Langbehn has come up on the debian-ppc mailing list with a more elegant solution for German keyboards, which should also work with other languages (I haven't tested yet with French). The trick is to patch /etc/X11/xkb/keycodes/xfree86 with this, and put the following options in the Input Device section of /etc/X11/XF86Config-4:
Section "InputDevice"
Identifier "Generic Keyboard"
Driver "keyboard"
Option "CoreKeyboard"
Option "LeftAlt" "Meta"
Option "RightAlt" "Meta"
Option "ScrollLock" "Compose"
Option "RightCtl" "Control"
Option "XkbRules" "xfree86"
Option "XkbLayout" "de"
Option "XkbVariant" "nodeadkeys"
EndSection
This should map the Apple key as AltGr or mode_switch, and enable you to use classic xfree keymaps. Finally, here's my XF86Config-4.

Back to top

Mac OS and mol

Mac-on-linux, aka "mol" is a GPL'ed virtual machine that allows you to run Mac OS (9 or X) or another linux-ppc install, either in an X window or on another tty. It's really a great asset of linux on the macs, and it compares very favorably with the solutions available on the x86 to run proprietary software on linux, since it is much more reliable and offers more features than wine*, but remains quite fast when compared to vmware (enough to play some games, like EvNova - my secret reason for buying a mac - or Civilization), and free on top of it.
Setting up mol is not difficult, there are only a few steps to follow: One thing worth remembering about mol is that you can use it to install Mac OS from within linux, without rebooting. This means that you can run mkofboot straight after the install is complete, thus you won't have to go through the pains of booting and chrooting from a linux cd or setting up the boot partition directly in open firmware. You will only need to make sure that your cdrom device is listed in the blkdevs in molrc.osx, then put the Mac OSX cd or dvd in your tray and boot it with startmol --osx --cdboot. If you need to set up a new partition for this, you had better create it first with mac-fdisk in linux, format it to plain hfs (hformat in the hfsutils package), then add it to molrc.osx and boot the cd in mol. You can then choose to install OSX on the new partition by formating it to hfs+ (choose this as an option when you select the disk you will install on, not in the "Disk Utility"). I find this way of doing things more reliable than using the Mac "Disk Utility", which I must admit I am a bit biased against, since the damn thing erased my whole hd and the gentoo I had just got to work, just one week after I got the laptop :(

Back to top

Gentoo-specific stuff

Here are the few more quirks you'll need to remember if you intend to use a gentoo on the powerbook:
Back to top

Useful links

Last updated 06 June 2003
Please feel free to mail me for questions or suggestions.