KVM, as it is based on qemu, emulates the hard drive as /dev/hda, via an IDE adapter. However, my images (taken from a real machine) assume the boot drive to be /dev/sda. This can ofcourse be changed, but since that information is embedded deep in to the initramfs being used for the kernel, and I still want to be able to boot the image on real hardware as well, I'd rather not touch it.

Is there any way for me to get the drive to show up as /dev/sda instead of /dev/hda?

(Also, Xen is a possibility for me, but Xen + HVM shares the same problem, as it uses qemu hardware emulation as well.)

  • You must be virtualizing a very old Linux system, as any Linux kernel released since the time you originally posted this would already label (virtual or real) IDE disks as /dev/sda et seq. – Michael Hampton Feb 25 '13 at 10:19

While QEMU is able to emulate a usb-storage device, AFAIK, it is not able to boot directly from it. KVM should be similar. One other option that I would recommend for you is this. I'm not sure if it will work as I have not tried it myself by it probably would.

Use your drive image as a usb-storage device. However, boot by specifying the kernel and initrd directly on the command line. So, something like this:

kvm -kernel <kernel image> -initrd <initrd image> -usb <usb options> ...

To make the emulation more accurate, you should use the kernel and initrd images extracted from your drive image. This will boot your kernel, which should have the USB drivers built in to detect /dev/sda and then load your initrd, which will do it's magic. Then, boot should proceed using your drive image as /root as usual.

| improve this answer | |
  • 1
    I found the -drive option about the same time as I read your answer, so I never got to try it. Also, it seems that the 'boot=on' option is KVM specific, and that KVM can boot from usb, even when QEMU cannot. Thank you. – Nakedible Jul 29 '09 at 15:19

Actually, found out the suitable answer for me on my own.

kvm -drive file=x,bus=scsi,boot=on

The drive option allows for specifying the bus. But for some reason, by default, scsi is not bootable. However, KVM supports the boot=on flag for making the scsi drive bootable.

However, this solution still had a problem - for some reason, it took several seconds for the scsi drive to be detected properly by the kernel (I'm guessing it's some usb device settle wait or similar). Because of this, I had to manually break my initramfs boot at a suitable spot to wait for the drive to appear and then continue the boot. I did this by supplying break=mount on the kernel command line.

So, with this KVM config, and the break=mount option, I could finally boot my disk image without modifications.

Quick note: bus=scsi is nowadays if=scsi.

| improve this answer | |
  • still think my solution is easier but good job! +1 – sybreon Jul 29 '09 at 13:53
  • afaik bus=scsi is not a very good idea with qemu - it's still not stable. – dyasny Sep 23 '11 at 8:20

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.