Add physical disk to KVM virtual machine

I'm setting up a file server (nas4free) as a KVM virtual machine on a Ubuntu Server 12.04 system.

How do I add physical hard drives directly to the VM so they can be used by the guest (nas4free), but not the host?

Specifically the hard drive I'd like to mount is /dev/sda (which is not currently mounted on the server.)

So far I've found two solutions but I haven't gotten either to work.

The first is from Server Fault where it's suggested to use virt-manager. I haven't gotent this to work because when I try to select an existing drive nothing is being listed. My best guess as to why this is, is because I'm using virt-manager over ssh and not connecting as root, should that make a difference?

The second solution I've found here is to just run the command (modified for my system)

qm set nas4free -virtio /dev/sda

but that seems to require proxmox which I don't have installed and doesn't seem to be in the default repositories?

Finally, once the above is sorted out and I can mount the drive directly to the VM, does anyone have an experience with whether the drive should be mounted to the VM as scsi, ide, or virtio? (I know virtio was recommend in the linked ServerFault page, but I hadn't heard of it before now since I mainly use VMWare).

Thanks for your help!!!


Although this has been answered, rather than using /dev/sda you should use /dev/disk/by-id/ where you get from

    ls -l /dev/disk/by-id

That way you are covered just in case the disk changes from /dev/sda to /dev/sdb.


Having the exact same need, I found the following.

(the whole following text comes from the above source)

It can’t be done with virt-manager. That one took me a while to figure out. As far as I can tell, virt-manager works with storage pools. You can make a disk into a storage pool, but you can’t add an existing disk directly to a VM.

Luckily the fix is easy: you add the disk to the domain’s xml config file by hand. So open up /etc/libvirt/qemu/.xml in your favourite editor and add a section to the section:

<disk type='block' device='disk'>
  <driver name='qemu' type='raw'/>
  <source dev='/dev/md/storage'/>
  <target dev='vdb' bus='virtio'/>
</disk>

This will make the host’s /dev/md/storage available in the guest as /dev/vdb. After changing a domain’s config by hand, you have to reload the config by hand. Log in to your host and issue this command:

# virsh define /etc/libvirt/qemu/jetsetetser.xml
Domain jetser defined from /etc/libvirt/qemu/jetsetetser.xml

Here is a nice resource with more information about managing vms with libvirt : https://help.ubuntu.com/community/KVM/Managing

I strongly recommend you follow the advice given by smccloud. This works like a charm for me. Beware to not mount any volume in the physical drives used in your guest, or you will severely damage its filesystem !