iMacLinux Kernel Guide
Welcome to the iMacLinux Kernel Guide. This guide is intended to help you get a new kernel compiled and working on your iMac. If you have arrived at this guide through another site, such as iBookLinux, then it means that the editor for that site has not yet updated the guide for that particular hardware product. If that is the case, do not worry, most of the steps should be the same, you may need to browse the menus for hardware that is unique to your system.
Getting the Kernel
There are several sources from which to obtain the source code for the Linux kernel. I would recommend trying the official kernel source first, this can be found by visiting kernel.org, if you are in the us, you can ftp to ftp.us.kernel.org. Most countries have official kernel mirrors, so replacing US with your country code may save you a trip to the kernel.org website, although if this is your first time building a linux kernel you probably want to check it out.
The other source available for the PowerPC is the famous BenH rsync source. If you are having problems with the official kernel source, or you need drivers or patches that aren't in the official source (such as development drivers for new Apple hardware), then you will want Ben's tree. You can find Ben's tree on PenguinPPC.org. You will need rsync to retrieve the source, you should be able to install rsync using rpm or deb packages from your distribution CDs or download them from your distribution vendors web site. You can also find rsync here.
Sometimes support for newer Apple hardware is broken in the official kernel source, this happens for a variety of different reasons, including someone adding support for a new device or making changes to common code, that was untested on a particular piece of Apple hardware. Initially there is a little trial and error involved, to see which kernel source works best on your system. This guide should work for both Ben's tree and the official kernel source, the only difference is how you obtain the source, and there maybe new options in Ben's tree.
This guide is going to assume that you are using the source code from the official kernel tree. However, here are the instructions for getting ben's tree, if you decide to use them, you can skip down to the next section. First cd /usr/src and mkdir benh_kernel. Now type rsync -avz rsync.penguinppc.org::linux-2.4-benh /usr/src/benh_kernel , it may take a couple of minutes depending on your connection. Now all you have to do to keep the kernel up to date, is re-run that same command before you want to build a new kernel. You will now have the kernel source in /usr/src/benh_kernel, you should now type mv /usr/src/linux /usr/src/linux/old and ln -sf /usr/src/benh_kernel /usr/src/linux to link the new kernel source. You can now skip down to the Checking For Tools section, or read on if you want to use the official kernel source. tip: If you have a newer Mac (such as the iMac 350MHz Indigo) you might want to just stick with the BenH code to avoid problems.
Depending on the mirror you access, the source is usually in /pub/linux/kernel/, in this directory you will see lots of vX.X (where X.X are version numbers). Depending on the mirror, these may go back to the original 0.x series of kernels, so which version do you want? The current stable version is 2.4, and the development version is 2.5. It is easy to determine if a version is development or stable, as the second version digit (minor) is odd for development and even for stable. Some people feel that Linux 2.4 is still a little new, we use it here in production and find that it is rock solid, if you are a little paranoid, and don't need newer driver support or better virtual memory support, you might want to grab the latest 2.2 code, which is the previous stable version.
For the sake of this guide, we are assuming that you will use 2.4. If you cd into the v2.4 directory you will find lots of patch-* and linux-* (where * is version.tar.ext, and ext can be gz and bz2. bz2 is bzip2 compressed and gz is gzipped compressed. bz2 compresses better but it may take your system a little longer (few seconds) to uncompress). The patch files can be used to take your source from one version to the next without needing to download the entire source each time. The linux 2.4 source code (bzip2) is approximately 23MB in size, so a broadband internet connection or a lot of patience is recommended.
At the time this guide was written, 2.4.15 was the latest code available. We recommend you use at least 2.4.12 to avoid any possible security or performance problems that existed in versions prior to 2.4.12. The 2.5.0 code was branched from 2.4.15, so 2.4.15 is essentially the same as 2.5.0. Experimental code, and the foundation for new features will be placed into 2.5.1 and on, while the 2.4 stream will receive bug fixes, driver updates and security fixes. New kernel level features will go into 2.5.0, however new drivers will likely be ported to 2.4. You will want to download the latest 2.4.x code, where x is the highest number in the directory, at this time that would be linux-2.4.15.tar.bz2. note: 2.4.15 has compile problems with PPC and some options, you may want to use 2.4.14 or 2.4.13 to avoid problems.
Preparing to build the kernel
Now that you have the kernel source downloaded, you will need to prepare your system to build the kernel. The standard place to put the kernel source is in /usr/src, make sure you are root on your system before doing anything. To be safe, first make a new directory in /usr/src, lets call it linuxtemp. So you would type mkdir /usr/src/linuxtemp, to create the directory.
This guide assumes you know where you downloaded the linux kernel source to. For the sake of this document, we assume that it is in /tmp. So first you need to cd to the directory where you have the linux source, for us, it would be cd /tmp as that is where we downloaded the source to. The source refers to the linux-2.4.15.tar.bz2 (replace 15 and bz2 depending on the version and compressed type that you downloaded). Once in the download directory, you need to uncompress the file. For bzip2 you simply type bunzip2 linux-2.4.15.tar.bz2, if we downloaded the gzip version, we would type gzip -d linux-2.4.15.tar.gz. If you want more information on these commands type man bzip2 or man gzip.
Now do an ls linux*, and you should see that the filename has changed. It no longer has the .bz2 or .gz extension, it is just linux-2.4.15.tar. This is the uncompressed tar file. We want to unpack the tar file into our /usr/src/linuxtemp directory. To do this we will first change to our linuxtemp directory by typing cd /usr/src/linuxtemp, now we want to unpack it (replace /tmp in the following command with the full path to where you downloaded the kernel source, if you downloaded it to somewhere other than /tmp). To unpack it we type (from the /usr/src/linuxtemp directory), tar xvf /tmp/linux-2.4.15.tar. For more details on tar type man tar, the xvf tells tar to unpack and provide verbose (lots of information) on output.
If all went well, doing ls in /usr/src/linuxtemp should reveal a linux directory. Now, chances are /usr/src already has a linux directory, this is probably the header files and full source code from your linux distribution. We don't want to mix the two source code trees up, so we need to rename our new linux directory to something else. So in /usr/src/linuxtemp, we will rename linux to linux-2.4.15. This is very easy to do, simply type mv linux linux-2.4.15, now do an ls, and you will see the directory is now called linux-2.4.15. Just in case this is the same version that came with your distribution, do an ls /usr/src to make sure that nothing with that name exists. If it does, change linux-2.4.15 to something else in the above command. If you already renamed it you will need to change linux to linux-2.4.15. Of course, if you downloaded 2.4.20, use 2.4.20 instead of linux-2.4.15. :)
Now we want to move the kernel source into the /usr/src directory. This is easy to do, simply type (from the /usr/src/linuxtemp directory), mv linux-2.4.15 ... The .. tells linux to move it into the previous directory, which is /usr/src, you could replace .. with /usr/src, for the same effect.
Finally, we want to link linux to linux-2.4.15. We are going to do this with a symlink. The reason for using a symlink, rather than just leaving it as linux, is to make it easy to switch between kernel versions, by just having to relink the symlink, rather than moving directories. There maybe an existing directory or symlink called linux, so lets rename that. First lets cd to /usr/src, by typing cd /usr/src/, then type mv linux linux.old to rename linux. To create the symlink simply type ln -sf /usr/src/linux-2.4.15 /usr/src/linux, see man ln for information on links. Think of the link as a pointer to the linux-2.4.15 directory, everytime you look at the link you are looking at the linux-2.4.15 directory.
Checking for tools
Before we can start building the kernel itself, we need to make sure we have the right tools already installed. If you are using a redhat style distro such as YellowDog or Mandrake, you can use the rpm command to see what is installed on your system. Type rpm -qa | more to list what is installed. The | more tells linux to put the output from rpm -qa and pass it through the more command. This allows you to read the information screen by screen, rather than letting it simply run off the screen. We are looking for some important tools, mainly gcc and make. You can do this quickly by typing rpm -qa | grep gcc. The grep command will look for gcc in the output of rpm -qa, and only display those lines that match. Now, make and gcc are not the only two things needed by the linux kernel. You should check the Changes file. You can find this in the Documentation directory of the Linux source code (eg. cd /usr/src/linux/Documentation then less Changes). This file has the minimum requirements for the kernel. You should make sure that you have all the required software installed and that the versions are higher than those of the requirements. Any recent linux distribution (past year or so), should meet the minimum requirements and have the required packages on the CD or available for download.
The last thing we need to take care of before we can build is the kernel headers. If you are running a redhat style distribution chances are they are lame, and have not symlinked the kernel headers. So we need to check, first cd /usr/include. The two directories we are interested in are linux and asm. These should point to /usr/src/linux/include/linux and /usr/src/linux/include/asm-ppc. However they are probably just directories. To check type ls -la | grep linux and then ls -la | grep asm. If you see something like linux -> /usr/src/linux/include/linux, then you are fine. If you see just linux or nothing at all, then you need to create a symlink. Same goes for asm. To do this is easy, simply type ln -sf /usr/src/linux/include/linux /usr/include/linux for the linux headers and ln -sf /usr/src/linux/include/asm-ppc /usr/include/asm. Now cd /usr/src/linux and get ready to build.
Building the kernel. Now that you are all set, and have checked and installed any required software. You can start the build process.First we need to make sure we are in the /usr/src/linux directory, you can type pwd to see where you are, then if you are not in /usr/src/linux, type cd /usr/src/linux to go there. Before we start, we want to make sure that this is a clean tree, so type make mrproper. This cleans out any files that might have accidently made it into the tree, unlikely, but lets be safe.
There are many different ways to build the kernel, we are going to use the console menu method, since it is pretty quick and easy to navigate. The kernel stores your configuration in a .config file, if you have one from a previous version or one you built before you know works, you can copy it to /usr/src/linux, and run make oldconfig. This script will then prompt you for any new features or drivers since that config was built. For our example though, we are going to type make menuconfig to start the menu configuration.
If it worked, you should get a screen with a blue background and a large grey box with menu options. The top left hand corner should say Linux Kernel v2.4.15, or reflect the version you downloaded. If it doesn't, or it says something strange like v2.2.12, you probably missed a step or are in the wrong directory. If you still have problems, post to the forums for help.
The first menu option is Code Maturity level options, with it highlighted, hit enter to enter that menu. You will see a [ ] with or without an * in it. If it has an * in it, it means it is selected. This option tells the kernel whether or not we want to know about experimental drivers. Don't think of experimental as unstable, usually they work, but they maybe a little new and not so well tested, since that is usually the state of drivers for our apple hardware, we want to make sure the prompt for development and/or incomplete drivers is selected. Use the right arrow to select EXIT at the bottom to return to the previous menu.
The next option is Loadable Module Support, what this means is that Linux has the ability to break up the kernel into loadable modules. Loadable modules are little blocks of code that perform a function that the kernel can load in and out of memory as needed. Lets say you have a scanner, you don't need the scanner drivers loaded into memory all the time, you just need them loaded when you want to use the scanner. So rather than making a large and bulky kernel that takes up lots of memory for stuff you don't use all the time, you can build modules, so the kernel remains small and fast (and so it can fit on removable media like floppy disks). You want to select all the options in the Loadable module support menu (press down arrow to highlight it, then hit enter with SELECT at the bottom highlighted, then make sure each is select [*], use the up and down arrows to move between the options. If one isn't selected, press SPACEBAR to select it. When you have all the options in loadable module support selected, use the right arrow to select exit then press enter to return to the main menu.
The platform support menu is the most important one to get right. Highlight it, press enter to enter it. In there you will see several options. The first is the processor type, with it highlighted, hit enter. You want the very first line that reads 6xx/7xx/74xx/8260 to have the (X) next to it. The other options are for embedded and IBM Power3 and Power4 CPUs. If you have an iMac, iBook, G3/G4 system you want the first option. Your iMac DOES NOT HAVE a Power3 CPU. Selecting it will cause your kernel to well, not work :) With it highlighted, hit enter. You can use the help to read about the other processors if you are interested. You do not want to select the MPC8260 support, and the Machine type should be set to CHRP/PowerMac/PReP. If you have a G4 you want to select Altivec support. Since the iMac is a G3 system right now, you want to deselect Altivec support if it is selected. You can enabled Thermal Management System, however keep Interrupt Drive TAU driver disabled, unless you want to experiment to see if it works on your system. You may want to turn on the average high/low temperature option in cat /proc/cpuinfo on your new kernel does not display the right temperature info. Use the right arrow to select exit, and hit enter to return to the previous menu.
Continue to Part 2
Last Update: 2001-11-24 11:31:36