Installing Gentoo on my MacBook
This is a short overview of the steps I undertook to get a nice
Gentoo installation on my brand new MacBook.
It’s far from complete — not even spell-checked — but could be
useful anyway. :-) Please don’t hesitate to
href="mailto:bart@inGen.be">contact me with your suggestions,
questions or remarks!
Prerequisites
- Get a MacBook. I got myself a black one with 2Gb of RAM, a
dutch QWERTY keyboard and 80G of hard disk. I deliberately chose
for a MacBook and not a MacBook Pro, because the INTEL video
chipset in the MacBook has better free drivers than the ATI video
chipset in the MacBook Pro. - Get a Gentoo installation CD. A minimal one will suffice if you
have a connection to the internet available. - Inform yourself: a good resource for more information about
what I’m about to write can be found at the excellent Gentoo documentation wiki on this subject. A good deal of help
can also be found at #mactel-linux on irc.oftc.net. - Install Boot Camp for legacy BIOS emulation (needed for a correct video card
detection by X.org) and easy repartitioning of the harddisk. - Install rEFIt, a
nice EFI boot loader. - Repartition your hard disk. Just make the OSX partition as
small as possible and leave the rest unchanged. You can partition
it later on.
Installation
- This should be the last time you see your OSX again. :-) But
don’t worry. Your installation will remain untouched during the
following process. - I hope you are familiar with Gentoo installation. Get the great
handbook for x86 and enjoy the ride… At a few points I’ll interfere
with MacBook specific hints.
Where the Gentoo handbook can use some help
2.c. Download, Burn and Boot a Gentoo Installation CD
Don’t bother about wirefree internet for now. Just plug in a
cable and enjoy the Gigabit connection with the sky2 module
4.b. Designing a Partitioning Scheme
You are limited to 4 partitions. 2 are already taken by your OSX
installation, so 2 remain to be used for your favourite OS.
The handbook gives the (good) advice for partitiong your disk
into /, /boot, /home and
swap. This is not possible now, and I chose for the
following scheme:
Output generated by fdisk
Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 1 26 204819+ ee EFI GPT Partition 1 does not end on cylinder boundary. /dev/sda2 26 3812 30408704 af Unknown /dev/sda3 3812 7216 27342630 83 Linux /dev/sda4 * 7216 9729 20192038+ 83 Linux
Contents of /etc/fstab
/dev/sda3 /home ext3 noatime,user_xattr,data=writeback 0 2 /dev/sda4 / ext3 noatime 0 1 /swapfile none swap sw 0 0 /dev/hda /mnt/cdrom iso9660 user,noauto,ro 0 0 proc /proc proc defaults 0 0 shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
Output generated by df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda4 19G 14G 4.4G 76% / udev 998M 268K 998M 1% /dev /dev/sda3 26G 1.6G 23G 7% /home shm 998M 0 998M 0% /dev/shm
As you probably noticed, I have a swapfile and no swap
partition. With 2Gb RAM you hardly ever swap a page out anyway. :-)
Create it as follows:
Creation of a 2G swapfile
dd if=/dev/zero of=/mnt/gentoo/swapfile bs=1024 count=2097152 mkswap /mnt/gentoo/swapfile swapon /mnt/gentoo/swapfile
5.e. Configuring the Compile Options
A short overview of the fine fine fine MacBook hardware:
- The Intel Core Duo processor is from the Prescott family
- The display controller is an “Intel Corporation Mobile
945GM/GMS/940GML Express Integrated Graphics Controller” - The audio device is an “Intel Corporation 82801G (ICH7 Family)
High Definition Audio Controller”
Some entries from
/etc/make.conf
CHOST="i686-pc-linux-gnu"
CFLAGS="-O2 -march=prescott -fomit-frame-pointer -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j4"
VIDEO_CARDS="i810 vesa"
SOUND_CARDS="hda-intel"
INPUT_DEVICES="keyboard mouse joystick evdev"
7.b. Installing the Sources
It is advised to start your adventure with a Vanilla kernel and
not with a Gentoo kernel. Additionally, at the time of writing (the
latest stable version of the Linux kernel is 2.6.18), you’ll need
to apply some kernel patches too. Let’s see how this goes.
Patch your vanilla kernel for the
MacBook
# emerge subversion # cd /usr/src # svn co https://svn.sourceforge.net/svnroot/mactel-linux/trunk/kernel/mactel-patches-2.6.18 mactel-patches-2.6.18 # cd mactel-patches-2.6.18 (remove 'efi_e820_all_mapped_fix.patch', 'version.patch' and 'sigmatel_audio.patch') # ./apply /usr/src/linux
7.c. Default: Manual Configuration
There are some kernel configuration options you need to handle
with care. For reference you can download my
href="http://bbbart.eu/blog/wp-content/uploads/2009/08/config-macbook-bbb">fully working, not-too-bloaty kernel config.
If you use this kernel configuration, don’t forget to (auto)load
the following modules:
- uhci_hcd
- evdev
- appletouch
- usbhid
- mousedev
At least make sure to have the following:
- CONFIG_SCSI_ATA_PIIX=y or your kernel won’t be able to find
your hard disk - CONFIG_VM86=y or X.org won’t be able to initialize your video
card via BIOS (read: no X and a lot of headache wondering why) - CONFIG_FB_INTEL=y for the framebuffer to work at vga=792
(1024×786) - CONFIG_SKY2=y for the built-in gigabit network interface to
work - CONFIG_X86_SPEEDSTEP_CENTRINO=y for frequency scaling to
work
8.a. Filesystem Information
Because we have a swapfile instead of a swap partition, make
sure to tell your system so through /etc/fstab. Simply
replace the swap partition with your swapfile in the first
column.
10.b. Default: Using GRUB
Make sure you emerge >=grub-0.97-r3. My
/boot/grub/grub.conf looks like follows:
My /boot/grub/grub.conf
timeout 10 default 0 fallback 1 title GNU/Linux Vanilla 2.6.18-mactel-bbb *SPLASH* root (hd0,3) kernel /boot/bzImage-2.6.18-mactel-bbb root=/dev/sda4 vga=792 splash=silent,theme:gentoo console=tty1 initrd /boot/initrd-fbsplash title GNU/Linux Vanilla 2.6.18-mactel-bbb root (hd0,3) kernel /boot/bzImage-2.6.18-mactel-bbb root=/dev/sda4
Also make sure to grub-install grub on your
/ or /boot partition — in this case that
would be /dev/sda4 — and that that partition is marked
bootable.
Configuration
Now the fun part can begin: getting all the hardware you paid
for to work perfectly. :-)
Some useful information
First let me post some useful information, like href="http://bbbart.eu/blog/wp-content/uploads/2009/08/dmesg">dmesg, lspci, href="http://bbbart.eu/blog/wp-content/uploads/2009/08/lsusb">lsusb, lshal, href="http://bbbart.eu/blog/wp-content/uploads/2009/08/lsdev">lsdev and cpuinfo.
The hardware
Now let’s go through the hardware and see what we can get to
work:
Networking
Gigabit networking over the cable works like a charm with the
sky2 module, included in the kernel.
Wireless networking works fine as well with the
madwifi, which you can find in portage in the
madwifi-ng ebuild. Make sure to enable the
onoe USE-flag.
X
I just enabled AIGLX and it is lovely. I’m already addicted to
it. You’ll need to unmask some packages for X.org to get to work on
your MacBook though.
First of all you need modular X 7.1:
Extract from my
/etc/portage/package.keywords
# Modular X 7.1 <=x11-base/xorg-x11-7.1 <x11-base/xorg-server-1.2 <x11-drivers/xf86-input-evdev-1.2 <x11-drivers/xf86-input-mouse-1.2 <x11-drivers/xf86-input-keyboard-1.2 <x11-drivers/xf86-input-joystick-1.2 <=x11-proto/glproto-1.4.8 <=media-libs/mesa-6.5.1-r1 <=x11-drivers/xf86-video-vesa-1.2.0 <=x11-drivers/xf86-video-i810-1.6.0 <=x11-apps/mesa-progs-6.5
Then you’ll have to patch your video BIOS with the 1280×800 mode
with
href="http://www.geocities.com/stomljen/">915resolution:
Extract from my
/etc/portage/package.keywords
<=sys-apps/915resolution-0.5.2
My
/etc/conf.d/915resolution
replace=( "5c 1280 800" ) log="/var/log/915resolution"
At this point you should be able to get your X up and
running.
Now let’s go on the next level:
href="http://gentoo-wiki.com/HOWTO_AIGLX">AIGLX. First, add the
following to your X configuration:
Extract from
/etc/X11/xorg.conf
Section "DRI"
Group 0
Mode 0666
EndSection
Section "ServerFlags"
Option "AIGLX" "true"
EndSection
Section "Extensions"
Option "Composite" "Enable"
EndSection
Section "Device"
Option "DRI" "true"
EndSection
Section "Screen"
Option "XAANoOffscreenPixmaps" "true"
EndSection
Also make sure you don’t load the Mesa GLcore
module. Now you’ll need a compositing window manager. Metacity will
have this functionality from 2.16 on, but today we’ll use
href="http://en.opensuse.org/Compiz">Compiz.
Extract from my
/etc/portage/package.keywords
# AIGLX <=x11-wm/compiz-0.2.0 <=media-libs/glitz-0.5.6
Emerge it and then run compiz-aiglx form the
command line. Tzadaaam!
Keyboard
I have a Dutch QWERTY keyboard, but except for the key to the
left of the !/1 it is — as far as I know — identical to an
international QWERTY. Anyway, I just load the us keymap (both in
console and in X) and that works for all other keys. I also found
it useful to change the behaviour of Shift Lock to
Compose Key. Who ever needs Shift Lock
anyway?
The special keys at the top row (brightness, volume, num lock
and eject) work out of the box in X.org. In gnome 2.14 I could just
assign them to their respective actions in Desktop > Preferences
> Keyboard Shortcuts. I didn’t do anything to enable backlight
brightness control yet. To eject a CD in console, emerge and use
sys-apps/eject.
Probably you also want the Fn to behave like a
normal Shift or Control key. This is
easily achieved by changing the value of
/sys/module/usbhid/parameters/pb_fnmode:
Extract from my
/etc/conf.d/local.start
# have Fn react like the shift button echo "Teaching \`\`Fn'' how to behave" echo -n "0x02" > /sys/module/usbhid/parameters/pb_fnmode
Here’s my complete xorg.conf.
Touchpad
In console (gpm)
Just emerge gpm and use the following settings:
My /etc/conf.d/gpm
MOUSE=ps2 MOUSEDEV=/dev/input/mice APPEND="-l \"a-zA-Z0-9_.:~/\300-\326\330-\366\370-\377\" -g 1 -A60 -a 6 -d 5 -2"
This works very fine for me.
In X (synaptics)
The touchpad is recognised as synaptics hardware, so that makes
things easy. Make sure you have the following modules loaded or
compiled into your kernel: uhci_hcd,
evdev, appletouch, usbhid,
mousedev. Then, include the following part in your X
configuration:
Extract from my
/etc/X11/xorg.conf
Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ExplorerPS/2"
Option "ZAxisMapping" "4 5"
EndSection
Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "Device" "/dev/input/mouse1"
Option "Protocol" "auto-dev"
Option "LeftEdge" "100"
Option "RightEdge" "1120"
Option "TopEdge" "50"
Option "BottomEdge" "310"
Option "FingerLow" "25"
Option "FingerHigh" "30"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "MaxDoubleTapTime" "180"
Option "VertScrollDelta" "20"
Option "HorizScrollDelta" "50"
Option "MinSpeed" "0.79"
Option "MaxSpeed" "0.88"
Option "AccelFactor" "0.0015"
Option "SHMConfig" "on"
EndSection
Section "Module"
Load "synaptics"
EndSection
Section "ServerLayout"
InputDevice "Configured Mouse" "CorePointer"
InputDevice "Synaptics Touchpad" "AlwaysCore"
EndSection
Tap-to-click, horizontal and vertical scrolling all work with no
problems.
I assume you’re also interested in getting a middle and a right
mouse button. For that, I use the — otherwise completely unuseful —
apple keys. Try the following:
Extract from my
/etc/conf.d/local.start
# emulating middle and right click echo "Enabling middle- and rightclick" echo 1 > /proc/sys/dev/mac_hid/mouse_button_emulation echo 125 > /proc/sys/dev/mac_hid/mouse_button2_keycode # 125 = left apple echo 126 > /proc/sys/dev/mac_hid/mouse_button3_keycode # 126 = right apple
Sound
First of all: forget about oss, move on to
alsa. The hardware in your MacBook is managed
perfectly by the hda-intel module. You can use the
version included in the kernel, but there are some problems
reported with them. I use the
media-sound/alsa-driver-1.0.13 ebuild from portage.
This works fine.