Virtualization on the command line with KVM

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Boot Orders

The virtual machine always tries to boot from the first hard disk. If you want to boot from the CD drive, you need to specify the -boot once= option at startup, as in the following example:

$ qemu -cdrom ubuntu.iso -m 1024M -boot once=d my_img.img

The d refers to the CD/DVD drive, whereas c would select the first hard drive instead. Combining the characters with the -boot order option gives you a permanent boot sequence in the order indicated:

$ qemu -cdrom ubuntu.iso -m 1024M -boot order=dcn my_img.img

The virtual machine thus would always boot first from the optical media, then the first hard disk, and then look via Etherboot and PXE in the network for a bootable system. PXE, which stands for Intel Preboot Execution Environment, is the protocol for booting an operating system off the network. Etherboot is a GPL-licensed PXE implementation.

External Drives

If you want to use a USB device connected to the physical machine, you need to reach the host system in several steps. First, use the lsusb command on the host system, which provides a list of all attached USB devices (Figure 6). Find the device and jot down the Bus and Device at the beginning of the line.

Figure 6: To get at a USB device, keep track of the Bus and Device numbers.

In Figure 6, for example, the USB stick is on the line with Bus 001 and Device 003 for the Flash Drive. You then specify these values when you start the virtual machine, as follows:

$ qemu -cdrom ubuntu.iso -m 1024M -boot once=dcn my_img.img -usb -device usb-host,hostbus=1,hostaddr=3

The -usb option activates the USB support and you specify the device name after it. The usb-host is the USB device on the host and the bus and device numbers are after hostbus and hostaddr , respectively. You can also "plug" the USB device into a running virtual machine. Change to the monitor and use the usb_add command (Figure 7).

Figure 7: Add the device in the monitor…

The command has the general syntax usb_add host:<Bus>.<Device> , so the USB stick example would be as follows:

(qemu) <usb_add host:1.3>

For QEMU to reach the physical USB device (Figure 8), it has to access the device file. If it can't, a flood of error messages start appearing, in the manner of /dev/bus/usb/001/003: Permission denied . In such a case, it's easiest to start QEMU as root instead of a normal user.

Figure 8: …and access it from the virtual machine.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content