Install Linux to and Boot from a USB Drive on Your MacBook

I, like millions of others, use Mac OS X as my main operating system. It’s fast, reliable and secure, and the computers it runs on are undeniably the best designed and built machines available on the market. There are many options available to users who need the added flexibility of running Linux or Windows alongside OS X, perhaps through SSH or by using a Virtual Machine. Sometimes, though, you need a full, non-virtualised OS environment to work in, and while Boot Camp is great it’s not ideal for someone like me who rolls with a very fast, but very small, SSD boot drive.

In this tutorial, I’ll show you how to install Linux to any external USB device and boot your Apple computer from it. I’ll be working with Ubuntu 11.04 32-bit and a MacBook Pro running Mac OS X 10.6 Snow Leopard. Guides elsewhere online seem to only help you if you happen to already have a Linux box to work with – my tutorial only requires one Macintosh computer. All the software used herein is open source and free of charge.

Ingredients

  • A Macintosh computer with an Intel CPU
  • Oracle Virtualbox (available for download here)
  • Ubuntu Linux (here)
  • USB storage device
  • rEFIt Bootloader (here)

Before beginning this process, you should make sure you have all the appropriate tools to hand. There are a couple of restrictions you should be aware of when assembling this kit:

  • While using 64-bit Linux is technically possible, I used a 32-bit ISO to minimise any compatibility issues.
  • Your storage device can be of any type – as long as it’s USB and >=4GB in size you can use it. Bear in mind that the device you choose will be wiped as part of this process.

Step 1: Prepare the USB Device in OS X

The USB storage device needs to be blanked in preparation for Linux installation. To do this, first plug the drive into your Mac and open Disk Utility. Select the relevant disk in the left hand column and press the ‘Partition’ tab. The disk needs to be partitioned as per the screenshot below – a single partition of free space. Select ‘1 Partition’ and ‘Free Space’ from the dropdown menus. Before applying the changes, click the ‘Options’ button and select ‘Master Boot Record’. Now press apply.

Once the partitioning process has completed, you need to eject the disk. Right click it in the left hand column and press eject – but leave it plugged in. We just need Mac OS X to remove its hooks from the drive so we can use it elsewhere later.

Step 2: Create a VirtualBox VM

If you haven’t already, install VirtualBox onto your Macintosh host system and launch it. We need to create a virtual machine from which we can install Linux to the external device.

Press ‘New’ and name your VM ‘Ubuntu’ (VBox should automatically select Linux/Ubuntu from the ‘OS Type’ fields). The virtual machine needs to have a boot hard drive of size 5GB and 512MB of RAM. We’re not actually going to use the hard drive, but it needs to be present to satisfy the installer later on if you’re using a relatively small USB device.

 

Step 3: Boot to Ubuntu

Once the VM has been specified, fire it up with the ‘Start’ button. VBox will ask you to select an OS disc – in this dialog, navigate to and select the Ubuntu ISO image you downloaded earlier.

Next, we need to attach the USB device to the virtual machine. Double click on the USB icon (third from the left) in the bottom right hand corner of the VBox window and select your USB drive from the list to attach it (‘SMI Corporation USB DISK’ in the example below).

Step 4: Install Ubuntu

When Ubuntu boots, it will ask you whether you want to try or install the OS. We’re ready to install, so select that option.

When the installer launches, instruct it to erase the target disk and install Ubuntu. Strangely, you’re asked first if you want to erase the target media before actually specifying which disk you want to install to: this option is on the next screen. If you followed the steps so far correctly, you’ll have two options in the target dropdown – the first will be the 5GB VBox hard drive, and the second will be your USB device. Select the USB device from this menu.

This is all the information the installer needs to get started. It will ask you some questions about usernames and passwords while loading the files onto your drive, but from here on in it’s a standard Ubuntu install. If you selected that you wanted updates as part of the installation process, you might find that the last stage of the installer takes a very long time – when you’re offered a ‘Skip’ button, it’s perfectly safe to use it. With a bit of luck and a fair wind you’ll be greeted with a success screen after half an hour or so.

 

Don’t click the ‘Restart Now’ button – instead, just power off the VM.

Step 5: Install rEFIt

rEFIt is an open-source ‘boot menu and toolkit’ which gives you more choices for booting your EFI-equipped Macintosh. If you haven’t downloaded it already, do so now.

When the download is complete, mount the rEFIt .dmg and double click on the installer (‘rEFIt.mpkg’).

The default installation path for rEFIt is ‘/efi’ – the following assumes that you’ve kept that path.

To enable rEFIt on your machine, open up a Terminal window and enter:

sudo sh /efi/refit/enable.sh

rEFIt installation is now complete, so make sure your USB disk is inserted and reboot the machine.

Step 6: Boot from USB

If all has gone to plan, you should be greeted by the rEFIt boot screen. The available boot options are listed as icons on the screen, and you can navigate using the keyboard. You’ll have an Apple logo, representing the OS X install on your main boot drive, and also a picture of Tux, which relates to the Linux install on your USB disk. Select Tux from this list, and Ubuntu will commence to load. (Occasionally your USB device won’t be detected first time – just select ‘restart’ in rEFIt and it will be detected when the computer restarts).

And that concludes this tutorial! Of course, you’ll need to obtain drivers etc… for your particular Mac in order to get full functionality, but you machine is now equipped to boot a real instance of Linux from your USB drive. There are some great tools out there, like rEFIt, which are so useful for simplifying hacks like this one, and my hat absolutely goes off to the minds behind rEFIt, VirtualBox and, of course, Ubuntu who write superb software and give it away online to any tinkerer who wants to give this kind of thing a go. Enjoy!

34 Responses to “Install Linux to and Boot from a USB Drive on Your MacBook”

  1. […] Linux made its way onto my 13″ MacBook Pro this week via external storage. While installing, I was armed with just the laptop itself and a wireless-only internet connection, […]

  2. […] always limited their flexibility, however, is their storage mechanism, the virtual hard disk. In a previous tutorial, I used Oracle’s VirtualBox to install Ubuntu Linux to an external storage device. […]

  3. Andrew says:

    Will this work with white macbook?

  4. Peter says:

    Hey~! I’m trying this with linux MINT, would the boot USB NEED TO BE IN THE COMPUTER ALL THE TIME?
    Or could you install Linux in the sudo linux envioment that is ON the drive to get a full OS on your internal HDD or SDD?

  5. Fernando says:

    Good article.

    In my case, with a Macbook Pro 3.1 and Mac OS X 10.5.8, I have no external USB disk access from the Ubuntu installer application. I will try to use qemu-image to translate the virtualbox image to bin, and then clone it with dd.

    Will it work? I’ll tell you.

  6. D says:

    A solution that actually works! Though setting up a usb device filter is a good idea for the virtual machine then unplugging and replugging the drive once the machine is running.

  7. Sarin says:

    Having a Macbook ver 5.2. Mac OsX Snow Leopard 10.5.8 n Windows 7 running in it.Wanted Ubuntu also in my flash drive for my office.
    Installed everything as per the above instructions.At first i have got the Fatal Error as grub could not be located,but the second attempt made a clean install.BUT now the state of mac is reFit inspite of giving the prompt of Mac,Windows 7 And Tux it boots into Windows 7.
    Pls help me

    • Nick says:

      I had the exact same problem and nothing I would do would fix the problem. I finally figured out what’s going on here. As far as I can figure, when OSX detects a bios style os it just throws it over to it’s own “emulated” bios. The problem is you cannot edit the boot order to make it try to boot from a USB first, and you can’t get to bios settings to change that since it doesn’t really exist. I finally found this windows program called EasyBCD which lets you to edit your boot menu.

      http://neosmart.net/EasyBCD/

      What I did was add a new entry and chose the Plop Boot Manager from the bottom panel. Then once I boot to windows it now gives an option to boot windows or the plop boot manager. Pick USB from the Plop menu, and it works like magic! There may be a better way than this, but if there is I don’t know how.

  8. LTB says:

    I’m running OS 10.5.8 and am trying to boot Ubuntu 12.04 from an external hard drive. The problem I’m running into is the second part of step three where I attach the USB drive. If the disk is ejected, it leaves the “SMI Corporation USB Disk” option in light gray, and doesn’t allow me to select it. If the disk isn’t ejected, the SMI Corporation text is written in black, but the disk is unable to connect. What should I be doing differently? Thanks for your help.

    • Solomon says:

      I have the exact same problem. Ejecting the USB-disk in Diskutility does not help. The USB stick remains grey:ed out in VM and is thus not choosable.

  9. Klaas says:

    hi, thank you for the tutorial!

    however, after following all of your steps and booting from the usb drive in the refit menu, i get a black screen saying: “no bootable device – insert boot disk”
    i have lion on an early 2011 MacBook Pro.

    do you happen to know what could be the problem?

  10. Saadat says:

    What file do we use for virtual disk. There are four options:
    VDI
    VMDK
    VHD
    HDD(parallels)

    • P. Bateman says:

      This is where I think I maybe having issues. Here is what I did:
      -I purchased a white macbook running OS X 10.5 from craigslist.
      -Downloaded EFIt and made sure it was working
      -On my MacBook Pro running 10.8 I prepared an 8 gig thumb drive as described, downloaded virtualbox and then the suggested Ubuntu. (virtualbox would not install on the 10.5 machine)
      -I installed that to the usb drive as described in the tut from my 10.8 machine. All seemed good to go.
      -Put the usb drive in my 10.5 machine then selected Tux from the EFIt menu
      -Then I get “No bootable device — insert boot disk and press any key”

  11. Saadat says:

    Also, the USB Drive doesn’t show up as an install destination. What do i do?

  12. Connor says:

    Can this work with windows 8?

  13. Simon H. says:

    @Andrew: Yes. I don’t know of any Intel-based Mac that doesn’t run. There might be some models with restrictions from Apple that makes it harder to install, but I really can’t see a problem there.
    @Peter: Following this tutorial, your USB-Stick needs to be plugged in when using Linux. You can also install it easily on your HDD/SDD:
    1) Prepare your disk: Open “Disk Utility” under Mac, select your HDD/SDD and resize it so that approx. 20GB of free space is available (have a look for the specs of the linux of your choice. I prefer more, cause it can be a bit fiddling to resize your Linux partition once it’s installed, AND once Linux is installed, you simply want MORE of it!)
    2) Install rEFIt (like described in this article).
    3) Copy the install media on your Pendrive. So basically you download a the iso-file and copy the raw data onto it. You can use the dd-command for that (also in the Mac Terminal): dd if=/path/to/downloaded.iso of=/dev/diskN bs=4k. Here’s a good instruction: http://en.opensuse.org/SDB:Live_USB_stick#OS_X_instructions
    4) Reboot. rEFIt shall boot up with a screen similiar to the one above. But this time you’ve an installer on your flash drive. Select it and go through the the Linux menu. Have a coffee.
    5) Congratulations! You first Linux should be installed. After reboot, rEFIt will show you even another Icon with a penguin and and harddisk. This is your final Linux.
    6) Reformat your pendrive with FAT32 so that you can use it again in everyday work.

    There’s a known issue with Apple firmware that very poorly supports USB. If your having trouble finding your pendrive, burn the iso-file on a CD with Disk Utility. Restart and see if rEFIt finds your drive.

    I hope that helps a bit.

  14. Patrick says:

    Thanks for this instructions, but I have problems to get rEFIt to work. I am on a 10.7.4 MBP (early 2009).
    I found messages that it might require several re-starts to get it running properly but I tried it again and again without success. Any guesses as rEFIt is not developed any further since 2010?

    • Zebedee Pedersen says:

      I still use it on 10.7.4 on a 2009 MBP + a new Mini, works fine. Possibly some sort of permissions error? It’s always ‘just worked’ for me.

  15. Arya says:

    Simon, I tried your suggestion for installing from USB and was told that “The disk you inserted was not readable” after the dd. The installing to USB through VirtualBox is running right now; can I use that same installation if I plug the flash drive into a PC?

  16. Dave says:

    I dont have any mac so I will try this buy booting OSX in a virtual machine and enabling USB and then install Linux to USB drive to boot up on an iMac at work. Fingers crossed!

  17. Pieter-Jan says:

    Can we delete the vm once the installation is done?

    • If you mean the config in Virtual Box, then yes. Unless you would like to access the drive/disk from Mac OS X in the future. If you’re only going to be running Linux directly from the drive (no more virtualbox), then the config can be removed.

  18. Hi Zebedee,

    Like Klaas above, unfortunately I am running into the “no bootable device” problems. No matter what I seem to try, the Mac doesn’t seem to be able to start GRUB.

    My setup:
    * Macbook 2008
    * External USB drive from Freecom
    * USB drive is GPT/GUID partition table
    * USB drive has four parts: EFI (hidden), HFS+ (for refit), swap and /
    * The OS installation (CentOS) goes fine and shows zero problems
    * I have verified that GRUB is installed in /boot by mounting the disk in a VM
    * I have verified that GRUB is in the MBR, by: dd bs=512 count=1 if=/dev/disk4 (in my case)

    Oddly, that MBR/GRUB dd does appear to contain an odd extra error, but I’m not sure if that’s caused by DD or something else.

    Anyway… I’d love to know your thoughts on this.

    On other forums I have read about re-syncing the GPT/MBR in rEFIt, but that doesn’t work for me as the whole lot is on the external USB drive.

    • I have since replace rEFIt with rEFInd, which is a new branch of the rEFIt software. The original is apparently no longer being developed, so rEFInd has added more feature.

      rEFInd -does- manage to find GRUB and to properly identify the desired boot volume. It still fails to boot (this time wiht “unsupported while loading vmslinuz” etc…), but at least I got one step further.

      -> http://www.rodsbooks.com/refind

  19. Stuart Cracraft says:

    I would think you could since the VM was used for install only.

    You’re now bootable off the external.

  20. m4rsh says:

    thanks for this.. been a big help…

    • m4rsh says:

      i only have one issue at the moment, i found the install to be super easy to follow, my main issue is i always get an error when booting from the usb stick.. the error is something to do with the airport card, how do i install the updates?

      i have checked the relevant at the start of install but to no avail.. any help greatly received

      M4rsh

  21. kw says:

    Thanks for your post. What a pain and how philosophically “unclean” it is to have to install rEFlt on the Mac drive as part of this process. Too bad we can’t just rely on the native mac bootup process (the option button) to select any bootable parition attached to the machine.

  22. Chuckk says:

    Install Refit “as above”? Like, to the MacBook?
    What if I don’t want to alter the MacBook, like it is not mine? If I want to install Refit to the USB drive, does this have to happen before installing Linux? Does this change the number of partitions?

  23. Chuckk says:

    Also, every time I try to partition the USB drive with nothing but Free Space and MBR, I get:
    Partition failed with the error:
    Invalid argument

    No other info. Thanks Steve.
    This is OSX 10.4.11 on Intel
    Thank you!

  24. jonoave says:

    Hi,

    Can I subsquently wipe the Ubuntu installation and boot automatically into Mac OS without any trace of the Ubuntu installation?

  25. Matt says:

    This does not work. Followed every step word for word and am even using the same exact gear and os. When you get to the very last step and click on Tux to boot ubuntu you will get a black screen that says “No bootable device” I have tried several times and get the same result every single time.

Leave a Reply