How to boot Ubuntu on a mac from external USB storage?

Well, I spent a second whole day on it and now I've cracked it.

I sincerely hope some other poor soul gets some value out of this.

Here's a recipe that works (at least, on my iMac with Ubuntu 14.04):

  • Boot with bootable USB, install Ubuntu
  • Partition your USB as follows:
    • 200MB EFI boot partition
    • 200MB ext2, mount to /boot
    • Swap space if you want it
    • One or more other partitions to hold Ubuntu proper (e. g. ext4 on /)
  • Complete the install, reboot to OS X
  • Get gdisk (pkg installer for OS X) and rEFInd binaries
  • execute "diskutil list" from the console and note the device name, and the EFI partition (e. g. /dev/disk3, /dev/disk3s1)
  • Follow the gdisk recipe at http://www.rodsbooks.com/ubuntu-efi/ under "Fixing the installation" point 6
  • Install rEFInd on your USB's EFI partition. From the refind directory:

    ./refind-install -–usedefault /dev/disk3s1
    

    (you can drag the file into command prompt to get full path)

Then when you reboot, you can "EFI Boot" to rEFInd, and there should be an option to boot GRUB/linux.

I have documented this in more detail here: http://coljac.net/2014/stuff/installing-ubuntu-onto-a-bootable-usb-stick-or-other-device-on-a-mac/


If you prefer not to change your Mac's default boot loader and have your USB key bootable from any Mac here is the solution I found:

  • start the Ubuntu live version by selecting "Try Ubuntu without installing"
  • prevent any bootloader installation by starting the installer via the ubiquity --no-bootloader command via Terminal
  • erase and install Ubuntu on your destination USB drive
  • restart your Mac and start the grub command line using the Ubuntu live USB and pressing 'c' when the GRUB bootloader shows up
  • perform a manual boot of the installed Ubuntu system
  • fix the EFI partition:

    • install required packages:

      $ sudo apt-get update
      $ sudo apt-get install mactel-boot hfsprogs gdisk grub-efi-amd64
      
    • use gdisk and mkfs.hfsplus to replace the existing partition with an Apple HFS/HFS+ one

    • replace the existing entry UUID=... /boot/efi vfat defaults 0 1 in your /etc/fstab file with UUID=<your usb EFI partition uuid> /boot/efi auto defaults 0 0
    • run sudo mount /boot/efi
    • create the required directories and files:

      $ sudo mkdir -p "/boot/efi/EFI/$(lsb_release -ds)/"
      $ sudo bash -c 'echo "This file is required for booting" > "/boot/efi/EFI/$(lsb_release -ds)/mach_kernel"'
      $ sudo bash -c 'echo "This file is required for booting" > /boot/efi/mach_kernel'
      
    • install GRUB:

      $ sudo grub-install --target x86_64-efi --boot-directory=/boot --efi-directory=/boot/efi --bootloader-id="$(lsb_release -ds)"
      
    • bless the bootloader code:

      $ sudo hfs-bless "/boot/efi/EFI/$(lsb_release -ds)/System/Library/CoreServices/boot.efi"
      
    • create the GRUB configuration:

      $ sudo sed -i 's/GRUB_HIDDEN/#GRUB_HIDDEN/g' /etc/default/grub
      $ sudo sed -i 's/GRUB_TIMEOUT=10/GRUB_TIMEOUT=0.1/' /etc/default/grub
      $ sudo grub-mkconfig -o /boot/grub/grub.cfg
      

The system is now bootable from any Mac by simply pressing and holding the "Option" key at startup.

Image of the Mac boot menu with Ubuntu entry

I detailed the instructions here: Ubuntu installation on USB stick with pure EFI boot (Mac compatible)


I skipped the whole gdisk thing as mentioned in the solution. This alone worked for me

./refind-install -–usedefault /dev/<EFI-disk-of-external-storage-where-ubuntu-is-installed>

Tags:

Usb

Boot

Uefi

Mac