Installing Ubuntu on an external SSD drive on a Macbook

This guide will show you, step by step, how to install a full version of bootable Ubuntu on a SSD (solid state drive, or any other external drive), using only your Macbook. We will generally be following these instructions, with a few key modifications.

Why would you want to do this?

  • You want to have a portable full install of an Ubuntu system for prototyping
  • You do NOT want a virtual machine because they are slow
  • You do NOT want to make any permanent changes to your Macbook

Alternative options:

  • Use a persistent Ubuntu live session… certain features do not work
  • Use rEFInd. This requires permanent changes to your Mac

What you will need:

  1. An Intel powered Macbook (may have to be newer than 2013) with 2 USB ports
  2. A bootable USB flash drive for installing Ubuntu: instructions.
  3. A blank SSD drive, like this SSD USB drive ($70-130 on Amazon for the 128 GB and 256 GB versions). Why this drive? According to the specs it is FAST, and it is a SSD, not a standard USB Flash drive. So it should be more reliable (and faster) than a generic USB Flash drive. It is more appropriate for a full install of an operating system than a flash drive is.

How long will it take?

Maybe an hour. If you mess up, a good part of a day.

Let’s get started!

Part 1: Formatting your external SSD drive

  1. Insert your external SSD drive into your Mac
  2. Open your Utilities folder
  3. Double-click Disk Utility
  4. Select your external SSD drive (NOT your Mac’s hard drive!)
  5. Click Erase with these options (if it fails, just try again):
    • Name: EmptyDrive
    • Format: Mac OS Extended (Journaled)
    • Scheme: GUID Partition Map
  6. With the external SSD drive selected, click Partition. Reduce the size of the EmptyDrive partition by at least 128 MB. In this example I changed the original ~128 GB to ~127 GB. That is overkill, but it makes things simple.
  7. Apply the changes. In the window that pops up informing you that a new Untitled partition will be created, accept by clicking Partition.
  8. Select the Untitled partition, click erase, and rename it to Ubuntu Boot Loader

Part 2: Install Ubuntu on the external SSD

Start up an Ubuntu live session

  1. Shutdown your Mac.
  2. Unplug the external SSD drive.
  3. Insert your USB flash drive that has the Ubuntu installer on it.
  4. With the option key pressed on your keyboard, boot up your Mac.
  5. Select the Orange EFI Boot option (right arrow, enter).
  6. Choose “Try Ubuntu” (default option)

Prepare your SSD drive

  1. Plug in SSD drive.
  2. Open GParted (click the upper left corner icon, type in “GParted” and click the GParted Partition Editor application icon).
  3. In GParted, find your external SSD drive in the upper right box (e.g. select /dev/sdd, or whatever the appropriate letter is for you). Make sure the size of the drive makes sense.
  4. Delete all the partitions EXCEPT the hfs+ Ubuntu Boot Loader partition. Mine had two partitions to delete: a fat32 system with label EFI, and a hfs+ system with label EmptyDrive. For each partition to delete:
    • Select it
    • Click the red circle/slash symbol
  5. The delete operations are now queued, but have not been applied. Click the green check box to apply the operations.
  6. Add a new partition (click Partition > new).
  7. Use these options:
    • New Size: 8192 MiB (this should match your RAM, e.g. 8 GB = 8192 MiB)
    • File system: linux-swap
  8. Add another new partition with the following options:
    • New size: default (unless you want yet another partition)
    • File system: ext4
    • Label: Whatever you like
  9. Apply the new partitions by clicking the green check
  10. Make a note of the ext4 partition name, e.g. /dev/sdd2
  11. Close GParted

Start installing Ubuntu

  1. Connect to WiFi (this saves time later, but is optional)
  2. Double click “Install Ubuntu” in upper left corner on the desktop.
  3. Choose your language.
  4. Check the boxes:
    • Download updates
    • Install third party software
  5. Select: something else.
  6. Find the ext4 formatted partition you just created in GParted. Your best confirmation is to look at the size of the disk. Don’t screw this up.
  7. Click change… and apply these options (there should be a better way to do this, but this works):
    • default size
    • Ext4 journaling file system
    • check Format the partition
    • Mount point: /
  8. Choose this device for boot loader installation: select the device that corresponds to the ext4 partition. (Do not select the SSD itself)
  9. Go through the rest of the installation.. will take about 10 minutes.
  10. When it is finished, choose “continue testing”, as we have a few more things to do.

Making Ubuntu bootable part 1

Ubuntu has been installed on your SSD, but you won’t be able to boot into it since there’s no EFI boot loader, needed for Mac firmware to recognize the OS as bootable. So, we need to go into the Ubuntu installation and create a boot.efi file that we’ll use to boot it. While still in the live Ubuntu session…

  1. Open up a Terminal window (similar to launching GParted):
  2. Run this command in the terminal window (replace ‘/dev/sdaN’ with the device that corresponds to your /ext4 partition that you made a note of earlier – mine was ‘/dev/sdd2’)) (it mounts your /ext4 Ubuntu installation to /mnt):
    sudo mount /dev/sdaN /mnt
  3. Tip: you can select something on this page, copy it with ctrl-c, and paste it into the terminal with shift-ctrl-v. But make sure to double check the formatting, especially for underscores, and dashes.
  4. You’ll also need to mount several of the top-level directories, which is easiest to do with the following (long one line) command:
    for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  5. Now, we can use the chroot command to change our root directory to /mnt, so that the bash session in the Terminal is effectively running inside the Ubuntu installation:
    sudo chroot /mnt
  6. This allows us to configure GNU GRUB, the “GRand Unified Bootloader,” with:
    grub-mkconfig -o boot/grub/grub.cfg
  7. Now save this to a standalone file with (this is one long line):
    grub-mkstandalone -o boot.efi -d usr/lib/grub/x86_64-efi -O x86_64-efi --compress=xz boot/grub/grub.cfg
  8. Exit the chrooted partition:
    exit
  9. Here are all the terminal commands together:
  10. The boot.efi file is still in the new installation, however, we want to copy it to the live session:
    cp /mnt/boot.efi /home/ubuntu
  11. Now you will need to access the boot.efi file from your Mac OS system. The easiest is to email the file to yourself, or save it to a google drive. You can find the boot.efi file in your home directory (click the file cabinet icon in the upper left, which launches a folder view of your home folder).
  12. Now you can shutdown Ubuntu. The computer might hang.. give it 30 seconds and then manually shutdown.

Making Ubuntu bootable part 2

If you are running El Capitan or later, your Mac has extra security precautions called SIP (System Integrity Protection). This makes the last few steps a little harder. Following these instructions (copied from here), you can get around it:

  1. Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on your screen.
  2. Click Utilities > Terminal.
  3. In the Terminal window, type in:
    csrutil disable
  4. Press Enter.
  5. Restart your Mac.

Note: if you ever get a black screen with the words “grub”, just type exit.

Making Ubuntu bootable part 3

Final stretch!

  1. Launch your terminal (Go > Utilities > Terminal)
  2. Plug in your Ubuntu SSD and type in:
    cd /Volumes/Ubuntu\ Boot\ Loader/
  3. Tip: on your mac (unlike Ubuntu), copy/paste to the Terminal does not require shift.
  4. Type in the following lines (one at a time) (the password is your Mac’s password):
    sudo mkdir System mach kernel
    cd System
    sudo mkdir -p Library/CoreServices
    cd Library/CoreServices
  5. Download your boot.efi file from your email or google drive.
  6. Assuming your boot.efi file is now in your Downloads folder, type this into the terminal:
    sudo cp ~/Downloads/boot.efi ./
  7. Tip: In both Mac OS and Ubuntu, you can find a file through the user interface / finder, and drag the file into a terminal window, and it will insert the full path to the file.
  8. Now we need to make a SystemVersion.plist file. You can see what needs to be in it, and download the file directly via this link.
  9. Copy the SystemVersion.plist file to the same directory on the external SSD where your boot.efi is (/Volumes/Ubuntu\ Boot\ Loader/System/Library/CoreServices). Go back to the terminal window you had open from before and type:
    sudo cp ~/Downloads/SystemVersion.plist ./
  10. Open Disk Utility (Go > Utilities > Disk Utility) to check what disk number your bootloader is. In this case mine is disk2s3.
  11. Now we “bless” the partition for booting, and set the boot flag, like so (This is the step that required us to disable the SIP earlier):
    sudo bless --device /dev/diskNsK --setBoot
    Where you replace N and K with the letters from step 12.

Turn SIP back on (for security).

  1. Shut down your Mac
  2. Remove your USB devices

  3. Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on your screen.

  4. Click Utilities > Terminal.
  5. In the Terminal window, type in:
    csrutil enable
  6. Press Enter.
  7. Shutdown the Mac.

Boot into Ubuntu!!

  1. Plug in your external SSD drive onto which we have installed Ubuntu
  2. Press the option key while booting up the Mac
  3. Select the orange Boot EFI device
  4. Now you have a functional Ubuntu install!

A few tips:

  1. Whenever you have that SSD drive plugged into the computer, boot up while holding the option key. If it is not plugged in, just use your Mac as normal.

  2. Sometimes you may encounter this screen when booting into your Mac after using the Ubuntu drive:

    Don’t panic. Just type exit and press enter.

  3. Get a right click working (better yet, use an external mouse):

    1. Click the “Activities” icon and type in Universal Access
    2. Select “Pointing and Clicking”, and turn on Simulated Secondary Click. Now if you click and hold for a brief moment, you will get a right click.
  4. If, when you shutdown Ubuntu, it seems to take forever (e.g. 1 minute and 30 seconds), press the “Esc” key when you see the Ubuntu… logo. This will tell you what the computer is doing. If you see this:
    A stop job is running for remote CUPS printers available locally
    Then implement unhammer’s (the second) reply explain here.

  5. Get familiar with the command line editor nano