How to install Ubuntu to a USB key? (without using Startup Disk Creator)
Tags: ubuntu, system
Published: 2021-11-25 10:07:22

---
title: How to install Ubuntu to a USB key? (without using Startup Disk Creator)
published: true
date: 2021-11-22 11:57:38 UTC
tags: Ubuntu,system
canonical_url: https://stackallflow.com/ubuntu/how-to-install-ubuntu-to-a-usb-key-without-using-startup-disk-creator/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">system-installation</span></p>
</header>

> If you are hurrying to reply, System → Administration → **StartUp Disk Creator** — no, that’s not what I’m talking about.

I want to try Ubuntu 11.04’s Unity without touching my existing Ubuntu install.

To do this, I need to install the nVidia drivers first (sigh).

To do this, I need changes to persist a reboot.

To do this, **I need to _really_ install Ubuntu on a USB key.**

How do you do that?

* * *

## What I tried

1. I tried to make a USB key from [Testdrive](https://launchpad.net/testdrive), then boot from it, then choose “Install Ubuntu.” The installer refused to install to the installation media itself.
2. I tried, from my installed copy of Ubuntu:
```
sudo kvm /dev/sdb --cdrom .cache/testdrive/iso/ubuntu_natty-desktop-i386.iso

```

…but the installer didn’t detect the disk properly.

#### Accepted Answer

## Ubuntu/Linux solution

## 1. Obtain latest image

You should do this with [testdrive](https://launchpad.net/ubuntu/+source/testdrive) [![Install testdrive](https://hostmar.co/software-small)](http://apt.ubuntu.com/p/testdrive).

![TestDrive](https://i.stack.imgur.com/Rj1n8.png)

**Note.** If your key is smaller than 4.4 GB (for Ubuntu 11.04 (Natty Narwhal)), you **must** get the alternate installer. The Desktop installer refuses to continue if there is less than 4.4 GB of free disk space.

## 2. Format the USB disk.

This is important if you already have anything looking like a Linux install on your disk, or the installer will not want to touch that disk, for some reason. I failed earlier because I didn’t perform this step, so skip at your own risk! You need a key that is at least 3 GB in size.

You can do so from _System_ → _Administration_ → _Disk Utility_. Choose the destination USB key, unmount all partitions, and select _Format Drive._

![Disk Utility](https://i.stack.imgur.com/wNNA7.png)

You need to make sure you select “Don’t Partition” before it lets you format the disk.

![Format drive window.](https://i.stack.imgur.com/gkwf2.png)

## 3. Start a virtual machine on the USB key

I made sure (with `file`) that my USB key was in `/dev/sdb`, then ran:

```
sudo qemu-system-x86_64 /dev/sdb -cdrom ~/.cache/testdrive/iso/ubuntu_natty-desktop-i386.iso

```

…to install the i386 ISO of the Natty Narwhal desktop — the file name will vary if you download a different ISO image.

Details for your virtualization solution of choice will vary, but you want to use the _device file_ of your USB key as the VM’s hard drive.

Append `-boot order=d` to the kvm command to make it boot from the image in case it tries to boot from the ‘hard disk’ and fails because it cannot find an operating system there.

## 4. Install normally.

At this point you are working on a virtual machine that sees your USB key as the only connected hard drive. From inside the “QEMU” window, install as you would normally do.

A few notes:

- **Partitioning.** Avoid using the automatic partitioning system, as it will create a swap partition on your USB key. That’s no good, as swapping becomes _super_ slow (seconds-long system freezes slow) and quickly kills your drive’s life. Simply allocate a single partition for `/`. If you’re using the alternate installer, make sure you set the `noatime` flag to further reduce the amount of writes to the disk.
- **Updates.** Skip the option to automatically download and install updates. It is not guaranteed that the repositories will be in a consistent state by the time you run the installer. Personally, I’d rather manage the upgrades manually with a tool such as [aptitude](https://help.ubuntu.com/8.04/serverguide/C/aptitude.html) (which does no longer ship with Ubuntu by default).
- **Alpha-quality software.** Things are a little wonky — it is alpha quality software, after all. I had `dpkg` exiting with error code 1 without being able to review the error – no packages were broken as a result, however. I tried to shutdown the virtual machine cleanly after the setup, but it hung. On a reboot, however, the system booted fine.

## 5. Reboot and boot into your copy of Ubuntu

You may need to fiddle with your BIOS settings to make this work.

* * *

A nice (or annoying, based on your use case) thing about Ubuntu on a USB is that next time it’ll refresh GRUB, it’ll also detect and add to the list the kernels and operative systems on the HDD. This should let you boot straight into your HDD from your USB key’s GRUB.

The post [How to install Ubuntu to a USB key? (without using Startup Disk Creator)](https://stackallflow.com/ubuntu/how-to-install-ubuntu-to-a-usb-key-without-using-startup-disk-creator/) appeared first on [Stack All Flow](https://stackallflow.com).