HowTo: Boot Linux from an external USB drive using Mac Mini

Since my laptop is under repair I've tried to boot its operating system (Fedora 13) from a Mac Mini. I've bought a cheap external USB-Case for 2,5"-SATA-Drives from LogiLink, removed the drive from my Acer Aspire 1810T (beware of the glued foil and cable!), put it into the case and attached both USB cables to the laptop. And voilà, it works! Linux starts without any problems, as if the drive had never been anywhere else but in an external USB connector. So I've hopefully attached it to the Mac Mini. And this is the story how Apple stoles me a whole day of my life.

Even while I would like to tell you the whole story I think it would be a very boring article. So I'll just tell you what you have to do if you want to boot Linux from an external USB device.

First part, prepare the Mac. In OSX download and install rEFIt, an EFI boot menu. Take care that you customize the installation type during setup (german: "Installationstyp > Anpassen", I don't know how these steps are labeled in english) and select "File System Drivers" to get access to ext2, ext3 and ReiserFS partitions. After the second reboot you should see a boot menu with entries for OS-X, Windows (if installed) and, if your USB-Drive is already connected, an entry to boot Linux from it. If today is your lucky day this will work and you could stop reading now. But supposably something like this happens:

Choosing Linux in the menu boots Windows!

rEFIt's FAQ provides no real solution for this. It looks like Apple just don't want you to boot a native (MBR) bootloader from USB, as booting the same loader from the internal harddisk or from a bootable cdrom seems to work without any problems. So, let's modify the linux system to make it will be bootable by rEFIt by installing an EFI-enabled version of Grub2.

Boot the linux drive from another system. If you don't have one you can use a rescue system like grml, it will be listed in the rEFIt loader - and even bootable (wtf?). I recommend to take the latest grml64-medium, but ensure that you are downloading the same architecture as the linux system on the usb drive. Mount your root partition, chdir into its directory and execute "mount -o bind /dev dev; mount -t proc none proc; chroot . bin/bash". Then mount other required devices like /boot or /home.

After you've booted (or chroot'ed) into your system you have to install grub2 with EFI support. Most likely your distribution's package is compiled without it, so download the current release from ftp://alpha.gnu.org/gnu/grub/ (1.98 at the time of writing), untar and compile it. You can do this as a normal user. Please don't run "make install" if you don't know for sure what you are doing.

$ wget ftp://alpha.gnu.org/gnu/grub/grub-1.98.tar.gz
$ tar xvzf grub-1.98.tar.gz
$ cd grub-1.98
$ ./configure --with-platform=efi --target=x86_64
$ make
$ ./grub-mkimage -d . -o grub.efi normal sh chain boot configfile \
  reboot cat lspci ls datetime loadenv search help efi_uga fixvideo \
  font minicmd fat ext2 linux part_msdos part_gpt hfsplus appleldr
$ sudo mkdir -p /boot/EFI/grub2
$ sudo cp grub.efi *.mod *.lst /boot/EFI/grub2

This example supposes that the /boot directory is on it's own partition. If it isn't please use "/EFI/grub2" instead of "/boot/EFI/grub2". And if you want this to work don't name it anything else than EFI, not "efi" nor "Efi", since rEFIt is scanning for this directory.

A short note to the "./grub-mkimage"-command: The grub.efi file should contain all modules that have to be avaible in the very first step. In most cases "help", "search", "minicmd", etc can be loaded at runtime using "insmod". But if something goes wrong you will be happy to have these modules in the core image. If you don't want to put grub on an OS-X device it should be safe to remove 'part_gpt hfsplus appleldr' from the command line, but I haven't tried.

Now you have to create the configuration file at /boot/EFI/grub2/grub.cfg. If you're already using grub2 you can copy or symlink your existing config. Here's an example that should be bootable on any system. Of course you have to change the filenames of "vmlinuz" and "initramfs" to the ones on your system. If /boot isn't on it's own partition prepend "/boot" to the paths. Replace BOOT_PARTITION_UUID and ROOT_PARTITION_UUID with the values valid for your system. "ls -l /dev/disk/by-uuid/" shows the current mappings. Note that these values will change if you reformat these partitions.

set default="0"
set timeout=5
set root='(hd1,1)' 
search --no-floppy --fs-uuid --set BOOT_PARTITION_UUID

menuentry "GNU/Linux" --class gnu-linux --class gnu --class os {
    set gfxpayload=keep
    set root='(hd1,1)'
    search --no-floppy --fs-uuid --set BOOT_PARTITION_UUID
    echo    Loading Linux ...
    linux   /vmlinuz-2.6.34.6-54.fc13.x86_64 root=UUID=ROOT_PARTITION_UUID ro quiet rhgb 
    echo    Loading initial ramdisk ...
    initrd  /initramfs-2.6.34.6-54.fc13.x86_64.img
}

If you want to use the same settings for EFI and PC version of grub2 (the one shipped with your distribution) you can create a symlink: "cd /boot/grub2 && symlink -s ../EFI/grub2/grub.cfg" or vice versa.

Finally, I had to do some driver modifications. Put the following line into "/etc/modprobe.d/macmini.conf" for audio support:

options snd-hda-intel model=mb31

And replace the nouveau driver by the proprietary one. On Fedora 13 this is done by the following commands:

$ sudo yum remove xorg-x11-drv-nouveau
$ sudo yum install kmod-nvidia

You can append "rdblacklist=nouveau" to the kernel's command line, but ensure that X isn't started as it might try to replace the VESA driver with nouveau.

By the way: Steve, I hate you.

Comments

May I ask you a question?! You said that you installed linux on external hard drive. And when you was installing a base system (Mount your root partition, chdir into its directory and execute "mount -o bind /dev dev; mount -t proc none proc; chroot . bin/bash". Then mount other required devices like /boot or /home.) you mount a "/boot" directory that haven't for default folder "EFI", you created it like "grub2" folder in "/boot" or you mount something?!
And then you created a grub.cfg where you did this: "set root='(hd1,1)'" - do you mean the second drive, second part, like /dev/sdb2 - what is in this partition (/boot, /root, or what)?!