Using Multiple Disk Images in QEMU

HardwareLinux

QEMU by default lets you use 4 "hard drives", or simulated devices, as hd[a-d], with the virtual CD-ROM taking up hdc if you start the emulator with a CD-ROM image.

Here's another way to get more disk drives, use QEMU disk images (created with qemu-img) as USB disks. Why would you want more than 4 disks you ask? It would make a great setup for testing/learning/playing with LVM and/or disk mirroring/concatenation.

USB support has not always been available in QEMU, make sure you install the latest version (0.8.2 was the latest at the time this story was written, 21Aug2006). According to the QEMU website, the first version of QEMU with USB support is 0.8.0.

When you start QEMU, make sure you specify the -usb option to enable USB support. Inside the QEMU monitor, you can type info usb to verify USB support works. If USB support is working, you'll get a list of connected USB devices connected to the running QEMU virtual machine, or an empty list if you currently have no USB devices attached in the QEMU session. If you missed turning on USB support (via the -usb option to QEMU), your error message will look like this:

(qemu) info usb
USB support not enabled

Create the disk images with:

$ qemu-img create -f qcow demo1.qcow 100M
Formating 'demo1.qcow', fmt=qcow, size=102400 kB

Create a bunch of those, then use LVM or another tool that lets you mirror/concatinate volumes to simulate multiple disks. I think the limitation you would hit as far as the number of USB virtual disks would be 16, that being the maximum number of partitions allowed on SCSI disk devices in Linux, which is what Linux uses to connect USB disk devices to the system.

Here's a sample QEMU startup script with a Debian CD image on the emulated CD-ROM, some gratuitous network redirection, and a bunch of USB disks created using the above qemu-image command:

/usr/local/bin/qemu \
-cdrom /local/mnt/ISOs/debian-31r2-i386-netinst.iso \
-pidfile qemu.pid -monitor stdio \
-boot c -localtime -redir tcp:22222::22 \
-usb \
-usbdevice disk:demo0.qcow -usbdevice disk:demo1.qcow \
-usbdevice disk:demo2.qcow -usbdevice disk:demo3.qcow

Once you have QEMU up and running on the host with your guest OS, use the following commands in the QEMU monitor to mount disk images created with qemu-img:

(qemu) usb_add disk:demo4.qcow
(qemu) info usb
  Device 0.2, Speed 12 Mb/s, Product QEMU USB MSD(demo4.qcow)
(qemu) usb_del 0.2
(qemu) info usb
(qemu)

Use the partitioning tools of the guest OS to partition and format the new "hard drives" once you attach them.

The Current Terror Alert Level is...
Terror Alert Level

All content is © Copyright 2013 by Brian Manning, unless otherwise noted. See Site Credits/Categories pages for website and image credits.