Macbook dual boot wifi-with-WPA howto

From Mactel-Linux

Jump to: navigation, search

Contents

Preparations

Install Boot Camp, make a Windows partition and install rEFIt as described in Dual Booting.

Booting Linux from the live CD

Once you have a Windows partition and rEFIt is installed, you can insert the live CD. The results of booting from it were a bit of a disappointment for me.

First, after the "Loading kernel..." screen, the screen would go blank and not reappear. That was solved by typing "nosplash" at the boot prompt, as indicated by the text on the boot screen.

When I booted again with "nosplash", I could see the messages from the kernel flying by during its boot, but the kernel crashed before its boot was complete with the message:

"Kernel panic - not syncing: IO-APIC + timer doesn't work! Boot with apic=debug 
 and send a report. Then try booting with the 'noapic' option".

So I rebooted, and typed "nosplash noapic" at the boot prompt to pass the noapic option to the kernel, and pressed enter. Now I did reach the shell. Yipppeeee!!!!... or not.

Because now, whenever I hit a key, Linux treated it as two keypresses. So when I typed 'parted', it said 'ppaarrtteedd'. And when I then pressed backspace, it said 'ppaarrttee'. The system was running, but completely unusable. Google came up with a solution from obscure mailing list archives: if this happens to you, pass the kernel the "irqpoll" option at the boot prompt. So my boot prompt string became: "nosplash noapic irqpoll". And this time: YIPPPEEEEE!!! I could boot into Linux and issue commands!.

Partitioning

I typed 'parted' at the shell prompt and came into parted and typed 'help' to see the parted help menu. It was clear enough to delete the windows partition and replace it with a Linux swap partition and a ReiserFS partition. I immediately, from within parted, formatted the ReiserFS partition. Apparently, one should not do that, because later I got filesystem errors on my ReiserFS partition. I reformatted the ReiserFS drive with the mkreiserfs command and now everything was fine. I mounted it on /media and copied all directories in / except /proc, /sys and /media to /media.

Making the Linux partition actually bootable

I followed the instructions from Dual Booting and copied the lilo.conf file listed there to /etc/lilo.conf on the ReiserFS partition, and rebooted. Now, the Linux partition showed up in rEFIt, but when I attempted to boot it, it said "Missing operating system". I already expected such thing, because I hadn't run "lilo" to actually write a kernel loader to disk. So I rebooted into the live CD Linux and tried to run lilo. It turned out there is no lilo in the whole live CD. So I booted into OS X, transferred the /sbin/lilo binary from my Linux desktop onto the MacOS X partition of my MacBook, and rebooted into Linux from the live CD. I made a directory /media/sda2 and mounted the Mac partition on that with 'mount -t hfsplus /dev/sda2 /media/sda2'. I mounted my ReiserFS partition as /media/sda4 and copied the lilo binary from the Mac partition to /media/sda4/sbin. I chrooted to /media/sda4, mounted proc and sysfs on /proc and /sys within the chroot and ran "lilo".

I rebooted and booted Linux from the ReiserFS partition. It worked, but crashed with an error saying that it was unable to mount the root FS (that is, the ReiserFS partition). Apparently (not unexpectedly this time), the kernel had no built-in ReiserFS support.

Building a kernel with ReiserFS support

So I booted into OS X, downloaded the sources for Linux 2.6.17.11 onto my desktop, and rebooted into Linux from the CD. First, I tried to mount the Mac partition and build the Linux kernel on that; that gave me some strange filesystem errors (like "hfs: walked past end of directory") which in turn made the build bail out. Apparently, the HFS+ driver in Linux is not stable enough for heavy stuff like kernel compilations. So I mounted the ReiserFS partition, copied the kernel source tarball to /usr/src on that partition and unpacked it there, and built from there.

The kernel configuration was quite okay by default; the most important changes I made are enabling ReiserFS as a built-in option and enabling the Intel/ICH7 ATA and SATA controllers as built-in while disabling or configuring as module the other disk controller chipsets.

The buid goes blazing fast on these groovy laptops ;-), so a bit later I chrooted to my ReiserFS partition, copied the new kernel image (arch/i386/boot/bzImage) to /boot/vmlinuz-2.6.17.11 and made the symlink /boot/vmlinuz point to it, so I didn't have to change the lilo.conf. I ran "make modules_install" from the Linu build directory to install the modules, ran "lilo" to write an updated kernel loader to disk, and rebooted.

And I chose the Linux hard disk partition in rEFIt. It worked!

Configuring the fresh Linux system to usability

Because I'd just copied the system from the live CD, I was dumped into a root shell. I didn't have write permission on /, I solved that with 'mount -o remount,rw /dev/sda4 /'. The underlying cause is a bad fstab, so having gained my write access to the disk I edited /etc/fstab to reflect the new situation as well as my taste.

Now, I made a user account with the 'adduser' command, logged in as that user, and just typed 'startx'. And now, some of that Ubuntu goodness seemed to be present even in these harsh circumstances; I was immediately dumped into a GNOME session with Firefox and GAIM at my fingertips.

Wait, Firefox, GAIM: I need network access! I plugged in the ethernet cable of my wired network and ran 'dhclient eth0'. It worked, I was on-line, just a matter of minutes after booting the Linux installation from the first time.

Now, I didn't want to type 'dhclient eth0' manually every time I want that network connection to work; I found out by browsing through /etc that you can configure the default configuration of your network interfaces in /etc/network/interfaces; the file itself contains pointers to further explanation on how to configure it. I made it say that eth0 was using DHCP.

Configuring the wireless network

MacBooks have a wireless network card from Atheros for which there appears to be no driver in the default kernel; you have to get the Madwifi driver package to make it work. Simply follow the instructions to build and install madwifi (you have to complete with a 'make install' as root, I couldn't find that in the docs), and then you have a driver. Give the command 'depmod ; modprobe ath_pci' to load it.

The network interface you have to use to connect now is 'ath0'. However, I'm a bit of a noob when it comes to wireless networking, and I only know the nice Airport interface. So what was I supposed to do now? Simply do 'dhclient ath0'? That didn't work, and couldn't work, because I'm using WPA passphrase protection on my wireless network.

It turned out via google that WPA wireless networks are somewhat rough terrain from Linux; you can connect to them using the tool wpa_supplicant. WPA supplicant is installed on Ubuntu, however, when I tried to use that one, it gave me an arcane error message: "ioctl[IEEE80211_IOCTL_SETMLME]: Argument list too long", which itself was buried between a lot of other, irrelevant debug output.

Research in the source code turned out that it was because the version of wpa_supplicant that comes with Ubuntu is built against an older version of Madwifi. If you want to use a recent Madwifi, you must build wpa_supplicant yourself. So I downloaded the source from the wpa_supplicant web page. You then have to write a file named .config in the source directory of wpa_supplicant. I used this one:

  CONFIG_IEEE8021X_EAPOL=y
  CONFIG_EAP_PSK=y
  CONFIG_WIRELESS_EXTENSION=y
  CONFIG_DRIVER_MADWIFI=y

It configures PSK (passphrase) as the only EAP to support; I'd gladly included other EAPs, but doing so resulted in an error when wpa_supplicant started.

Then I had to edit the Makefile to append -I/where/the/source/of/madwifi/is(or /usr/include/madwifi) to the CFLAGS variable.

I typed 'make' to build the wpa_supplicant, and when it was finished there were two files 'wpa_supplicant' and 'wpa_passphrase' in the directory. I copied them to /sbin to overwrite the Ubuntu versions of these files.

To work, wpa_supplicant needs a configuration file like this in /etc/wpa_supplicant.conf:

  network={
       ssid="<Your WiFi SSID>"
       psk="<Your WPA passphrase>"
  }

Where the SSID is the name of your wireless network as it appears in the Airport menu in OS X.

You can then invoke wpa_supplicant like:

wpa_supplicant -i ath0 -c /etc/wpa_supplicant.conf -D madwifi -d

and leave it running. The -d turns verbose output on; Use -dd for even more verbosity or omit the option for a quietwpa_supplicant.

If your wpa_supplicant establishes a connection with your wireless access point - for me it did - you can then indeed use DHCP to bring up the ath0 interface with 'dhclient ath0'.

And w00t, wireless networking's up!

ATI Drivers

Now its time to install the ATI Catalyst drivers. I installed the latest version listed here. In my case, I installed 8.29.6.

I ran aticonfig like so:

sudo aticonfig --initial
sudo aticonfig --overlay-type=Xv


I received an error about a missing library when trying to run X so I ran:

apt-get install libstdc++5

You can check to see if it already exists at /usr/lib/libstdc++.so.5

Further information and acknowledgements

I got the information for getting wireless networking up via googling around and using the search feature on the ubuntu site. These results were especially helpful:

Personal tools