I am trying to get qemu-kvm to boot from my live usb stick. Is this possible?
qemu-kvm has disappeared. use the hint in start qemu by giving it a path to a linux root instead. this means
qemu-system-x86_64 -usb -usbdevice disk:/dev/sdb
where /dev/sdb is your raw device (not partition) of the usb stick that you want to boot.
(however, as of 12/2014, it's been flaky for me. booting ubuntu-gnome 14.10 results eventually in a kernel panic on a stick verified to boot just fine on the metal.)
I don't know why exactly, but Renan's answer didn't quite work for me. KVM said to me it couldn't find a bootable drive (despite the usb partition being marked as such).
However I've found another solution. Get the USB device VendorID:ProductID with lsusb. Example:
$ lsusb ... Bus 002 Device 007: ID 0781:5406 SanDisk Corp. Cruzer Micro U3
Pass that to KVM, and ask for the boot menu:
sudo kvm -m 512 -smp 1 -drive file=/path/to/hardisk/file.img -usb \ -usbdevice host:0781:5406 -boot menu=on
Press F12 for the menu, choose the usb device, it works. There's probably a way to command the usb boot without needing to call the boot menu, but I didn't find any in man kvm.
I did this by first creating a guest using e.g. virt-manager, then editing the virsh config file to boot from USB:
Edit config file for the vm:
# virsh edit TAILS
<boot>element from the
<os>element. (Leave the rest of the
<os>element intact.) You can't use
<boot>here, because the boot order will be specified in step 4.
Get the vendor and product ID for the USB device that contains the live system:
# lsusb -v | grep -E '\<(Bus|iProduct|bDeviceClass|bDeviceProtocol)' 2>/dev/null
This produces output like:
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive bDeviceClass 0 bDeviceProtocol 0 iProduct 2
The vendor ID is the first four hex digits after 'ID' on the first line,
090c in this example. Product ID is the last four hex digits after the colon, here
- In the virsh editor, add a
<hostdev>element for your USB device, inside the
<devices>element (which should already exist). Detailed instructions/examples for this element are at https://libvirt.org/formatdomain.html#elementsHostDev.
lsusbgives the values in hexadecimal, so use the
0xprefix unless you want to convert the values for some reason.
<devices> <hostdev mode='subsystem' type='usb'> <source startupPolicy='mandatory'> <vendor id='0x090c'/> <product id='0x1000'/> </source> <boot order='1'/> </hostdev> </devices>
- Save and exit virsh editor, and boot the VM in the usual way. (I'm using virt-manager, but a command-line boot uses the same config file.)
To emulate USB storage, attached to an USB port, that can be inserted and removed and will be seen as an USB device instead of a SATA hard disk (like -hdb does), use:
$ qemu-system-x86_64 \ -device piix3-usb-uhci \ -drive id=pendrive,file=<disk.img>,format=raw,if=none \ -device usb-storage,drive=pendrive \ -boot menu=on
Replace <disk.img> with some USB disk image. Then to connect and disconnect the pen drive while running the VM, on the running qemu instance console:
(qemu) device_del pendrive (qemu) drive_add 0 id=pendrive2,if=none,file=<disk2.img> (qemu) device_add usb-storage,drive=pendrive2