Making a portable full installation of Ubuntu on a USB HDD

Close up photo of a USB pen drive

I regularly have the need to try things out on Linux. Sometimes a virtual machine won’t cut it for me typically due to memory, disk and performance limitations. Moreover, a decent, up-to-date, bootable Linux environment is a great backup in case all of my other computers are broken, infected or stolen. That entails having the Linux installation on an external, USB-attached hard disk drive which can boot with relative ease on any UEFI-enabled PC (driver compatibility notwithstanding). Moreover, all the preparatory work has to be performed using a single-boot Windows computer without ending up having a dual boot system. It sounds tough. It is tough, but I’m writing this from my portable Ubuntu Linux installation running off a USB-attached SSD!

What you need

  • An empty external (USB) hard drive. I used a USB 3 drive enclosure with a cheap 256Gb SSD. For those of you worrying about performance, the USB 3.0 port is faster than the maximum transfer rate of any SSD I’ve seen to this date.
  • Ubuntu Linux bootable USB drive. Very easy to create using Rufus on Windows. I used a cheap, promotional flash drive. Reduce, reuse, recycle FTW.
  • Windows System Repair Disc (a bootable USB drive with Windows recovery tools which you can make yourself) or a Windows installation or rescue CD-ROM / DVD-ROM. I used another promotional flash drive.

Remember to take backups of all your critical files and folders before continuing. You are going to make changes to your computer. If it breaks don’t cry, I warned you. Also test both your bootable media. Twice. You will need them both!

Caveats

Having a dual- or multi-boot system isn’t as straightforward as it used to be a decade ago. Nowadays, in the interest of security, performance and backwards compatibility, there are many semi-hidden options and features which can get in your way. Given enough experience and patience you can work around them. Below is a selection of problems that got me moderately stumped along the way.

Secure boot caveat

I have only tested these instructions with Secure Boot turned off. Even though Ubuntu does support Secure Boot (it comes with signed bootloaders) I have no idea if my method uses the signed bootloaders or not. I suggest turning off Secure Boot if possible.

FastBoot caveats

Many boards come with some sort of “fast boot” or “boot optimization” options. For example, my Intel NUC has an option called Fast Boot which won’t let me choose an alternative boot device at startup. It also has an option to support Intel Rapid Start Technology which does get in the way of booting to multiple OS. I had to disable both.

It’s worth noting that Windows 8 and 10 have an Fast Startup or Fast Boot feature. This feature takes some shortcuts when it comes to booting and also makes the NTFS filesystem remain in a dirty state, making it unwriteable from Linux. It’s best to understand what it does and disable it if you plan on writing to your Windows drive from Linux.

USB host controller caveat

Some firmwares will present the USB host controller as UHCI (USB 1.1) at boot time. When Linux probes for an xHCI (USB 3) host controller during the boot process they will respond positively. At this time Linux loads the xHCI driver and the USB host controller resets itself.

However, your root filesystem is inside a device attached to this USB controller. Therefore the controller resetting means that Linux can no longer communicate with the USB-attached hard drive. Therefore the Linux boot will hang forever without any further indication as to what went wrong.

Most affected boards (including my Intel NUC) have an option to enable the xHCI host controller interface by default. Enabling the xHCI option in the BIOS fixes the hanging boot issue. If you are only using modern operating systems with USB 3 support (anything newer than and including Windows 8.1 and Ubuntu Linux 15.04) you can safely enable that option.

Installing Linux

Boot your computer from the Ubuntu Linux bootable USB drive. Remember that you may have to enter your computer’s boot manager to do that (on my Intel NUC I have to press F10; on most other BIOS I’ve seen it’s F9; consult your BIOS documentation).

Install Ubuntu Linux regularly. When it prompts you about the disk layout choose Something Else and partition your external HDD the way you want. I chose to create a modestly sized root partition (about 40Gb), a swap partition that’s as big as the biggest RAM configuration I am going to be using this installation with plus one Gb (my computers max out at 16Gb so I made a 17Gb swap partition) and the rest of the disk went to a massive /home partition.

Caveat: I chose to use btrfs which – as I learned along the way – makes things a bit more complicated down the line. For your sanity’s sake I recommend using ext4. This guide assumes the use of btrfs and will point out the caveats with this approach.

Fix Windows 10 boot

Unfortunately the Ubuntu Installer assumes that you want a dual booting configuration alongside Windows. Therefore it adds itself (actually, the bootloader it uses, GRUB2) to your computer’s UEFI configuration. This causes two problems. For starters, the external HDD is not portable as you cannot boot with it on another computer.

Secondly, if you remove this external HDD your Windows won’t boot. Bummer. We have to fix that.

  • Shut down your computer.
  • Disconnect the Ubuntu HDD
  • Boot from the Windows system repair disc USB drive (or a Windows installation or rescue CD-ROM / DVD-ROM).
  • Select Repair your computer.
  • Select the operating system and click Next.
  • Choose Command Prompt.
  • In the command prompt run
    diskpart
    sel disk 0
    list vol
  • Verify that the EFI partition is using the FAT32 file system. It will have a volume ID, let’s say 99. Now we need to assign a drive letter to it. Back in the command prompt type:
    sel vol 99
    assign letter=z:
    exit
  • Now we need to fix the boot record. Again in the command prompt type:
    z:
    cd EFI/Microsoft/Boot
    bootrec /FixBoot
  • Finally, we need to re-create the BCD store which tells the Microsoft boot loader where to find Windows so it can boot it. From our trusted command prompt:
    ren BCD BCD.old
    bcdboot c:\Windows /l en-us /s z: All
  • If this didn’t work try
    ren BCD BCD.old
    bootrec /RebuildBcd

At this point exit the command prompt and shut down your computer.

Create an ESP on the Ubuntu HDD

A hard drive is not bootable with UEFI unless it has an ESP (EFI System Partition). An ESP is simply a FAT32 partition with a special flag that tells the EFI BIOS to look inside it for boot information. We have to create one on your hard drive.

  • Plug in your external HDD and the Ubuntu Linux bootable USB stick.
  • Boot with the Ubuntu Linux bootable USB stick using the option to try Ubuntu before installing.
  • Open a Terminal (CTRL-ALT-T)
  • Run sudo fdisk -l to get a list of partitions.
  • Identify from them the drive that has the Linux partitions, in my case /dev/sdb. I’ll call it /dev/sdX from now on.
  • Also identify the partition that contains the root filesystem. I will call it /dev/sdXY from now on.
  • Launch GParted from the Terminal:
    sudo gparted /dev/sdX

    Why not just click on GParted on your desktop? Well, I kept receiving errors about the Ubuntu Linux bootable USB stick because it was already in use. Of course it is, I am using it to run the computer off it, duh!

  • Resize the first partition on disk to have another 200 Mb of free space after it.
  • Create a new partition on the free space, changing the file system to fat32.
  • Apply operations. You need to do that now for the next step to be possible.
  • Right click the new partition.
  • Click on Manage Flags.
  • Set the boot and esp flags. This is what makes the partition “special” to the EFI BIOS.
  • One more thing! Note down the the partition that contains the ESP filesystem. I will call it /dev/sdXZ from now on.

Make sure the Ubuntu installation on the external HDD can see the ESP

The new ESP on the external drive must be visible by the Ubuntu installation in the HDD. Otherwise GRUB2, the Linux bootloader, won’t be able to update itself, making your system unbootable after the next kernel update at the latest.

  • Launch GParted from the Terminal, as we saw above:
    sudo gparted /dev/sdX
  • Double click the partition with your Linux root (/) filesystem on the external HDD
  • Note down the UUID, e.g. 01234567-89ab-cdef-0123-4567890abcde
  • Double click the new FAT32 partition and note down the UUID, e.g. 0123-ABCD
  • Close GParted
  • Open a Terminal

The process is different depending on the format of your root partition on the external hard disk.

If you DID NOT use btrfs (e.g. you used ext4)

sudo umount /media/ubuntu/01234567-89ab-cdef-0123-4567890abcde 
sudo mount /dev/sdXY /mnt

If you DID use btrfs

If you DID use btrfs, you made your life complicated. We need to mount the btrfs subvolume containing the root partition instead of the entire partition. Otherwise you’ll never be able to install GRUB and you’ll probably lose an entire day, like me.

btrfs subvolume list /media/ubuntu/01234567-89ab-cdef-0123-4567890abcde

This will give you a line with a numeric ID. Let’s say 123. Note it down.

umount /media/ubuntu/01234567-89ab-cdef-0123-4567890abcde
mount /dev/sdXY -o subvolid=123 /mnt

The rest of the instructions are common, no matter if used btrfs, ext4 or something else

  • sudo nano /mnt/etc/fstab
  • There is a line with /boot/efi already in this file. Comment it by placing a # in front of it.
  • Add the following line:
    UUID=0123-ABCD /boot/efi vfat defaults 0 1

Install GRUB2 on the external drive’s EFI System Partition

Right now our external drive has an empty ESP. We need to put a bootloader in it to make it actually, well, bootable.

First caveat: all the instructions you find on-line assume you are using a dual boot system with Windows or macOS. When you have an external drive it is critical that you use the –removable option in the last step. This installs the EFI bootloader under the special “fallback pathEFI\Boot\bootx64.efi in the ESP. Normally this not supposed to be used for permanently installed Operating Systems. It’s the mechanism used by EFI BIOS to boot arbitrary external media. Technically, that’s exactly what our external hard drive is: arbitrary external media!

Second caveat: installing the bootloader is only possible from inside the Linux installation we want to boot. However, we need the bootloader to boot that installation, leading to a Catch-22 issue. The solution is to run the bootloader installation through a chroot jail. The actual caveat that got me stumped for a day comes from the fact that I am using btrfs (because it’s so much better for SSDs!). btrfs has subvolumes. If you mount the entire partition instead of a subvolume the grub-install script can’t figure out the mapping between paths and devices, therefore failing to install itself on the ESP, returning the cryptic error

/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).

The error is misleading! /dev is mounted if you follow my instructions below. The actual problem, as I understand it, is that there is a discrepancy between the mounted device and the path to the chroot root. That’s why I had you mount only the subvolume containing the root filesystem in the steps above. If you were not paying attention, you are not following the instructions step-by-step, you rebooted before this step or just came here directly looking for a solution to your problem about GRUB not installing look above for instructions on mounting the correct btrfs subvolume.

  • We need to prepare the chroot environment. The ESP must be mounted in the correct place and we have to bind system mount point for some special trees (most notably /dev). Moreover, we will copy the resolv.conf file to let the chroot environment have network access should it need it.
    mount /dev/sdXZ /mnt/boot/efi
    for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/$i; done
    cp /etc/resolv.conf /mnt/etc/
    modprobe efivars
  • Finally we enter the chroot environment and install Grub in a way suitable for a removable device (see the first caveat above).
    sudo chroot /mnt
    grub-install -d /usr/lib/grub/x86_64-efi --efi-directory=/boot/efi/ --removable /dev/sdX

Now your external HDD is bootable. Reboot your computer, select it from the boot media selection of your UEFI BIOS and you’re done!

139 Replies to “Making a portable full installation of Ubuntu on a USB HDD”

  1. Nice instructions. I’m fighting currently with exactly that problem.
    One question/comment: In your chapter “Secure boot caveat” you wrote: “[i]I’ve only tested these instructions with Secure Boot turned off[/i]”. Here you are referring to the option in the ubuntu installation, right? I first thought you are talking about turning UEFI-Boot off in the “BIOS” (I know it is not called anymore BIOS)

    1. I was talking about the UEFI firmware setting. You’re right, it’s not called BIOS, it’s called UEFI Firmware now 🙂

      Somewhere in the Boot options menu there’s a switch for Secure Boot which [url=https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Secure_boot]only allows cryptographically signed bootloaders to execute on boot[/url]. If you are using the precompiled Ubuntu kernel and bootloader they are signed and can work with Secure Boot. However, since I’m using grub-install in the last step I am not sure if I’m breaking the signature. If your PC barfs a message about unsigned bootloaders, invalid signature or you get to simply stare at a black void, er, screen then this might be the case.

  2. Hi I think your post is the solution to my problem [url=http://askubuntu.com/questions/888426/make-a-portable-ubuntu-usb-stick-on-a-uefi-windows-machine-with-no-boot-loader-c][/url] question. Since hanging the boot order in the firmware to UEFI Windows, windows appears to boot normal again. So my question: do I need to do the fix windows 10 boot section and if so will I have issues doing this as my Windows machine is Bit locker encrypted (chip not key)

    1. Hi Alec! Apparently I did answer [url=http://askubuntu.com/questions/888426/make-a-portable-ubuntu-usb-stick-on-a-uefi-windows-machine-with-no-boot-loader-c]your question[/url] (I’m adding the link since you pasted it wrong above). You still need to fix the Windows boot section as I described. That’s necessary for the small UEFI boot stub to live in the correct place. The BitLocker encryption settings [url=https://www.howtogeek.com/236719/whats-the-difference-between-bitlocker-and-efs-encrypting-file-system-on-windows/]are stored in the NTFS filesystem[/url] itself. Therefore Windows knows that the volume requires decryption and the decryption key is [url=https://technet.microsoft.com/en-US/library/hh831713]safely tucked away in the machine’s Trusted Platform Module[/url].

      FYI, that’s the same principle which allows you to run UEFI live Linux distributions on your PC without being able to access the encrypted volume but also without damaging it. Moreover this is the same principle behind being able to repair a damaged UEFI partition without losing all the contents of your hard disk. BitLocker is a very well thought out full disk encryption solution. However, it’s always a great idea keeping a backup and a backup of the backup before doing anything which could have even the remote chance of screwing up your computer. Better be safe than sorry!

      1. Hi again. After a long time I came back to this. The bootrec /fixboot rec dosnt work for me (dosnt find windows). I think because the dirve is bitloked and I dont have the key to unlock it in recovery. Anyhow since I forced the boot order in bios the machine was booting normaly just no longer finding the ubuntu on the SSD and the BCD looked normal. I followed the rest of your instructions and all is now working. Boots to windows with no SSD and boots to ubuntu with SSD when selected as boot media. so many many thanks for your instructions! If only Ubuntu had an install option that let you spesify where to put the grub!

        1. If you have a drive protected by BitLocker you need to use a Windows 10 recovery DVD and first try to use its Repair option. It will ask you to enter the BitLocker recovery code which you have either printed out or it’s stored in your Microsoft account (default for self-owned machines). Even if the automatic repair fails you can then go to the command prompt and do everything you need – the drive is now unlocked.

  3. Excelent!!!
    Been for days trying to fgure out how to do this.. seems to be a Ubuntu install limitation. First the bootloader was installed on the PC harddisk, without me wanting it .. then made the EFI partition with the proper flags but no matter what I tried, it never installed the bootloader on that partition. Finally read somewhere that Ubuntu only installs automatically EFI if partition is sda, since i am booting for a live usb to install in other, the media is always sdb.. really really thank you!!!

    1. Yes, that’s UEFI only. I don’t have a computer with legacy (BIOS) boot to test. I’m pretty sure that if you have 2Mb of free space in the beginning of your hard disk you can install a GRUB MBR there. It’s been too long since I last did that and it was with GRUB 1 so don’t ask me how 🙁

  4. Thanks! First clear description of what’s going on, and how to make it work. Finally got my external SSD to boot.

  5. Hi, thanks for your write up. Does running an OS installed on a USB drive risk damage to the drive and premature failure? Or is it safe to do without having to worry about even wearing and write rates? I assume the technology in the drive is different to old HDD or SSD and not necessarily designed for this type of use or is it all good?

    1. Wear leveling is a feature of the SSD itself. It doesn’t matter which system bus / connector the SSD is attached to (SATA, mSATA, PCIe via M.2, USB…). The bus selection only affects maximum throughput, not wear leveling.

      Modern SSDs are designed to be used as the primary or only storage medium of a computer. Otherwise devices like the Apple MacBook Pro or the Microsoft Surface Pro wouldn’t be possible. For average (non server) use SSDs and HDDs have practically comparable lives.

      Please note that I used a “real” SSD in a USB enclosure. If you use a flash drive your mileage will definitely vary (and be much, much shorter). Flash drives are not designed with a long write cycle in mind. They are also woefully inadequate in terms of speed. If you want to have an OS on a portable drive use a regular SSD in a USB 3.x enclosure.

  6. Hi. Thanks for these instructions and they did help, but I’m still unable to boot from my external hard drive. I get ‘System BootOrder not found. Initializing defaults’ error message and then restarts. I tried installing Linux Mint on one of my external drivers and can confirm that i was able to install the OS successfully and also the grub install with the removable option fine with no errors. Its only during boot that I’m stuck. Any one else faced similar issue?

    1. This seems to be a UEFI firmware issue. First make sure that Secure Boot is disabled in your UEFI setup (what we called BIOS setup in the olden days). I never had any luck booting Linux off removable media with Secure Boot enabled.

      If you still have this issue you may want to use efibootmgr as root, e.g. from a bootable USB stick with Linux, to set up the UEFI boot load order. See [url=https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/system-bootorder-not-found-4175584185/#post5577511]this question on LinuxQuestions[/url].

  7. Hi. I would like to notice that in the ‘Fix windows 10 boot’ when recreating the BCD store. A ‘/f’ flag is missing from the original instructions, and the RIGHT version should be:

    bcdboot c:\Windows /l en-us /s z: /f All

    Otherwise, very bad things happen… :*

  8. Wow! I just finished this procedure, and it works. It did take several hours for me to complete it because I and just getting started with Ubuntu Linux. One thing which took me a while to figure out was that I had to change directory to “/” before the “cp /etc/resolv.conf /mnt/etc/” would work. This was located in the second to last bullet point in the procedure. Question: now hard would it be to change to Linux Mint if I want to do that? Do I have to start all over at the beginning of the procedure? Many thanks for the detailed procedure! No way I would have done the installation in this manner without the excellent procedure.

    1. Mint is not an official flavor of Ubuntu IIRC, meaning that you can’t just apt-get install something and be done with it (as you’d do with Kubunty, Xubuntu, Mythbuntu and other official flavors). So in this case, yup, you’d need to start over.

  9. Oops: I didn’t notice the last comment about the missing “/f” flag. Is this comment validated by N.K. Dionysopoulos? Can I fix it now, after already booting from my external ssd?

    1. It’s not a flag, it’s a selector. It tells bcdboot which boot loader (formware) technology to use: BIOS (MBR) or UEFI. The default value is auto-detect. If you are running it on a UEFI-capable computer it will default to UEFI. I would NOT use /f All unless you have a valid reason to want to boot [i]Windows[/i] using legacy boot. Since this guide talks about UEFI I think it’s safe to assume you’d never want to do it. Well, if you have explicitly enabled legacy boot and your firmware doesn’t fall back to UEFI if there’s no MBR record then, yes, you will need to use /f All – which I believe is what happened to our anonymous friend above. For most other people, though, this would be an unnecessary step with potential complications.

      TL;DR: If it ain’t broken don’t fix it.

  10. Hi Nicholas, GREAT job!… but I need a little help. I’m trying to follow your guide using my mac and installing ubuntu on my external HD. Do you think will be the same? Is your guide usefull for Apple’s too? Thank you in advance.
    Best regards.

    Andrea.

    1. It’s actually simpler with Macs since all you need to do is reset the PRAM after unplugging the external SSD. The Mac’s firmware prioritizes booting macOS from the main partition of the primary disk. I would bet that you have a MacBook Pro / Air which means that macOS will prioritize booting from its internal SSD. Therefore you don’t need to do the whole restore Windows bootloader dance. You still need to follow the instructions to reinstall the Linux bootloader in a way that makes it into a portable boot disk.

      That said, running Linux on a Mac is a pretty hectic experience since Apple won’t release any drivers or specifications for its proprietary hardware implementations, of course. The least of my worries had been the keyboard. Using an external keyboard or mapping keys the hard ways had helped a lot. The major problem I had with it is that many built-in devices won’t work. You may get iSight working if you have an old Mac. Forget about getting the SD card reader working. If you have a 15″ with discrete graphics you’re in for a world of pain (I have an old 2011 MacBook Pro with AMD discrete graphics that took serious boot parameter tinkering to get it booting and nope, discrete graphics won’t work at all). The touchpad was recognized as a 2 button mouse – no multitouch. External touchpad was simply not working. Magic Mouse was recognized as a very non-magical 2 button mouse. It couldn’ve been worse.

  11. I do have a problem: My system won’t boot when I remove the external ssd. I get The message: GNU GRUB Version 2.02~beta3-4ubuntu7. This is followed by several more lines That begin with “Minimal BASH-like line editing is supported. …” followed by “grub _”. Apparently, I did something wrong. I am using a computer with Windows 10 installed. I did execute the line: “bcdboot c:\Windows /l en-us /s z: All” (it is possible that I entered /1 instead of /l after windows). I got a message that indicated the command didn’t work – don’t remember the wording. Then, I executed the “bootrec /RebuildBcd” command. It seemed to work; I got no message after I executed it. Then, I continued with the remaining instructions. My system works fine with Ubuntu, but will not boot to Windows 10. Can you suggest how I should fix this, please. Thanks, Jim Mc.

    1. My only logical conclusion is that you accidentally missed something in the “Fix Windows 10 boot” section of this guide. It’s the trickiest bit for getting this to work. It took me two days to figure out how to fix the same problem you had and that’s how I fixed it. Then I started over and redid everything from scratch just to make sure that my guide is accurate (yup, it is). If, however, you miss [i]any[/i] of the steps, even those which look inconsequential (like changing to the ESP directory before running bcdboot) can throw the entire process out of whack.

      So, my best advice is to print a hardcopy of this guide, or open it on a tablet / phone / whatever, and retry the Fix Windows 10 Boot section’s instructions very carefully, without skipping anything. I know it sucks and it’s slow. Sorry 🙁

  12. I finally got back to this, and it works. However, to boot to Windows with the HDD removed, it is necessary to go into setup and change the first boot device to “windows Boot Manager”, save changes, and exit; otherwise it hangs. I thought it would automatically skip Ubuntu and boot into Windows, but it doesn’t. Thanks for the procedure and the help. Jim

    1. Boot into your UEFI setup (what we used to call “BIOS” in the olden days) and change the boot order. Set Windows first.

  13. With “Windows boot manager” as the first boot device, it always boots into windows, and I don’t have an option to boot into Ubuntu without going into setup and changing the first boot device to Ubuntu. Not a big issue, just a small annoyance that I can deal with. If Ubuntu is set to boot first, I do have the option to choose Windows, but if I then disconnect the SSD, I have to go into setup and change the first boot device to windows. It would be a tad more convenient if it would just skip ubuntu when the SSD is disconnected, or give the option to choose Windows or Ubuntu when the first boot device is set to Windows. I’m not complaining, just making a fine point.

  14. I’ve seen other HOWTOs that suggest an alternate process, which *sounds* simpler: (1) set the BIOS boot sequence to boot from a USB device, (2) shut down compuyer and disconnect internal hard disk(s), (3) boot Ubuntu from USB flash drive, (4) install Ubunti form flash drive to portable hard disk. (Since the only i8nstalled or available hard disk is the portable one, it will be installed as single boot without altering the disconnected internal drive.) Any comments./comparisons on this, or any additional steps this would require to insure compatibility with UEFI? I am carrying out the install on an older BIOS computer, but want to be able to use the portable hard disk to boot UEFI machines.

    1. First of all you need to disconnect the internal hard drive which may not always be feasible or convenient. It’s been a decade since I last run a midi tower with a side panel missing and don’t get me started on my Slimbook and its abundance of screws.

      Secondly, most computers will freak out as soon as you unplug the USB HDD because the only and default boot disk disappeared.

      Thirdly and MOST important: what you end up with IS NOT a portable hard drive! It will only boot on the computer you installed it on and only if you don’t mess with the UEFI boot order. In other words you’ll still have to press F9 to choose which OS to boot on the original computer and your HDD cannot be used anywhere.

      I don’t know what the other people claim, but it doesn’t look like they tried their own instructions. I did and I was disappointed. So I spent two days, found instructions that work, wrote them down, formatted my HDD again, tried them again and only then did I hit publish.

      Basically, if you see something written on this blog I have tried and use it myself. I don’t do useless brain fart dumps for page views. That’s why my blog posts are so far in between 🙂

  15. Thank you for these instructions. I use W8 on my notebook but having an Ubuntu installation available on my notebook would come in handy for me because I’ll be away from my desktop with Ubuntu for over a month soon. I don’t want to make any changes to my notebook’s HDD with W8 installation, so I thought running Ubuntu from an external drive would be the best.
    Before I start (well, I still haven’t got any SSD yet, so I can’t really start yet), I would like to confirm one thing. Does it mean that if I follow these instructions, I can create an installation of Ubuntu and make it bootable on some PC, and then when it’s done take the SSD and use it with a different PC if I plug it in and change the booting priority?
    If it’s possible I’d rather try to make the external SSD Ubuntu installation on my old W7 notebook so that it wouldn’t matter that much if something got screwed up during the part where you have to fix Windows booting. But I’d like to use it with my regular W8 notebook when it’s done.

    1. Hello Jan,

      Yes, you understand correctly. You can create the bootable drive on any computer and have it boot on any other computer just fine. Modern Linux is very smart about automatically detecting hardware and loading the appropriate drivers. I’ve tested that by booting my portable Ubuntu installation off a MacBook Pro when I had to boot the Intel NUC into Windows but still needed to use my Ubuntu installation at the same time 🙂

    1. Maybe, but I wouldn’t count on it. Installing an operating system may change the default EFI boot entry in the system. Part of the solution addressed that issue.

  16. Thank you for these instructions. However im running into a boot issue. when the dual boot screen appears i select Ubuntu and then it seems as though it want to load the OS but then i get a screen which is black and white and list some boot details (similar to below). any thoughts? also, the hardware is a surface pro 3. thanks

    [ 1.65621] 18042: cant read CTR while initializing 18042
    /dev/sdb1: clean, 187936/2437776 files, 1117662/971276 blocks
    [FAILED] failed to mount /boot/efi.
    See ‘systemctl status boot-efi.mount’ for details
    ……….

    1. The first line is not an error, see https://unix.stackexchange.com/questions/379834/linux-throws-error-cant-read-ctr-while-intializing-i8042

      The second line means that Ubuntu can’t mount the EFI partition. At this point it should be throwing you to a shell. As told, run systemctl status boot-efi.mount to see why the mount failed. This should give you more clues as to what’s going on. 80% of the time spent on the computer doing something new is troubleshooting – but that’s we get to learn something new, right? 😉

  17. Hey I’ve been trying to follow this guide but I can’t seem to get past the fix windows 10 boot part! I keep getting a “access denied” message whenever I try to fixboot. I can still boot into windows with the external drive unplugged, but I can’t boot into the drive on any other computer. I don’t think I misfollowed the guide anywhere but just in case I’ve uploaded a picture of my command prompt: https://m.imgur.com/MxNT1Id. Do you know of any solution? I’m on currently on a Lenovo flex 3 laptop and I’m pretty positive the ESP is the EFI partition.

    1. It looks like you’re mounting the wrong partition. This seems to be the Lenovo Recovery System EFI System Partition if I were to make an educated guess based on its name (LRS_ESP). Since it’s part of the system recovery I bet it’s immutable. Look at volume 2. It’s FAT32 which is what an EFI partition should be. It’s small (260MB) which is also what an EFI partition should be. It’s also called SYSTEM_DRV which seems to be consistent with an EFI (system) partition.

  18. Thanks for the reply! Unfortunately I’m getting the same access is denied error for that volume as well :(. I’m on a Lenovo Flex 3 laptop, and I’m starting to think this isn’t possible to do on my hardware.

  19. Hello. I followed all of your steps, but when I boot into Ubuntu, it shows “file /boot not found.” Can you please help me? I looked up steps and it said I needed to include –boot-directory?

    1. Are you using BTRFS instead of, say, EXT4? In this case you need to list the subvolumes and mount them. If your boot directory is a separate subvolume you have to mount it too. BTRFS always has subvolumes, even if you use one partition per volume. This cost me a day and some of my sanity as I explicitly say in the tutorial.

      Generally, remember to mount your /boot volume [i]before[/i] mounting /boot/efi, in its turn happening before you enter a chroot environment to install GRUB to the external drive. If you mess it up GRUB will install its configuration files on the main volume (filesystem root, where the /boot mount point lives) which, of course, won’t work properly since at boot time Linux will be mounting the boot volume to /boot, thus hiding any files in there.

      Also check your /etc/fstab file. If your /boot directory is on a different volume than your main (filesystem root) volume you need to have an entry there. Check that the UUID of the entry matches the reality of the partition table of your removable drive. The same applies for the EFI System Partition volume which also needs an fstab entry to mount point /boot/efi. I think that this is most likely what happened to you since you got a message about the /boot partition not being found by our friend GRUB.

      Only after doing all of that should you follow the last two steps of this tutorial. Then GRUB will be seeing all the partitions, mounted to our chroot environment, and the fstab will tell it how to find those partitions at boot time. The options we pass to GRUB will install an EFI boot loader on the external drive and that’s all there is to it.

          1. Also, yes. It does work on Secure Boot.
            Also, does this work on mac? I have windows, and is it possible to do cross-platform

          2. It should work on a Mac. I have only tried this on a 2011 MacBook Pro without issues. If anything, it was easier than getting it to work on Intel NUC.

  20. Thank you so much for the work you’ve put into this. I’ve had the same issue as Eric with the Windows fixboot ‘access denied’ error, and I’m definitely using the correct EFI partition (its the only fat32 partition of 100MB). But I’ll deal with it by just reinstalling Windows 10 from scratch – thankfully I made a system image backup before starting this process.

    My (newbie) question is simpler: when preparing the chroot environment, how do I get from the “>” prompt, back to the normal terminal prompt? (Screenshot [url=https://goo.gl/virUVq][/url]). Typing ‘exit’ didn’t work. Thanks!

    1. Check all your FAT32 partitions. Also note that they may not be in the first volume (physical device)! Many computers come with separate devices. Sometimes you have two separate devices even though you have installed only one hard disk if that hard disk is hybrid (an HDD and an SSD in one). While Windows sees it as one big drive, this is just a logical grouping; there are two physical devices and that’s what matters when we try to get boot working 😉

      Regarding the chroot environment, pressing CTRL-D or typing exit should work. Please note that whenever you use sudo you get into a child shell so you have to exit this first. That is to say, if you chroot and then sudo you need to use exit twice to get back to the original shell you started from.

  21. Hi there!
    Great tutorial.
    I want and will try this solution with a HDD plugged on Windows 10 laptop.
    My only doubt is that if when I install Ubuntu on the external HDD will Grub replace Windows 10 default bootloader/boot manager? Or in other words, will I always have the Grub menu instead of Windows 10 default bootloader/boot manager even when the HDD is not connected by usb to the laptop?
    My intention is not to have the Grub menu, that is, if I boot from the laptop disk, automatically boot Windows 10. And if I boot from the external HDD, automatically boot Ubuntu!
    Is that possible?
    At best, I would not mind that Grub menu only showing if booting from the external HDD, where Ubuntu is installed.
    Best regards,
    José Pedro

    1. When you install Ubuntu it does replace Windows boot manager. That’s why we have a tutorial section on recovering the Windows boot manager 🙂

      If you follow my instructions your laptop’s internal drive will only have your Windows boot manager and only boot on Windows. The external HDD will have a special UEFI executable for GRUB2. This lets you plug it into any UEFI-capable computer (pretty much everything built after 2010 or thereabouts) and boot it – note that you may have to enter the boot selection menu if you haven’t made boot from USB a higher priority item than boot from internal drive in the UEFI configuration (what we used to call “BIOS” back in the day).

      1. Thanks for your answer.

        I’de also like to ask your opinion about I read in another article/tutorial, where the instructions are to install Ubuntu (from the live USB) opening the Terminal and run the following command:

        [code]ubiquity –no-bootloader[/code]

        With this the author says the installation would not replace the Windows default bootloader.
        Is this accurate?

        Then the instructions (after Ubuntu is installed) are to boot from the live USB and use the GRUB console to look for the new installation, specifically look for the /boot/grub directory:

        [code]grub> ls (hd2,gpt2)/boot/grub
        unicode.pf2 …[/code]

        Then set this as the root for further commands:

        [code]grub> set root=(hd2,gpt2)[/code]

        Then find out the UUID of the drive:

        [code]grub> ls -l (hd2,gpt2)
        Partition hd2,gpt2: Filesystem type ext* 〈…snip…〉 UUID e86c20b9-83e1-447d-a3be-d1ddaad6c4c6 – Partition start at […][/code]

        After that tell GRUB where Linux is:

        [code]grub> linux /boot/vmlinuz〈…tab here!…〉.efi.signed root=UUID=〈the UUID from above〉[/code]

        Finally set the initrd (initial RAM disk) and boot:

        [code]grub> initrd /boot/initrd〈…tab here!…〉[/code]

        [code]grub> boot[/code]

        What do you think about this solution?

        1. Running ubiquity (the Live CD installer) like that will indeed NOT install GRUB at all. Anywhere. The rest of the instructions, however, don’t make your external HDD bootable. If you read the original article [url=https://medium.com/@mmiglier/ubuntu-installation-on-usb-stick-with-pure-efi-boot-mac-compatible-469ad33645c9]over at Medium[/url] (side note: ALWAYS attribute sources, don’t plagiarize) you’ll see that his goal was to boot to Linux once and then change his EFI partition type, making an HDD that’s only ever bootable on a Mac. With my instructions your HDD will be bootable on any computer with EFI and USB boot enabled, including but [i]not[/i] limited to Macs (so far I’ve tried on a late-2011 MacBook Pro 15″, late-2012 Mac Mini and an early-2015 MacBook Pro 13″).

          To be precise, the rest of the instructions you posted from that article would have to be carried out every single time you want to boot to Linux. Yes, every single time you will have to insert the Live CD / Live USB, display its GRUB menu, drop back to the GRUB command prompt, mess with UUIDs and hopefully boot to Linux. This is the exact opposite to user-friendly. Also, it’s highly unnecessary. Instead of these instructions just carry out my instructions from “Create an ESP on the Ubuntu HDD” onwards.

          Disclaimer: Follow this at your own risk. I have not tested this method. Your mileage may vary. If it breaks you get to keep both pieces 😉

  22. Sorry for not having attributed the source of the information, but I’m not used to these things.

    I’ll follow your instruction as soon has the external HDD arrives.

    My intention was to install Ubuntu on the external HDD, and whenever I wanted to boot to Ubuntu (always from the same PC) I’d only have to connect the HDD (in the UEFI/BIOS settings booting from the external HDD would have priority).
    I thought the process would be simpler, not that your instructions are complicated.

    Thank for the quick replies! 🙂

  23. boot-repair could save you all the steps done with grub. All you need is the fat32 partition and fireup boot-repair, the rest explains the UI at the Advanced tap.

    1. I had already tried that, unsuccessfully. That’s why I went into the trouble of doing things manually and write it up. You can of course try your luck with boot-repair and if it fails just pout instead of using the free instructions someone posted on the Internet. But please don’t come and shitpost on the comments. Nobody likes an arrogant know-it-all asshat. kthxbye

  24. Hi when I run:
    for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/$i; done
    I get:
    mount: mount point /mnt//dev does not exist
    mount: mount point /mnt//dev/pts does not exist
    mount: mount point /mnt//proc does not exist
    mount: mount point /mnt//sys does not exist
    Which makes me think I’ve done something wrong
    Also when I run:
    sudo chroot /mnt
    I get:
    chroot: failed to run command ‘/bin/bash’: No such file or directory
    Which makes me think I’ve made a mistake elsewhere in following the tutorial, any ideas on what I’m doing wrong?

    1. Follow all my instructions from “Make sure the Ubuntu installation on the external HDD can see the ESP” onwards. Most likely you either forgot to mount the external drive under /mnt or the drive is formatted with the BTRFS file system for which I have added some very important warnings.

  25. Hello,
    I followed all your steps. When I run last command
    grub-install -d /usr/lib/grub/x86_64-efi –efi-directory=/boot/efi/ –removable /dev/sdb

    I get this error:

    grub-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesnn’t exist. Please specify –target or –directory

    Filesystem is formated as ext4

    Any ideas?

      1. Thanks for immediate reply,

        so I changed command to

        grub-install -d /usr/lib/grub/i386-pc –efi-directory=/boot/efi/ –removable -dev/sdb

        and output was:

        Installig for i386-pc platform.
        grub-install: error: failed to get canonical path of `/dev/sdb3′.

        by the way: sdb1 is EFI, sdb2 SWAP, sdb3 ext4 linux root, sdb4 ext4 – data

        Is it trying to install grub on my linux partition instead of EFI?

        1. I suppose you meant –removable /dev/sdb over there 🙂 First make sure that you are running this from inside the chroot jail in /mnt. The error you get means that GRUB can’t find an /etc/fstab entry for the /dev/sdb3 partition, therefore it has no idea it’s the root partition. You can also try adding –force to the GRUB installation command line to force the installation but if you’re not inside the chroot jail you won’t get a bootable drive.

          1. Before, I did run the command:
            sudo chroot /mnt
            and line changed from
            ubuntu@ubuntu:
            to
            root@ubuntu:/# (and changed from green to white)

            If that’s what u’r asking. I did also all the steps above – except fix windows 10boot. My emmc with windows is dead – that’s why I’m installing Ubuntu to external HDD. So the original EFI partition on emmc is destroyed. And I don’t care about running windows. Just Ubuntu from external.

          2. Hi,
            found the mistake – missed one step, my bad – sorry for bothering with that.
            (missed sudo nano /mnt/etc/fstab)

            so, after including that, I run the installation with following amendments:

            had to run following commands as sudo (I get permission error if I wouldn’t):
            sudo mount /dev/sda1 /mnt/boot/efi
            and
            sudo cp /etc/resolv.conf /mnt/etc/

            the instalation of grub in last step finished this time with following remarks

            grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won’t be possible.
            grub-install: warning: Embedding is not possible. GRUB can only be installed in this setup by using blockllist. However, blocklists are UNRELIABLE and their use is discouraged..
            grub-install: error: will not proceed with blocklist

            After reboot I still can’t see the external HDD to boot from.

            I tried this
            https://blog.hostonnet.com/grub-install-warning-this-gpt-partition-label-contains-no-bios-boot-partition-embedding-wont-be-possible

            to fix that, grub installed without errors – but still can’t boot. (etc can’t see HDD when booting)

            Any help here would be very appreciated – I’m fighting with this over a week. This is second approach to this. First I tried was (because that exactly computer I’m working with)
            http://www.jfwhome.com/2016/01/04/latest-steps-to-install-ubuntu-on-the-asus-t100ta/

            but that’s for internal emmc not for external HDD, so I ended here.

  26. Hi there.

    I finally got the opportunity to install Ubuntu on a 160 GB HDD, following the steps of your tutorial.
    At the end of the process I get Ubuntu boot when I select to boot from the external HDD, but the only problem I have is that before the Grub Menu appears, the following error messages appear:

    [code]error: file ‘/boot/’ not found.
    error: no such device: /.disk/info.
    error: no such device: /.disk/mini-info.[/code]

    Can you tell what is causing this error?
    Is there any solution?

    Best regards.

  27. Able to see uefi entry Ubuntu , boot into gnu grub, and doesn’t load Ubuntu system.. not able to proceed further, any help

    1. Obviously you didn’t follow all of the steps. Retry and make sure you don’t forget to do anything. Do NOT take creative license in interpreting the instructions in the blog post, do NOT skip instructions you think don’t apply to you. If there was something you could omit it wouldn’t have been included in the first place. And please make sure that you are careful with the disk and partition names.

  28. can u help me in my present condition, i followed the steps it went on smooth until this.. “mount /dev/sdXZ /mnt/boot/efi” it returned no such folder, so i manually created /boo/efi folder.. after that it went smoothly and completed installing grub. so now i am able to see two different uefi entires one for windows and one for ubuntu , windows is working as expected which i am very happy about, but if i choose uefi ubuntu it goes into (grub >) gnu grub prompt, i tried some commands there, ‘boot’ resulted in load kernal first, i also tried set root and set prefix commands.. no luck any suggestions to point the boot files from grub and boot to it.. NOTE: i have separate partitions for ‘swap’, ‘efi’, ‘/boot’, ‘/’. everything formatted in ext4 primary except the efi which defaults to fat32 and thanks for the tutorial.. a video tutorial will be much helpful any plans on that?

    1. The problem is that /boot/efi is a mount point where you are supposed to mount the EFI partition per the instructions. You didn’t do that because you skipped over an entire section. Then you created a folder by that name which is of course not visible by the UEFI firmware during pre-boot because it’s a folder inside an Ext4 partition, not a FAT32 partition itself.

      As I have written in a few comments above: do not skip any of the instructions, do not change their order. There is a reason why I’ve written all of that in a specific order 🙂

      So, the only thing you can do is start the process from scratch and this time be careful. If necessary, print out the instructions and use a highlighter pen to keep track of what you’ve done so far.

      1. thanks for replying, i tried some tools like supergrub2 and boot-repair, now i am able to boot and use it, maynot be as intended or depicted by this tutorial, but atleast i will be able backup if wanted and try ur procedure again to see where i went wrong.. thanks again

  29. I found the simplest way to install linux to a portable disk is to shut down the pc, disconnect all hard drives, boot from the usb, plug in the portable hdd, and go!

    1. No, you are wrong. Your solution only applies to machines you can tear apart and have non-soldered storage. It also does not make a portable installation. If you plug in that drive on another computer or if you plug in a different mix of drives on your machine it will fail to boot. It’s most definitely not portable. I will tell you everything that is wrong with what you wrote.

      For starters, you are missing the point that these instructions will be carried out primarily by people who have laptops which are a. under warranty or provided by an employer i.e. you can’t put a screwdriver on them; or b. use proprietary screws or glue; or c. have soldered-on storage or otherwise require taking apart the entire machine to reach the drive’s cable (or a combination of the above). In my case it was building the Ubuntu image on an Intel NUC. Not only it’s a pain in the rear opening up the tiny computer and removing the m2 drive, its capricious EFI also give you lots of issues when you change the attached drives. So, no, removing the drive is not the universally “simplest” solution.

      But let’s say this is not an issue. The biggest problem is that you are NOT doing a portable installation. The regular Ubuntu installation will result in an EFI System Partition which only works for the specific computer [i]and the specific device name[/i] your drive got during boot. Please [url=http://www.runscripts.com/support/guides/tools/multiboot-usb/grub2-install]read up on how grub2-install works and why –removable is all important[/url]. Right now your drive won’t boot on another computer, making it non-portable.

      I will give you an F-. Next time think why someone wrote a detailed article if there in an obvious “simplest” solution. Maybe the answer is that your “simplest” solution is actually broken in subtle but very important ways?

  30. Is it possible to use an efi bootloader manager like clover or rEFInd instead of using your solution?

    I tried to follow your tutorial but somehow i made a mistake and couldn’t make it work..

    1. I guess you can always try? Don’t ask [i]me[/i] how, though. The method I found to be working and the exact steps to reproduce it is documented in the article you are commenting on.

  31. I’m not sure how else to say this except that “you are a f’ing SUPERHERO”. I’d love to support any upcoming projects you might have in the works. Email me whenever you see this. For anyone interested in this tutorial, please note that I was very hesitant myself until noticing that the dev made a point to say that anything posted had been tried himself and that’s why his tutorials are so few and far between. Not to mention that everywhere else on the net remarks that this is simply impossible to accomplish. Bullshit! This tutorial is unbelievable in its accuracy and effectiveness! God Bless You my friend. Thank you ever do much!! You are the king in my book! Have a great day!

    I should mention that the only part that needs updating is that when arriving at the line where, in windows recovery steps, you have to do the command with /fixboot as the switch, the command fails with “Access denied”. The workaround is to do the following :

    Z:\>format Z: /fs:FAT32

    (erase the entire EFI partition which was assigned in a previous step to the arbitrary Z:, so in keeping with the example variables…)

    Then, simply,

    Z:\>bcdboot C:\windows /s V: /f UEFI

    (This replaces the Just initialized partition with a rebuilt data by the Microsoft command line tools).

    That is all, then continue with rest of steps as posted, word for word.

    Oh. I almost forgot…I was setting up external bootable for my Surface Book 2 with the target being Kali Linux 2018.1, so the only other minor detail was that at the very end, when installing the grub loader to the external IS drive using live Linux off of USB stick, in the paths, I had to replace
    >umount /dev/ubuntu/… With, simply,
    >umount /dev/root/…

    That’s really it!!

    Again, dev, you are a rockstar! This is amazing!! I can’t believe it’s working without issue whatsoever!!

    1. Thank you for your kind words 🙂 Yes, everything I post here is meticulously tested by yours truly. My blog is typically three parts field notes and one part prose. I am for quality, not quantity.

      Please do let me know how Kali works on your Surface Book. I have the older Surface Book and I was thinking of creating a Kali USB stick. My only hesitation has been that some stuff doesn’t work even in Ubuntu (obviously the touchscreen since the driver not in the official, therefore signed Kernel yet; sound was dead; built in keyboard and touchpad only started working in 17.04 etc). Also tell me which external Ethernet card you’re using because I’ve yet to find one which will reliably work in promiscuous mode.

      Now, regarding the fixboot switch, it requires Administrator privileges. I have a Win10 bootable stick from Anniversary Update. It is possible that MS changed something in between but I am incredulous. After all, how do you fix a bricked Windows installation if you are not allowed to fix the boot?! Then again, I was writing this tutorial based on what I was doing on a mid-2013 Intel NUC with Windows 10 Anniversary Update. It’s possible that Surface Book applies more strict controls over what you can do. I’m pretty sure there were UEFI options to that end.

    1. Your filesystem may have a problem and gets mounted read only. Why don’t you start in single user / repair mode and do a fsck to see where’s the problem? This is standard Linux admin 🙂

      1. Hi,

        It says that “Inodes that were part of a corrupted orphan list were found.”

        After I fsck, the system is still read-only.

        1. With the power vested to me by Google I present thee a thread relevant to your question https://forums.opensuse.org/showthread.php/467196-Error-corrupted-orphan-linked-list

          It only took me a few hours until I had the time to do that 2-minute search you could have done yourself. 

          Hint: if you see something you don’t understand on your screen search for it online. If you expect other people to do your homework for free you’re setting yourself up for some major disappointment in the long run. 

  32. For the step Fix Windows Boot, I use a software Disk Genius in Windows, delete the Ubuntu folder in Windows ESP partition, it works.

  33. Almost all the way through… But, when I try to mount sdxz as sudo mount /dev/sdXZ/ /mnt/boot/efi , an error pops up: mount: /mnt/boot/efi: mount point does not exist.

    I changed the difectory to mnt and saw it was empty. Any suggestions?

    1. The instructions right above that bit tell you how to mount your external disk into /mnt. You either didn’t do that or you got an error and you missed it.

  34. Thanks everybody.  I had an old boot of debian I think (It’s been a while since I loaded it), and it was just cloned to other drives using gparted, and later, a copy of partition guru, then power iso.  It was so versatile I had a few freelance techs using it to run cleanup\recovery opps whenever we needed to.  We loaded that, and a WinPE rescue disk onto several drives, allowing us to clean up most problems just before they hit the “sorry, it’s dead” stage.  Back then, we had a single tower with a P4 and a few gigs of ram.  A 1gb swap area was enough to be very fast by comparison to the winpe.  We had upgraded that one tower for a main software setup several times, as it ran ubuntu, winpe, and a full version of windows server 2012, which we used for running everything.  6 weeks ago, I took some time off, to handle family issues and school.  One of the newbees tossed the machine on the garbage heap.  So, I’ve decided that we’re all going to carry a drive with some system tools, and we’ll carry one of the working laptops for onsite work, rather than attempting to hook everything to a windows server running virtualboxes with winpe.  We’ll upgrade that machine again, but it will be for the most extreme cases.  Otherwise, working laptops with an i5 or better suffice.
    Your posts here were a great refresher, and an update in the use of EFI, thank you.  ALL of you.  And to add my two cents…
    SSD’s and usb drives are not meant as permanent storage.  They are less permanent than magnetic data at the moment, but are rapidly closing the gap.  They are meant for storage with fewer changes, but new drivers and controllers are allowing them to spread the workload out, stretching their lifespan.  They don’t succumb to as many bad blocks, but sectors will burn out, and you may have to repair an install once in a while.  For DATA, cloud and HDD RAID provide speed with longevity.  Cloud as a service lets somebody else worry about the maintenance, while you have constant access.
    In corporate, it’s a balancing act.  At home, I use an HDD for my data, and an ssd for system.

    1. SSDs are definitely meant for permanent storage the last 8 or so years. 15 years ago, no they were not. MLC flash storage suffered from electron bleed which could cause bit flips if the device was not powered on for over 1 to 3 years. Technology has progressed ever since and now it’s just as reliable as spinning disks as evidenced by its use in the data center and every single portable device save for cheap, crappy laptops.

      Now, USB sticks are a different issue altogether. The flash storage used there is not even near the level of a modern SSD and yes, they are neither as fast nor as reliable. That’s why I would NEVER use them for anything more serious than temporary storage or file transfer. But putting them in the same basket as SSDs is just plain wrong.

  35. I have tried that, it didn’t work. Even disabling the Secure Boot, selecting the external HD in the boot menu, the system hangs in a black screen.

    1. If you saw the GRUB menu the problem is probably that your hardware requires some kernel parameter. Google search is your friend. I remember that I HAD to use a parameter for my Intel NUC to activate the onboard graphics. I can’t check what it is now since that machine is currently at my vacation home.

      If you didn’t see the GRUB menu at all there are three possibilities. One, the EFI partition is not formatted as FAT32, is not marked as an EFI partition or does not contain the correct EFI binary. Check the instructions above carefully. Two, GRUB is not installed on the correct partition or the partitions you tell it to look for the kernels are wrong (hint: check the UUIDs in /etc/fstab and compare them with those returned by blkid). Three, everything is set up properly, the drive boots on another machine but your current machine is finicky / has a broken UEFI. My Intel NUC was giving me absolute hell with that. I had to unplug everything, wait 30″, hold down the power button and then plug in the power. Once in five tries it worked. The same drive was booting perfectly with my Slimbook Katana KDE and even with a SurfaceBook Pro. Go figure.

      Booting from USB is hard and mostly a crapshoot. The more you read about how it works the less plausible it sounds that it can ever work, at all…

  36. When I mount my newly made fat32 partition, there’s nothing in it. i set the flags and everything haha. am i missing a step?

    1. If you just created a brand new partition and formatted it as FAT32 it stands to reason that it has nothing inside it. Unlike EXT3/EXT4 partitions, FAT32 partitions don’t have a lost+found directory (in fact, that name would be illegal in a FAT32 partition) since they don’t have a feature for recovering lost inodes.

  37. Hi nick,
    great guide and amazing dedication to the comments section by the way.
    Im having trouble with the USB host controller.
    It seems your fix is missing from my HP envy’s bios settings :/ is there any other way to enable the xHCI on boot setting?
    Cheers

    1. It depends entirely on the firmware of your laptop. FWIW the NUC gave me grief half of the time I tried booting it up. Ironically, a Microsoft Surface Book and a Mac Mini I was also using this solution on didn’t bat an eyelid and worked the first time around. So I guess it’s just very hit and miss.

  38. Would remove the internal hard drive during the install make it easier? You wouldn’t have to fix Windows 10 partition that way.

    1. It depends on whether it’s possible to physically remove the drive (newer laptops have NVMe drives soldered to the motherboard) and how your UEFI firmware reacts to its main boot option being removed between cold boots. Please read the previous comments where I have discussed about it in length.

  39. Hi, NIcholas! I tried your instructions step by step, but it didn’t work for me. I was trying to install Ubuntu 18.04 on Seagate M3 1TB external USB HDD, and after a long fight, I found that the problem was actually in the size of the FAT32 partition that had to be created for the boot loader. It has to be [b]LARGER THAN 512 MB[/b], otherwise it won’t work. Here is what I did:
    1. I connected both the USB HDD and the USB flash drive with the Ubuntu startup burned on it to the computer (Laptop ASUS X55C).
    2. Started the computer. I had to press the “[b]Esc[/b]” button to see the boot menu; I chose “[b]UEFI: Udisk 8GB[/b]”, which is my Ubuntu 18.04 flash drive.
    3. I created new partition table (msdos) in the Seagate HDD using gparted, and since the Ubuntu installation partitioner kept going on with the annoying message that I hadn’t used the correct alignment, I made all the partitions needed for the installation with gparted. First, I made a logical swap of 16GB at the end of the freed space. Second, I made a primary 650MB FAT32 with boot, ESP flags at the beginning of the free space, and at last – in the remaining middle – an ext4 partition.
    4. After these actions, it was time (finally) to start the installer. When I was asked where to install, I chose “something else”. On the partition menu I found the Seagate HDD mounted as[b] /dev/sdb[/b]. /dev/sdb2 was my FAT32 recognized as EFI partition, /dev/sdb3 was my ext4 partition, and /dev/sdb1 was the swap partition. I order to set the mount point of the ext4, I had to select it and click “change” on the menu. Done.
    5. The final step: on the bottom of the partition menu, there is an applet where you choose, where to install the boot loader – I chose [b]/dev/sdb[/b] (the Seagate USB HDD). This is very important.
    6. Installation.
    After installation I restarted… ”Esc” button, and… YESSSS – a miracle! Finally I saw the long expected “UEFI: Seagate M3″… and it successfully booted!
    Before this success I got only “Seagate M3” on the menu, without “UEFI”, which wouldn’t boot at all.
    I hope this little clarification about the FAT32 partition will help someone, well – it’s working for me.
    Wish you all the best!

    1. It sounds like you put the entire /boot in the FAT32 partition which is wrong (but explains why you needed that much space). The FAT32 partition must be mounted to /boot/efi. You can either have a separate ext4 partition for /boot or just leave /boot in your root partition (as long as you are not using an encrypted disk, that is). /boot needs to be at least 512MB, ideally 1GB, in size since it holds all the kernels, GRUB2, initial RAM disks and a few odds bits and pieces. /boot/efi (the EFI system partition) needs to be FAT32 and can be as small as 100MB since it only holds the EFI stubs which kickstart the boot loader.

    1. This is irrelevant since you are installing on a new, blank USB HDD which you are formatting during the installation of Ubuntu. Your Windows installation, in the main HDD, has its boot configuration recovered after Linux is installed. This is basically 60% of this post, from “Fix Windows 10 boot” onward.

  40. Καλησπέρα, διάβασα το post σου για να στήσω τα ubuntu σε εξωτερικό σληρό (και με βοήθησε πολύ!). Τώρα θέλω να κάνω αυτό που στο installation των ubuntu ονομάζεται full system encryption και σου στέλνω γιατί δεν βρήκα πολλές πηγές online. Βρήκα αυτό αλλά δεν είμαι σίγουρος εάν είναι η ευκολότερη λύση να το κάνω έτσι (και αν θα πετύχει). Έχεις πειραματιστεί με κάτι σχετικό? Σκεφτόμουν ότι ίσως να μπορούσα να κρυπτογραφήσω όλο τον σκληρό αλλά δεν είμαι σίγουρος εάν θα μπορώ να κάνω boot τα ubuntu γιατί θα έχει κρυπτογραφηθεί και το efi partition..

    Χαιρετισμούς!

    1. Καλησπέρα! Δεν έχει κάποια διαφορά για το full disk encryption και ναι, το δοκίμασα και αυτό λόγω GDPR 🙂 Στην εγκατάσταση του Ubuntu πες του να στήσει encrypted LVM και προχώρα κανονικά. Δημιουργεί ένα ΜΗ κρυπτογραφημένο partition για το boot. Όσο για το EFI partition είναι πάντα μη κρυπτογραφημένο.

      Το full disk encryption λειτουργεί ως εξής. Το firmware της συσκευής ψάχνει το EFI parition. Από εκεί διαβάζει το EFI που ουσιαστικά είναι ένα shim, ένα μικρό πρόγραμμα που φορτώνει τον πραγματικό boot loader. Ο πραγματικός boot loader (GRUB2) βρίσκεται στο /boot. Πρέπει να είναι μη κρυπτογραφημένο γιατί ακόμη δεν έχουμε τρέξει κώδικα για την αποκρυπτογράφηση. Μόλις επιλέξεις Ubuntu από εκεί, ο GRUB2 προσπαθεί να φορτώσει τον kernel. Αν η συσκευή σου έχει ενεργοποιημένο το secure boot το firmware ελέγχει την υπογραφή του kernel. Αν η υπογραφή είναι έγκυρη (ή απλά δεν έχεις secure boot) ο kernel οφρτώνεται στην μνήμη, ξεκινάει το process 0 (kernel process) και φορτώνει το initial RAM disk από το μη κρυπτογραφημένο /boot. Μέσα στα πολλά που κάνει, το initial RAM disk φορτώνει το LUKS που σου ζητάει τον κωδικό σου. Βάζοντας τον κωδικό σου αποκρυπτογραφείς το (μεγάλο σε μέγεθος) κλειδί του LUKS το οποίο στην συνέχεια χρησιμοποιείται για να αποκρυπτογραφήσει τα δεδομένα του κρυπτογραφημένου partition. Στην συνέχεια αναλαμβάνει ο LVM (Logical Volume Manager) ο οποίος κάνει τον kernel να “βλέπει” εικονικά (γνωστά και ως “λογικά”) partition π.χ. το root partition, τυχόν swap κλπ.

      Το σημαντικό σε αυτή την διαδικασία είναι πως ο EFI loader, ο boot loader, ο kernel και το initial RAM disk είναι ΜΗ ΚΡΥΠΤΟΓΡΑΦΗΜΕΝΑ καθώς εκτελούνται στα στάδια προτεοιμασίας του συστήματος, πριν εκτελεστεί το LUKS. Ως εκ τούτου δεν σου δημιουργείται κανένα απολύτως προόβλημα με άλλα λειτουργικά. Το dual boot (συμπεριλαμβανομένου του boot από εξωτερικό δίσκο) με full disk encrypted Linux παίζει μια χαρά.

      1. Ευχαριστώ για την απάντηση! Δεν μπορώ να πώ στην εγκατάσταση του ubuntu να στήσει encrypted LVM γιατί δεν υπάρχει σαν επιλογή όταν επιλέγουμε “Something else”. Βρήκα [url=https://help.ubuntu.com/community/ManualFullSystemEncryption/DetailedProcess#The_stages]αυτό [/url]και έστεισα κρυπτογραφημένο system partition στο οποίο βρίσκονται τα boot,root και swap. Σε άλλο partition στον σκληρό έφτιαξα ένα efi partition το οποίο είναι μη κρυπτογραφημένο. Υπάρχει κάποιος τρόπος με αυτό το setup να κάνω boot?

        1. Κάτι αντίστοιχο έκανα [url=https://www.dionysopoulos.me/259-kubuntu-on-surface-book.html]εγκαθιστώντας το Kubuntu στο Surface Book μου[/url] τις προάλλες. Δες το “Prepare the disk encryption” και το “Install Linux and fix the disk encryption on the installed system” από αυτό το άρθρο. 

          Ο installer του Ubuntu / Kubuntu / Lubuntu / Xubuntu σκάει αν πας να του κάνεις manual dull disk encryption μέσα από το περιβάλλον του. Αν στήσεις το LUKS και το LVM με το χέρι πριν την εγκατάσταση παίζει μια χαρά. Το θεματάκι του είναι πως δεν φτιάχνει το crypttab και δεν ενημερώνει το initial RAM disk οπότε πρέπει να το κάνεις με το χέρι. Οι οδηγίες που έχω σε εκείνο το άρθρο παίζουν δοκιμασμένα και θα παίξουν χωρίς πρόβλημα και σε εξωτερικό δίσκο (η μόνη διαφορά εσωτερικού με εξωτερικό δίσκο είναι το τι κάνουμε στο EFI partition στην τελευταία περίπτωση). 

          Ελπίζω αυτό να βοήθησε!

  41. A question, if Un-plug or disabled in BIOS my main hard-drive, in order to isntall ubuntu on my external HDD, then I don’t need to do all of this right ? (i mean fixing windows boot, and creating the boot for ubuntu in the external hdd)

    1. No, this is NOT correct. Please see https://www.dionysopoulos.me/253-portable-ubuntu-on-usb-hdd.html#!/ccomment-comment=551

      You will definitely need to fix the EFI partition on the external drive. Also, depending on how your device UEFI firmware works, you MAY end up losing access to Windows completely.

  42. Hi,
    I have a similar issue to Debneil where it says the mount point doesn’t exist after trying to mount to /mnt/boot/efi in the EFI partition – however, I think I’ve done all the necessary steps to this point. I’ve included the prompts from fdisk, GParted, and the fstab file here:[url=https://imgur.com/a/36wrcqs] https://imgur.com/a/36wrcqs%5B/url%5D. I will note that there was no boot/efi in the original fstab file. Any help would be greatly appreciated, thanks!

  43. Nice guide. Gonna try this, this is exactly what I was looking for. Thanks for putting effort to write it.

    On the “Fix Windows 10 boot” rollback you probably meant

    “ren BCD.old BCD” and not “ren BCD BCD.old”

    Cheers!

  44. Hi, I do not understand this:

    sudo umount /media/ubuntu/01234567-89ab-cdef-0123-4567890abcde

    This means to unmount the external hdd / partition? Is it mounted now, in fact should we run gparted on mounted devices? It gives some denial message for me anyway.

    1. You only run GParted to find the UUID. You do not commit any operations so it’s safe to use. You can always use blkid on the command line to do the same. It’s just that GParted is simpler for people to understand.

      The umount is only necessary if Ubuntu automatically mounted the filesystem. The reason is that we need to mount the partition under /mnt so the rest of the instructions will work. If your partition is not mounted (check with cat /proc/mounts) you can continue with the mount command onwards.

      1. Thanks for the reply. The umount had failed in my case because the path was /media/xubuntu, which I really did not expect…

        Anyways, I have installed the distribution and it is there, but the last step, the crucial one, the creation of the boot loader partition, somehow did not work. I have received no error messages (I have followed the steps closely), but I seem to have the same problem as José Pedro Silva, /boot not found error is displayed on start-up. I can boot into the installation because the computer I did this on is dual boot and grub somehow replaced the original LINUX partition entry with the external disk entry. Now I do not know how to fix it other than trying the steps again, which did not work the last time. I do not suppose so, but if you had an idea, I would appreciate it.

        1. It looks like you selected the wrong location for installing the boot loader when you were installing on the external drive. Instead of the external drive you selected the internal and that caused the issue.

          Fixing it is possible, though not immediately obvious.

          Boot your computer from an Ubuntu installation flash drive. Open a console and do:

          [code]sudo su
          mount /dev/sdXA /mnt
          mount /dev/sdXB /mnt/boot
          mount /dev/sdXC /mnt/boot/efi
          for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/$i; done
          cp /etc/resolv.conf /mnt/etc/
          modprobe efivars

          chroot /mnt
          grub-install -d /usr/lib/grub/x86_64-efi –efi-directory=/boot/efi/ /dev/sdX
          [/code]

          Where:
          – /dev/sdX is your [i]internal[/i] hard drive, typically /dev/sda
          – /dev/sdXA is the internal hard drive’s root partition, typically /dev/sda2
          – /dev/sdXB is the internal hard drive’s /boot partition, typically /dev/sda1. If you do not have a separate boot partition skip that line.
          – /dev/sdXC is the internal hard drive’s EFI partition, e.g. /dev/sda3.

          You are mounting the internal drive’s regular Linux installation and putting yourself in a chroot jail. At this point your commands work as though you were booted into your regular installation. The final line installs GRUB2 on your [i]internal[/i] hard disk, overwriting the previously installed GRUB.

          1. I had actually thought that the forum had swallowed my last message, sorry for the late reply. I had not read the situation correctly, the boot loader was actually the one on the external hard drive, because my last desperate attempt was trying to run the chroot procedure from my dual boot system. Which for some reason worked, but the boot loader is identical to my dual boot one, which confused me. Anyways I now have working LINUX installation with some extra grub entries which suits me fine, some day may be I will learn how to prune them.

  45. Hi Nicholas, Many thanks for this instructions!

    I would suggest a shortcut to the procedure:
    – Choose to install Linux “somewhere else” (basically the menu option for advanced entries)
    – During the linux installation, create additionally a ~500MB participation and mark it as EFI
    – Select that EFI as the place where to install the Linux boot loader.

    After the Linux installation completes, you would still have to fix the windows EFI (bcd rebuild) but you would not need any additional step above.

    1. I’d like to point out that selecting the EFI partition of the external drive as the target for the boot loader during installation does not solve the issue that most computers will ignore it. So while it’s possible, it’s not a universal solution and that’s why I didn’t follow it. That and it makes it harder for me to explain in the article how to find the external drive’s EFI partition.

  46. Umesh Sharma
    First of all, thanks a lot for very informative article. I followed your instructions totally and installed Ubuntu 18.04.1 LTS on external HDD (USB3), the OS in my Dell laptop (EFI firmware) is Windows 10. Your solution works perfectly as long as I connect the external HDD on my Dell laptop, even with secure boot enabled. However, when I connect the same on my son’s HP laptop (HP envy 14-j106tx), also with EFI firmware, the disk goes into emergency mode and there is no way I can boot. It seems the solution works only on the machine on which the installation is made. I am not experienced with Linux, I read in an article (https://askubuntu.com/questions/847860/how-can-i-make-a-portable-ubuntu-installation-on-a-usb-stick-secure-bootable) where the solution given was as follows:

    How can I get secure boot working also on multiple machines?
    this command solved my problem now:
    grub-install –efi-directory /mnt/esp –boot-directory /mnt/rootfs/boot –target x86_64-efi –removable /dev/sdb –uefi-secure-boot
    this finally lets me boot on uefi systems with secure boot enabled. the only errors I get while booting is
    error: file ´/boot/’ not found.
    error: no such device: /.disk/info.

    I tried the solution given above; the command could be executed with my HDD plugged-in after booting through Live USB. But there was no success as far as portability is concerned and I get the same message on connecting to HP laptop. Any suggestions in this regard?

    1. I believe that enabling secure boot on a [b]portable[/b] device will break things because you are tying the boot to the exact hardware configuration at the time you created the boot loader. Portable installations shouldn’t do that, you want to be able to boot them anytime.

      I don’t know why the HP won’t boot it. Have you tried booting an Ubuntu installation disk? Maybe that will point you to the right direction for troubleshooting.

      1. I am able to boot through the Live Ubuntu USB on HP laptop, there is no problem there. I am not able to boot the installed USB HDD with secure boot enabled. I accept your contention that with secure boot enabled the portability may not be possible.

        I wish to clarify two doubts. In your procedure, you are creating EFI partition after installation of Ubuntu. Are you suggesting to do the initial installation in legacy mode? Second doubt: is it not better to make EFI partition while making other partitions, what is the advantage in shrinking the root partition after Linux installation to create EFI partition?

        1. When I wrote the article the Ubuntu installer would detect the EFI partition on the main drive and install its EFI stub there.

          Remember that the EFI System Partition (ESP) and the boot volume (what is mounted on /boot) are NOT the same and have a different purpose in life. The device firmware looks in the ESP of each attached hard disk for EFI stubs. These are presented in the device’s boot menu. The GRUB EFI stub (installed by Ubuntu) will find your boot partition and load GRUB from it. GRUB will then present its own boot menu. Once you make a selection, GRUB loads the kernel (vmlinuz) and mounts the initial RAM disk which initializes the system and its devices etc.

          While you can create an ESP in the Ubuntu installer it’s not necessary that this is the one which will be used, i.e. the one where Ubuntu will install its EFI stub. Even if it does, it installs a regular stub which is NOT meant for removal drives. So you’d still need to follow the advice to enter the chroot jail on the external installation and install GRUB with the –removable option.

          That bit would be very difficult to describe. The only people who’d get it are the ones who don’t need to read this article. Therefore I chose the easy method of describing how to create an ESP on the external drive after the fact.

          Predictably, people try to be “smart” and do things differently than I described without understanding or researching the repercussions. Little wonder people end up telling me “it doesn’t work for me, oh by the way I did Y instead of X”. Yeah, sure, you can create an ESP during installation but if you don’t reinstall GRUB with the –removable option it will only ever work on the machine you originally built the installation since you don’t have a [i]removable media[/i] EFI loader. If you had Secure Boot enabled it will also not work anywhere else because you’re locking the boot loader to the specific hardware configuration; if it changes it invalidates the boot loader. If you don’t have Windows the instructions won’t work because the installer is likely doing something silly, like replacing your main installation’s boot loader with its own. If you unplug your main hard disk it might not work because you are neither reinstalling GRUB with the –removable option nor do you account for most machines recording the new ESP in their NVRAM, breaking your main installation. I have run into these problems and that’s why I don’t do any of that.

          Follow my instructions to the letter and everything works. I have done that three times with different machines and SSDs. I know these instructions work, if you actually follow them.

          1. thanks for very detailed and informative reply. As I wrote in my first post, I did exactly as per your instructions and everything worked. The doubt why not create the ESP partition while creating other partitions was only due to the fact that it is easier and faster to create an additional partition when all the other partitions are empty compared to carving out a partition from the root partition which has system already installed on it. I accept your reply and the matter ends here.

  47. Great tutorial, I think, but I have a very preliminary issue.  I cannot get Ubuntu installed on the SSD.  I keep getting an offset from the beginning of the drive, which results in an error message “the partition assigned to “/” starts with an offset …[i]please go back and fix[/i]”. Gparted can delete the offset, or at least it does not show, but the installer recreates it, result can’t install.  Any suggestions. Thanks.

      1. Okay, got that problem solved.  I had to use an external partition program to set up the ssd, no problem.  Installed Ubuntu, seemingly no problem.  Worked well in its installed state.  However, when I shut down, there was no impact on the windows bootmanager. Booted into windows with, or without, ssd connected.  Should I go ahead and make the changes in Ubuntu on the ssd, or would they be futile?  Thanks for your help.  I’m an old, old dog trying to learn new tricks — think Commadore 64.

        1. Yes, you need to make the Ubuntu changes to the SSD. This is what makes it bootable on other computers as well.

  48. I wondered if all the hassle would be avoided if I disconnected the internal hard drive of an old computer (not the one I plan to use the drive on often) that had windows 10 on it. If the only drive the computer recognizes is the external one, then would GRUB be installed on the drive like normal? That is just using the “normal install” option on the drive. or would i have to create a swap, root-home, and efi partition with grub, etc. And would this approach still work on any computer, fully portable? I would love to here your response, as I don’t want to be using the virtual machine for class any longer and am worried about the process you detailed adversely affecting any of my machines

      1. well if that doesn’t work apparently, then can i do the tutorial steps on said old windows pc  and still be able to use it everywhere?

        1. Considering that this is quite literally what the post describes and that I am actually posting this from the bootable portable installation attached to a different computer than the one I originally used I would say that yes, it will work.

  49. Did the whole tutorial from start to finish, everything seemed to work fine, the drive booted from the pc with no problems. however when i try to boot it from the computer i plan on using it on (the other was an old pc i didn’t care to do the process on) i get a multitude of ACPI errors. after these errors the shell reads “you are in emergency mode. after logging in…etc” “press enter for maintenance (or press control-d to continue):”. i would like to know what this means and how i can fix it, as i feel i was so close to getting it to work.

  50. Hi Nicholas, I followed all the steps in the post and succesfully installed the bootloader on the HDD, but when I try loading ubuntu from it, an error pops up that say: Linpus lite boot failed.
    I have no idea why is this coming up. Please help.

    1. My blog post is written about Ubuntu. I have not used Linpus Lite. The only thing I understand from the message is that you have probably not updated /etc/fstab with the UUIDs of your partitions.

  51. It is probably an issue with the BIOS of my system. I used the same HDD on other system and it booted perfectly. No Linpus Lite error or anything. I have updated the BIOS on my system but still can’t boot it from there. Any suggestions ?

    1. If it’s a hardware issue you probably need to look at the computer manufacturer’s site for more information.

  52. Hello Nicholas!

    Thank you very much for all your work and responses!

    I have just one question:
    Is it possible to circumvent the Windows-fixing-boot issue, if I do the whole procedure on a Linux machine in the first place?

    1. Yes, of course. That step is only required when you carry the procedure on a Windows machine. If your machine is Linux you don’t need to do that.

  53. It works!!! thank you so much!!!

    My experience in fixing Windows 10 boot: I boot Win10 and then restart Win10 holding SHIFT key. Wait with SHIFT hey down until blue screen appears with some options. click on Troubleshoot > advanced options > command prompt. ([url=https://www.digitalcitizen.life/4-ways-boot-safe-mode-windows-10])

    Once in the windows command prompt I follow your instructions:
    “:>bootrec /FixBoot” –> trowed me “Access denied”

    But then I run
    :>ren BCD BCD.old
    :>bcdboot c:\Windows /l en-us /s z: /f All

    And this works like a charm!

    1. I am confused as to why you are complaining that doing something other than what I wrote in the article didn’t work. I clearly say “Boot from the Windows system repair disc USB drive (or a Windows installation or rescue CD-ROM / DVD-ROM)”. I do not say “click on the Windows start button and choose command prompt” which is what you did and of course won’t work because you’re not using an elevated (Run as Administrator) command prompt.

      Thank you for confirming that the right way to do it is actually following my instructions. Holding down SHIFT on boot and choosing Troubleshoot does, in fact, start Windows System Repair from the hidden partition on your disk — if there is one to begin with.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.