27

I am trying to get qemu-kvm to boot from my live usb stick. Is this possible?

22

qemu-kvm -hdb <device>, where <device> is the USB stick (e.g. /dev/sdb), should do it (tested with Ubuntu 12.04 on an USB stick and it works).

You will need write permission to the device (i.e. be root or change its permissions).

  • 2
    Good answer. BTW if you need an easy interface to manage your VMs, give virt-manager a try. – wazoox May 2 '12 at 21:19
  • 1
    Just as a hint: I tried VirtualBox instead of kvm to test my live usb stick, and it's A LOT faster. You have to use this command as root to create a vmdk file to be used in VirtualBox: VBoxManage internalcommands createrawvmdk -filename .VirtualBox/HardDisks/usbdisk.vmdk -rawdisk /dev/sdb – Marc MAURICE Mar 17 '13 at 8:37
  • 4
    Just a small note to self here - use the disk/device node in -hdb (e.g. /dev/sdb); NOT the partition (as in /dev/sdb4) – sdaau May 28 '13 at 14:10
  • In order to avoid a warning message WARNING: Image format was not specified for '/dev/sdb' and probing guessed raw. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted. Specify the 'raw' format explicitly to remove the restrictions. you can specify options in this format: -drive file=/dev/sdb,format=raw,index=0,media=disk See this question – Ashark Mar 8 at 2:35
24

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.)

/iaw

  • Thanks, needed this to auto boot a build of bin-x86_64-efi/ipxe.usb for a EFI boot, and it worked without issues so far. – NiKiZe Jul 27 '17 at 18:55
  • Can you please update your answer? I got the following: qemu-system-x86_64: -usbdevice disk:/dev/sdb: '-usbdevice' is deprecated, please use '-device usb-...' instead – Ashark Mar 7 at 23:50
8

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.

  • As for me, passing usb stick as a hdd drive works correctly for me, but passing usb stick as a usb device with -boot menu=on 1) in bios mode allow me to choose it, shows syslinux menu (I flashed archlinux iso to usb stick with dd) and it starts loading, but fails with Waiting 30 seconds for device /dev/disk/by-label/ARCH_201903 ... sd 2:0:0:0 [sda] Assuming drive cache: write through print_req_error: I/O error, dev sda, sector 0 Buffer I/O error on dev sda, logical block 0, async page read ERROR: '/dev/disk/by-label/ARCH_201903' device did not show up after 30 seconds 2) in uefi it fails – Ashark Mar 8 at 3:38
1

If you want to use an image of a liveusb, instead of a physical USB stick, you can do that with

$ kvm -usbdevice disk:/path/to/liveusb.img -boot menu=on ...

Without "-boot menu=on", kvm will always prefer the hard drive that you set with "-drive" or "-hd[a|b|c|d]".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.