July 31st, 2016

Hard Stare

Installing Linux onto a USB key

Something I seldom see mentioned, but I use a lot, is Linux systems installed directly onto USB sticks (pendrives).

No, you can't install from these, but they are very useful for system recovery & maintenance.

There are 2 ways to do it.

[1] Use a diskless PC, or disconnect your hard disk.

This is fiddly.

SUSE has some info on how to do this.

[2] Use a VM.

VirtualBox is free and lets you assign a physical disk drive to a VM. It's much harder to do this than it is in VMware -- it requires some shell commands to create, and other ones every time you wish to use it -- but it does work.

Here's how:


Read the comments!

Every time you want to run the VM, you must take ownership of the USB device's entry in /dev


chown lproven:lproven /dev/sdc

N.B. This may require sudo.

Then the VM works. If you don't do this, the VM won't start and will give an unhelpful error message about nonexistent devices, then quit.

(It's possible that you could work around this by running VirtualBox as root, but that is not advisable.)

The full Unity edition of Ubuntu 16.04 will not install on an 8GB USB key, but Lubuntu will. I suspect that Xubuntu would also be fine, and maybe the Maté edition. I suspect but have not tested that KDE and GNOME editions won't work, as they're bigger. They'd be fine on bigger keys, of course, but see the next paragraph.

Also note that desktops based on GNOME 3 require hardware OpenGL support, and thus run very badly inside VMs. This includes GNOME Shell, Unity & Cinnamon, and in my experience, KDE 4 & 5.

Installation puts GRUB in the MBR of the key, so it boots like any other disk.


  • Partition the disk as usual. I suggest no separate /home but it's up to you. A single partition is easiest.

  • Format the root partition as ext2 to extend flash media life (no journalling -> fewer writes)

  • Add ``noatime'' to the /etc/fstab entry for the root volume -- faster & again reduces disk writes

  • No swap. Swapping wears out flash media. I install and enable ZRAM just in case it's used on low-RAM machines: http://askubuntu.com/questions/174579/how-do-i-use-zram

  • You can add VirtualBox Guest Additions if you like. The key will run better in a VM and when booted on bare metal they just don't activate.

I then update as normal.

You can update when booted on bare metal, but if it installs a kernel update, then it will run ``update-grub'' and this will add entries for any OSes on that machine's hard disk into the GRUB menu. I don't like this -- it looks messy -- so I try to only update inside a VM.

I usually use a 32-bit edition; the resulting key will boot and run 64-bit machines too and modern versions automatically run PAE and use all available RAM.

Sadly my Mac does not see such devices as bootable volumes, but the keys work on normal PCs fine.

EDIT: It occurs to me that they might not work on UEFI PCs unless you create a UEFI system partition and appropriate boot files. I don't have a UEFI PC to experiment with. I'd welcome comments on this.

Windows can't see them as it does not natively understand ext* format filesystems. If you wish you can partition the drive and have an exFAT (or whatever format you prefer) data partition as well, of course.

I also install some handy tools such as additional filesystem support (exFAT, HFS etc.), GParted, things like that.

I find such keys a handy addition to my portable toolkit and have used them widely.

If you wish and you used a big enough key, you could install multiple distros on a single key this way. But remember, you can't install from them.

I've also found that the BootRepair tool won't install on what it considers to be an installed system. It insists on being installed on a live installer drive.

If you want to carry around lots of ISO files and choose which to install, a device like this is the easiest way: