Installing Ubuntu on a USB stick with QEMU-KVM

The more I learn about QEMU the more uses I find for it. Today I needed to install Ubuntu onto a USB memory stick. My normal process for doing such a thing is simply to create a bootable usb stick using usb-creator with the command:


What that gives you is a FAT32 formated usb with the Ubuntu installer and an option to “Try Ubuntu”. What I was after was to use the USB stick as a regular hard drive, formatted as normal with EXT4 and install Ubuntu on that. After a little headscratching I realized KVM would be perfect for this. Tell it to use the USB device file as the hard drive and the Ubuntu install ISO as the CDROM. Here is the command:

sudo kvm -hdb /dev/sdb -boot d -cdrom ~/Downloads/ubuntu-12.04-alternate-amd64.iso

The -boot flag identifies the device it should boot from with “d” being the shorthand for the first CD drive while -cdrom allows you to specify an iso to use as a disk. The really cool part of this is the -hdb flag that points to the device file for the USB drive. Slap the enter button and you are off to the races.

Having the flexibilty to do stuff like this is really awesome and saves me not only time but diskspace too, since I don’t need to keep creating Virtualbox VM’s. I’m going to have fun learning more about this.

One thought on “Installing Ubuntu on a USB stick with QEMU-KVM”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s