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
- Use a persistent Ubuntu live session... certain features do not work
- Use rEFInd. This requires permanent changes to your Mac
What you will need:
- An Intel powered Macbook (may have to be newer than 2013) with 2 USB ports
- A bootable USB flash drive for installing Ubuntu: instructions.
- 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
- Insert your external SSD drive into your Mac
- Open your Utilities folder
- Double-click Disk Utility
- Select your external SSD drive (NOT your Mac's hard drive!)
- Click Erase with these options (if it fails, just try again):
- 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.
- Apply the changes. In the window that pops up informing you that a new Untitled partition will be created, accept by clicking Partition.
- 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
- Shutdown your Mac.
- Unplug the external SSD drive.
- Insert your USB flash drive that has the Ubuntu installer on it.
- With the option key pressed on your keyboard, boot up your Mac.
- Select the Orange EFI Boot option (right arrow, enter).
- Choose "Try Ubuntu" (default option)
Prepare your SSD drive
- Plug in SSD drive.
- Open GParted (click the upper left corner icon, type in "GParted" and click the GParted Partition Editor application icon).
- 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.
- 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:
- The delete operations are now queued, but have not been applied. Click the green check box to apply the operations.
- Add a new partition (click Partition > new).
- Use these options:
- Add another new partition with the following options:
- Apply the new partitions by clicking the green check
- Make a note of the ext4 partition name, e.g. /dev/sdd2
- Close GParted
Start installing Ubuntu
- Connect to WiFi (this saves time later, but is optional)
- Double click "Install Ubuntu" in upper left corner on the desktop.
- Choose your language.
- Check the boxes:
- Select: something else.
- 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.
- Click change... and apply these options (there should be a better way to do this, but this works):
- Choose this device for boot loader installation: select the device that corresponds to the ext4 partition. (Do not select the SSD itself)
- Go through the rest of the installation.. will take about 10 minutes.
- 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...
- Open up a Terminal window (similar to launching GParted):
- 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
- 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.
- 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
- 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
- This allows us to configure GNU GRUB, the “GRand Unified Bootloader,” with:
grub-mkconfig -o boot/grub/grub.cfg
- 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
- Exit the chrooted partition:
- Here are all the terminal commands together:
- 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
- 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).
- 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:
- Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on your screen.
- Click Utilities > Terminal.
- In the Terminal window, type in:
- Press Enter.
- Restart your Mac.
Note: if you ever get a black screen with the words "grub", just type exit.
Making Ubuntu bootable part 3
- Launch your terminal (Go > Utilities > Terminal)
- Plug in your Ubuntu SSD and type in:
cd /Volumes/Ubuntu\ Boot\ Loader/
- Tip: on your mac (unlike Ubuntu), copy/paste to the Terminal does not require shift.
- 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
- Download your boot.efi file from your email or google drive.
- Assuming your boot.efi file is now in your Downloads folder, type this into the terminal:
sudo cp ~/Downloads/boot.efi ./
- 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.
- 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.
- 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 ./
- Open Disk Utility (Go > Utilities > Disk Utility) to check what disk number your bootloader is. In this case mine is disk2s3.
- 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):
Where you replace N and K with the letters from step 12.
sudo bless --device /dev/diskNsK --setBoot
Turn SIP back on (for security).
- Shut down your Mac
Remove your USB devices
Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on your screen.
- Click Utilities > Terminal.
- In the Terminal window, type in:
- Press Enter.
- Shutdown the Mac.
Boot into Ubuntu!!
- Plug in your external SSD drive onto which we have installed Ubuntu
- Press the option key while booting up the Mac
- Select the orange Boot EFI device
- Now you have a functional Ubuntu install!
A few tips:
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.
Sometimes you may encounter this screen when booting into your Mac after using the Ubuntu drive:
Get a right click working (better yet, use an external mouse):
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 locallyThen implement unhammer's (the second) reply explain here.
Get familiar with the command line editor nano