After many, many failed attempts, I finally got this working, and nonetheless in a very convenient fashion. I also got the flash drive Ubuntu running within VirtualBox, so I can administer it from the comfort of my host machine's OS. Awesome.
What Went Wrong
I made a number of attempts using two flash drives, one as the install disk, one as the target disk. None of these attempts worked.
- Following this guide: Ubuntu Desktop with manual partitioning. 16GB FAT32 mounted to
/UDISKas the first partition, 16GB ext4 mounted to
/as the second partition. "Device for boot loader installation" set to the disk itself,
/dev/sdb. Failed to produce a bootable drive.
- Same thing, but with "Device for boot loader installation" set to the second partition, the one mounted at
/. Same result.
- Following this kid (you really should watch a bit of the linked video, it's kind of awesome): Ubuntu Desktop with manual partitioning. Whole 32GB drive allocated ext4, mounted to
/, bootloader installed to
/dev/sdb. Failed to produce a bootable drive.
- Following this excellent guide, but using two flash drives, to install Ubuntu Server actually worked! And no manual partitioning was required, I just hit "Use entire disk and set up LVM" as specified in the guide. But it also messed up the UEFI settings on the host machine, which was fun to try to fix (for the curious, this is a fantastic piece of writing about UEFI). In the comments of this guide the guy mentions that he used a virtual machine, which led me to
- Following this guide to install from ISO running on QEMU as a virtual machine. This was my first attempt at doing a single-USB install. I wasn't, however, ever able to penetrate the labrynth of arcane errors QEMU produced en route to actually running the installer ISO.
I'm going to explain how to install Ubuntu to a flash drive, and then how to administer it, all using VirtualBox.
You only need one computer, and one flash drive. I'm running Ubuntu 18.04, and installing Ubuntu Server 16.04 on a USB 2.0 flash drive. YMMV with other combinations, but I wouldn't be surprised if this works for many other OS permutations. Note that, once you're set up with Ubuntu Server, you can easily switch to Ubuntu Desktop.
Also, I hear it can be done with a USB 3.0 flash drive, but VirtualBox won't like it, so you'll need a 3.0-to-2.0 adapter.
Download your ISO
Set up VirtualBox
We'll need to install virtualbox and add your user to two groups,
Security note, verbatim from here: Adding your user to the disk group can be dangerous and a security risk. It is as dangerous as having sudo access to write to a raw disk.
vboxusers is needed to connect to USB drive at all.
disk will be needed later, when we want VirtualBox to boot from the drive. If you don't intend to boot from the drive in VirtualBox, omit that command.
sudo apt-get install virtualbox sudo usermod -aG vboxusers $USER sudo usermod -aG disk $USER # see security note above
Install the VirtualBox Extension Pack for support for USB 2.0 and 3.0. USB 2.0 devices will work without it, USB 3.0 won't.
Open VirtualBox and follow the first 1:55 of this video. If you added the extension pack, make sure to tick "USB 3.0" in the USB section of the VM settings. This will work even if you're not using a USB 3.0 device.
If your machine boots and works like in the video, amazing! That didn't happen for me. I ran into a lot of problems.
The first problem for me was that Virtualbox coudn't find my USB devices, which we've mitigated already by adding your user to the
I don't remember what order the next two problems came in, but I imagine you'll see both:
- Kernel driver not installed. As seen here. I followed these instructions, which worked flawlessly for me, allowing me to eventually run
sudo modprobe vboxdrv.
- VT-x is disabled. I guess that's shorthand for virtualization. Stack Overflow says we need to enable virtualization, or turn down the memory allocation setting for our box. I did the former, which I found out how to do by Googling "enable virtualization on HP Spectre." Substitute your computer make and model as appropriate.
Okay, at this point, after like six restarts, I had VirtualBox booting the installer.
Install Ubuntu to your flash drive
This is actually really straightforward. Once VirtualBox was set up and running the installer, I just followed the instructions in the aforelinked guide exactly. VirtualBox doesn't have access to your host machine's drive, so the Ubuntu installer can't possibly screw it up.
Congrats, you have Ubuntu on a flash drive now.
I tried and failed to get this to work using Plop Linux Live, as is suggested here. It's an amazingly annoying OS, and it invariably failed to boot from my USB drive with
failure writing sector <some hex code> to hd0. Don't bother! You don't need to download anything!
I got it working by following this guide. It's the secret Ubuntu version of equivalent instructions for Windows that are plastered around the internet. If you followed the instructions above, your user is already in the
disk groups, which are mentioned in the guide.
I hope all this worked for you!