Linux on a MacBook – fedora 16

Since version 16 uses fedora grub2 which supports EFI, MacBooks should theoretically boot Fedora directly without using rEFIt. Some older models of Apple Laptops require a little workaround though.
On fedora64.org Jason Montleon is describing how this can work. I’m going to describe as a “copy-paste-tutorial” how I installed Fedora 16 on my 5 year old MacBook using that directions.

This is a post from my old blog http://tech.cbjck.de. It has been moved here and slightly edited for better readability. It's also been adjusted to the new layout.
The content however is old and might be outdated.


This post describes an single-boot installation. If you want to install OS X and Linux as a dual boot installation this should work quite similiar. You just have to create a partition of suitable size using OS X and pay attention not to delete OS X during linux setup.

The problem

The first MacBooks with DualCore-processors are using a 32-bit EFI instead of a 32-bit EFI (and boot the 32-bit kernel under OS X by default). The 64-bit fedora install media present a 64-bit EFI-Image that can’t be booted on early Macs. The workaround requires 4 steps:

  1. prepare boot medium
  2. install
  3. configure bootloader
  4. setup EFI

Step 1: prepare boot medium

A a solution for the EFI boot problem, we create a install medium which presents a 32-bit as well as a 64-bit EFI image and is able to boot on all 64-bit macs. To do this we will need a running system with fedora 16 (x86_64), eg in a VirtualBox and a usb-drive.

Install grub2-efi.x86_64:

yum install grub2-efi.x86_64

In an empty directory we create the 64-bit EFI image:

grub2-mkimage -d /usr/lib/grub2-efi/x86_64-efi/ 
-o BOOTX64.efi -O x86_64-efi 
--prefix /efi/boot part_gpt part_msdos lvm fat ext2 
chain boot configfile normal minicmd linux reboot halt 
search gfxterm gfxmenu efi_gop efi_uga video 
loadbios gzio video_bochs  video_cirrus echo true loadenv

On the usb-drive we create the folder EFI/BOOT and copy the created file BOOTX64.efi to that folder:

mkdir /media/Unknown/EFI
mkdir /media/Unknown/EFI/BOOT
cp BOOTX64.efi /media/Unknown/EFI/BOOT/BOOTX64.efi

As we can’t install the 32-bit edition grub2efi along with the 64-bit edition, we download the package to our folder:

wget http://ftp.uni-kl.de/pub/linux/fedora/linux/releases/16/
Fedora/i386/os/Packages/grub2-1.99-12.fc16.i686.rpm

Of course you can use any other mirror and maybe there is a newer release available so you might have to change the URI.

Now we convert the .rpm-package to a cpio-archive and unpack:

rpm2cpio grub2-efi*i686.rpm > grub2-efi.i686.cpio
 cpio -id < grub2-efi.

Instead of installing the package we simply copy the one file we need to ist correct place:

cp -r usr/lib/grub2-efi/i386-efi /usr/lib/grub2-efi

Then we create the 32-bit EFI image:

grub2-mkimage -d /usr/lib/grub2-efi/i386-efi -o BOOTIA32.efi
 -O i386-efi --prefix /efi/boot part_gpt part_msdos lvm fat 
ext2 chain boot configfile normal minicmd linux reboot halt 
search gfxterm gfxmenu efi_gop efi_uga video loadbios gzio 
video_bochs video_cirrus echo true loadenv

This image we copy to the usb-drive as well:

cp BOOTIA32.efi /media/Untitled/EFI/BOOT/BOOTIA32.efi

On the usb-drive we create under EFI/BOOT a file grub.cfg with the following content:

set timeout=30
set default=0

 menuentry "Fedora 16-Alpha askmethod" {
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz askmethod
 initrd /images/pxeboot/initrd.img
}

menuentry "Fedora 16-Alpha fakebios askmethod" {
 fakebios
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz askmethod
 initrd /images/pxeboot/initrd.img
}

menuentry "Fedora 16-Alpha MacBook fakebios, askmethod, 
nomodeset" {
 fakebios
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz nomodeset askmethod
 initrd /images/pxeboot/initrd.img
}

menuentry "Fedora 16-Alpha MacBook fakebios, askmethod, 
nomodeset, and VNC" {
 fakebios
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz nomodeset vnc askmethod
 initrd /images/pxeboot/initrd.img
}

menuentry "Fedora 16-Alpha rescue" {
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz rescue
 initrd /images/pxeboot/initrd.img
}

menuentry "Fedora 16-Alpha fakebios rescue" {
 fakebios
 search --set -f /images/pxeboot/vmlinuz
 linux /images/pxeboot/vmlinuz rescue
 initrd /images/pxeboot/initrd.img
}

Finally we copy the pxeboot images from a Fedora install media to images on the usb-drive:

cp -R /media/fedora-cd/images/pxeboot/ /media/Untitled/images/

Probably you will have to adjust the paths, so that /media/fedora-cd refers to your install media an d /media/Untitled to your usb-drive.
On the usb-drive we now should have the files vmlinuz and initrd.img under images/pxeboot.

Step 2: installation

On the MacBook we now boot from the usb-drive holding the alt-key on startup and selecting the usb-drive. It should be named “EFI-Boot”.
After a while the fedora installer Anaconda will start. We follow the install routine and choose an online repository as install source when asked for. For example use
http://ftp.uni-kl.de/pub/linux/fedora/linux/releases/16/Fedora/x86_64/os/
ort any other mirror. Probably a mirror close to you will allow a faster download.
When it comes to partioning, we change the proposed scheme. The 500 MB ext4 partition for /boot/ we change to a vfat partition for /boot/efi. Of course there can be another partition for /boot/. Anyways /boot/efi has to be on a vfat-formatted partiton with at least 200 MB of space. I assume / being located under /dev/mapper/lv_root, so you may have to change the paths given below.
We continue the installation as proposed by Anaconda, but don’t reboot.

Step 3: configuring the bootloader

Before restarting, we have to configure grub2. With Alt+F2 we change to a console and chroot to the just installed system:

chroot /mnt/sysimage

If you already rebooted, start up in the rescue mode and gain access to a console.
Now we mount the usb-drive under /mnt

<pre>mount /dev/sdb1 /mnt

Maybe your usb-drive will be shown as another device.
Then we copy the EFI images and the grub.cfg to /boot/efi/EFI/BOOT/

mkdir /boot/efi/EFI
mkdir /boot/efi/EFI/BOOT
cp -R /mnt/EFI/BOOT /boot/efi/EFI/BOOT/

and replace the content of grub.cfg with the following:

nano /boot/efi/EFI/BOOT/grub.cfg
set timeout=5
set default=0
set root=(lv_root)
menuentry "Fedora 16 (3.1.2-1.fc16.x86_64)" {
    fakebios
    linux /boot/vmlinuz-3.1.2-1..fc16.x86_64 
 root=/dev/mapper/lv_root ro
    initrd /boot/initramfs-3.1.2-1.fc16.x86_64.img
}

You will have to adjust the filenames to your version of the kernel, depending on your setup maybe the paths too.
To ensure that kernel updates will be refelcted in the file, we link it to /etc/grub2-efi.cfg, where the installer will expect it to be.

ln -s /boot/efi/EFI/BOOT/grub.cfg /etc/grub2-efi.cfg

Some MacBooks start with a dead keyboard. To fix this, we edit the file /etc/grub.d/10-linux

nano /etc/grub.d/10-linux

and the following past line 77:

cat >> EOF
fakebios
EOF

Important:It is probably not a very good idea to edit this file as it might be overridden by updates of grub2. So we should have a look here, when grub2 is being updated.

Now we leave the chroot-environment and reboot:

exit
reboot

Step 4: setup EFI

Pressing the alt-key on startup, the harddrive should be offered as “EFI-Boot”, just starting without alt-key will lead you to the “sad folder”.
To change this and boot fedora 16 by default, we use an OS X DVD, boot and start a Terminal from “utilities” in the menu bar.
First we check, wether /boot/efi has been mounted correctly, probably as /Volumes/Untitled

ls /Volumes

If necessary we mount the EFI partition manually:

mkdir /Volumes/Untitled
mount -t msdos /dev/disk0s1 /Volumes/Untitled

Using

ioreg -l -p IODeviceTree | grep firmware-abi

We check wether the computer is runnnig an EFI32 or an EFI64.
Depending on the result we then run

bless --mount /Volumes/Untitled --setBoot --file 
/Volumes/Untitled/EFI/BOOT/BOOTIA32.efi

or

bless --mount /Volumes/Untitled --setBoot --file 
/Volumes/Untitled/EFI/BOOT/BOOTX64.efi

On the next reboot fedora should start directly.

Leave a Reply

Your email address will not be published. Required fields are marked *