Apple MacBook: Dual-booting Ubuntu Linux

Posted by Nicholas Rahn Sun, 20 Aug 2006 12:56:00 GMT

Seduced by the new Apple MacBook, I was powerless to resist when Firefox presented me with the AddToCart button. I configured mine with a 2.0GHz processor, 1GB of RAM and the big 120GB hard drive. And I choose white, of course. Not black, you say? Well, had I wanted a black laptop, I would have bought a Dell or a StinkPad and condemned myself to joining the uncreative horde of tech-cool wannabees. White is it. White is the way. Tech-cool, here I come!

After it arrived, it was only a matter of days until I realized that Mac OS was just not going to cut it. Don’t get me wrong, it’s definitely usable, much more so than Windows, but it’s missing things that I get without too much trouble from a good Linux install. Virtual desktops, complete keyboard (re-)mapping, standard tools like SVN and CVS, applets, and the list goes on. You can of course get some or most of these things from the darwin ports project or other open source projects, but my goal was not to learn some new packaging system and spend countless hours configuring things to my liking. My goal was to get a working development environment up and running on my super-cool new MacBook laptop. And the easiest way for me to do that was to install Linux!

So I set out to install Ubuntu Linux (my new favorite Linux distro) on my new MacBook. Since the MacBooks are Intel processor based and use newish boot loader technology, there are no Linux distros that support out-of-the-box installation. You have to get your hands a little dirty to make it work. Nothing that Gentoo users aren’t used to, but it does take a little familiarity with some low-level installation concepts. If you are not comfortable with setting up partitions, configuring a boot-loader or performing administration tasks from the command line, you should probably just stick with Mac OS.

I should mention a couple of things before we begin.

Let’s install!

Backup

As with any install, the first thing to do is to backup any and all of your data. I’ve lost data to stupid mistakes before so I can tell you first hand that you will not regret taking the time. Backup early and backup often.

Get Ubuntu

Download and burn the Ubuntu CD. The ISO images work both as a live CD and as an installation CD. You should use the Ubuntu v6.06.1 LTS version as it has some improvements for the MacBook that v6.06 does not have.

Partition your disk using Boot Camp

Install the boot menu

% sudo cp -R /Volumes/rEFIt/efi /efi
% cd /efi/refit
% ./enable.sh

Plug-in

Ensure that your MacBook is plugged-in to your local Ethernet. Access to a wireless network during the Linux install is not supported.

Boot-up the Ubuntu Linux CD

Reboot with the Ubuntu CD in the computer. Once you are in the GNOME desktop, double-click on the “Install” icon to start the Ubuntu installer. Follow the installation normally, noting carefully the following steps:

Boot Loader

At the end of the installation process, the install will fail when trying to install GRUB. This is OK. It will say that the installer crashed. This too is OK

You should now find yourself back in the GNOME desktop environment again. Open a terminal (Applications -> Accessories -> Terminal) as we now need to do a few things by hand. In the terminal, execute the following commands:

% sudo mkdir /mnt/ubuntu
% sudo mount /dev/sda3 /mnt/ubuntu
% sudo mount -t proc none /mnt/ubuntu/proc
% sudo mount -o bind /dev /mnt/ubuntu/dev
% sudo chroot /mnt/ubuntu /bin/bash

We have just created an environment that looks exactly like your Ubuntu Linux system will look after we re-boot. In this same window, run this command:

% sudo apt-get install lilo lilo-doc linux-686-smp linux-restricted-modules-2.6.15-23-686 linux-kernel-headers

This installs lilo and a kernel that is more tuned for the MacBook’s processor.

Now use the nano editor (since emacs is not yet installed :-) to create the /etc/lilo.conf file. It should contain something like this:

boot=/dev/sda
default=Ubuntu

map=/boot/map
delay=20
image=/vmlinuz initrd=/initrd.img
append="quiet splash" 
root=/dev/sda3
label=Ubuntu
read-only

Open a new Terminal window and run:

% sudo parted

On the parted command line, execute the following commands:

(parted) print
(parted) set 3

     Note that the "3" is the number of the 
     root partition (/dev/sda3) of the Ubuntu Linux install.

Flag to change? boot/hidden/raid/lvm/hp-service/msftres? boot
New state? on/[off]? on
(parted) quit

Close this Terminal window.

Go back to the first Terminal and run the command:

% sudo lilo

You can safely ignore the warning.

Now exit the environment and unmount the partitions with these commands:

exit
sudo umount /mnt/ubuntu/proc
sudo umount /mnt/ubuntu/dev
sudo umount /mnt/ubuntu

Restart the computer.

Synchronizing the partition tables

When the computer starts up, you will see the rEFIt menu. It has a very nice, Mac-worthy, graphical display.

There should be two large icons: a Mac OS X apple and a Linux penguin; and several smaller icons below. Selecting one of the large icons and then hitting return will boot you into that OS. By default, without input, Mac OS X will boot in 20 seconds.

Before booting for the first time, you must synchronize the MBR/GPT partition maps. Do this by selecting the Partitioning Tool, the small disk drive icon below the two OS icons, and hit return.

You will be asked if it is OK to synchronize the partition tables. You should answer yes. Now, select the Linux penguin and boot into Ubuntu Linux.

Installing important software

Login to Ubuntu with the username and password you created during installation. Open a Terminal and run the following command, typing your password when asked:

% sudo dpkg-reconfigure debconf

On the first screen select “Dialog” and hit return. Choose the defaults on the next screens.

Now, start up the synaptic package manager (System -> Administration -> Synaptic Package Manager), typing your password if asked.

In your Terminal window, load the wireless module:

% modprobe new_wlan_scan_sta

Then in synaptic, search for “network manager” and install the network-manager daemon package and network-manager-gnome frontend applet package. The next time you login, you will see a small applet icon in the panel. It allows you to select your wireless or wired network.

It should be noted that the wireless drivers for Linux are not as good as the Apple drivers and so it will probably take longer to connect to the wireless router and you will probably see less signal strength under Linux than you do when running Mac OS X.

Now add the following apt sources/channels in synaptic (Settings->Repositories -> Add -> Custom):

deb http://ubuntu.desrt.ca/ ./
deb-src http://ubuntu.desrt.ca/ ./

Click the “Reload” button in the synaptic menubar, then search for “macbook”. Install the macbook-backlight and macbook-backlight-hal packages. These packages allow you to change the display brightness. Run the power management preferences dialog (System->Preferences->Power Management) and you can change the display brightness based on whether you are running on AC or battery.

You can also use the command-line program macbook-backlight if you make it setuid root:

% sudo chmod u+s /usr/bin/macbook-backlight

If you are interested in having sleep work, you will also want to install the laptop-mode-tools package if it is not already installed. Once installed we will need to make some small modifications. Due to an init script order error, the /usr/sbin/laptop-detect script will not detect that we are on a laptop. A quick fix for this is to edit the script and place ‘exit 0’ on the second line. This will make laptop-detect always report that we are on a laptop (which is the case here).

Another is to modify the ACPI configuration in /etc/default/acpi-support. Here you should uncomment the ACPI_SLEEP=true line (first configuration variable in the file). Then set ENABLE_LAPTOP_MODE=true (last configuration variable in the file).

Now reboot and you should have a working Ubuntu Linux installation to go with your Mac OS X.

One last thing to note is that Linux will often produce a kernel panic during boot. This is due to an APIC timing problem. If you reboot, normally the timing problem goes away (you may have to reboot more than once). A more permanent solution is to recompile the kernel to use a timing frequency of 1000Hz instead of 250Hz, but I will leave the details of that process as an exercise for the reader (hint: comment #152 on this page has some pointers).

From here, there a countless things you can do with your new Linux system, but I’ll leave that up to you. If you have problems with Ubuntu, their forums are a good place to start looking for help.

Again, thanks to the following two sites as they formed the basis of the information found in this post.

Posted in  | Tags ,  | 72 comments