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!!!

  • 1
    Run sudo virt-manager, no need to connect as root. Don't know if virtio works for physical devices... – ish Jun 1 '12 at 4:22
  • @izx, thanks for your reply! should that make a make a difference even though virt-manager is being run on my desktop and not the server? – evan Jun 1 '12 at 4:29

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.

  • 2
    Currently this is the only answer (that has ever been) posted on this question. There's some information in comments that might help, but as far as I can tell it's far from certain that they will fix the problem. You might consider expanding this to provide a full solution. If parts of your solution have been devised by others you can always cite them and link to them. I doubt izx would mind ..especially as (when I comment now) izx hasn't signed on to the site for over a year. – Eliah Kagan Jan 10 '14 at 10:14
  • I'm using virsh attach-device domain XML-file... to attach disks. Can you also use disk-id in the <source dev='/dev/...'/>element? – MrCalvin Jan 22 at 23:53

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'/>

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 !

  • 3
    Instead of virsh define..., the recommendation is to use virsh edit <NAME> This allows you to edit the XML in your favorite text editor and have the changes automatically update the VM. – Nathan Osman Feb 7 '17 at 1:03

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.