Wednesday 1 June 2016

How to Install Ubuntu on an External Drive and boot it on a Surface Pro 3

I've been trying to get a full Ubuntu install on an external USB3 SSD, but I could never make it boot. It turns out the files on the EFI partition have to be renamed. If one knows how to do that, the rest is quite simple.

Installation instructions

  1. Get the latest ISO image from ubuntu.com
  2. Install Virtual Box + VM Extensions (this are needed for USB 2.0/3.0 support). This will be used to install the
  3. Create a virtual machine based on Windows 10 (or 8.1). Make sure Enable EFI is enabled in System.
  4. Go to USB and select USB 3.0. Add your drive there.
  5. Select the linux iso for the optical storage. You might want to select the option, named "Live CD", so that it is not ejected after the installation.
  6. Start the machine, select "Install Ubuntu" and follow the instructions. You might want to select the partitions manually (and add the EFI partition yourself), or leave it as it is. 
Now the important part! The install is generally done, but it would not boot. The EFI partition needs to be fixed. Original idea comes from this post at Stack Overflow.
  1. Reboot the virtual machine, choose "Try Ubuntu".
  2. Start a terminal and mount the EFI partition. Because, there's only one storage device and the EFI partition is the first there, you can bet it will be sda1:
    sudo mount /dev/sda1 /mnt
  3.  Copy the bootloader files to the right place:
    sudo cp -r /mnt/EFI/ubuntu /mnt/EFI/BOOT
  4.  And rename the shim to a generic name:
    sudo mv /mnt/EFI/BOOT/shimx64.efi /mnt/EFI/BOOT/bootx64.efi
  5. Finally umount it:
    sudo umount /mnt
You are done.

To get the keyboard + touchpad working see this comment. Either attach a Bluetooth keyboard and execute the next steps from within the installation, or boot the installation in virtual box using a VMDK raw image of the external drive:
sudo apt-get update 
sudo apt-get upgrade 
sudo echo "deb http://ppa.launchpad.net/tigerite/kernel/ubuntu trusty main" > /etc/apt/sources.list.d/tigerite-kernel-trusty.list 
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 984AE706D31B333A  
sudo apt-get update 
sudo apt-get install linux-surface
And reboot.

A few notes

  • Surface Pro 4 keyboard and touchpad does not appear to work on Ubuntu 16.04, though the touchscreen works. A nice trick is to log in using the on-screen keyboard and then add a pair of Bluetooth keyboard and mouse. On the other
  • One might want to modify the boot order to USB -> SSD so that any time the system is booted with the external SSD in, one would get directly to Ubuntu.
  • On my machine, a custom installation of 16.04 would not work, because of this bug. What I do is, do a recommended install and then resize the partitions through the live cd. If you want to encrypt the home folder afterwards, you might want to follow this guide. Note however, that in order to enable encryption for the swap partition, you need to install the lvm2 package as well! Otherwise, /dev/mapper/cryptswap1 would not show after restarting cryptdisks.
  • I haven't tried updating the boot image fearing it might accidentally trash my windows boot as the drive is present on Linux. I don't think it would, but still...

4 comments:

  1. Would this work on a microSD card instead of an external hard drive?

    ReplyDelete
  2. Would this work on a microSD card instead of an external hard drive?

    ReplyDelete
  3. I just read your article and found it very informative for those who are looking to mount hard drive on Ubuntu easily but still there are many different hard drives that are easy to connect even if you are using Ubuntu. Well, if you are looking to buy the best external hard drive for your back up needs then you should take a look at this list of external hard drives. I bet you will find the best one for your needs on this link.

    ReplyDelete
  4. Window Surface Pro 4 keyboard crumble shrink so ugly at the edge
    This The cause

    ReplyDelete