7

I'm using QEmu with a Windows 7 guest on my (Arch) Linux system. I'd like to use the samba to share a directory on my host system with the Windows guest. I can do this from the terminal with a command like:

qemu-system-x86_64 /path/to/windows7.img -enable-kvm -net nic -net user,smb=/path/to/shared/directory -m 1024

But I've got libvirtd set up now, and I'd like to be able to start Windows 7 with virt-manager. I'm a complete novice with libvirtd, and I'm having trouble navigating the documentation. I think I need to set up a "network filesystem pool" (which I read about in the libvirt documentation), but I don't understand if I can do this through virt-manager or if I need to do it on the command line, or where I need to add the XML described in that link.

I've looked for examples, but haven't found anything. I've found various forum posts with people asking questions on how to do this, so I suspect I'm not the only one struggling with this!

1 Answer 1

4

It seems like libvirt does not support the -net user,smb command of qemu (I guess due to incompatibilities with other hypervisors). A possible workaround is to directly pass through the parameter to the qemu-kvm command.

To do so, you first need to add the XML namespace http://libvirt.org/schemas/domain/qemu/1.0 to your domain. Then you can use the <commandline> tag of that namespace:

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    ...
    <qemu:commandline>
        <qemu:arg value='-net'/>
        <qemu:arg value='user,smb=/path/to/shared/directory'/>
    </qemu:commandline>
</domain>

You can easily edit the XML configuration by running

# virsh edit <vm-name>
3
  • Some things to add: You can usually find the XML file to edit under /etc/libvirt/qemu/VMNAME.xml. I had to run sudo service libvirt-bin restart on Ubuntu for the changes to be applied into virt-manager.
    – nh2
    Nov 16, 2017 at 15:31
  • The adding of the flags worked for me, but I can't manage to make the VM start. Even when the path to the shared directory is set to e.g. /tmp/vmfolder, I get the error qemu-system-x86_64: -net user,smb=/tmp/vmfolder: could not create samba server dir '/tmp/qemu-smb.kLUW0k'. No idea why the qemu process wouldn't be able to create a directory in /tmp (which has chmod drwxrwxrwt for me), but I can see it failing in strace like mkdir("/tmp/qemu-smb.kLUW0k", 0700) = -1 EACCES (Permission denied). Weird.
    – nh2
    Nov 16, 2017 at 15:33
  • 1
    @nh2 : That error is likely caused by AppArmor. See bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1365261 To fix the problem, edit /etc/apparmor.d/abstractions/libvirt-qemu and add the following lines somewhere above the deny /tmp/{,**} r, rule: owner /tmp/qemu-smb.*/ rw, owner /tmp/qemu-smb.*/* rw, Aug 8, 2018 at 23:02

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.