18

I am running a Fedora Workstation virtual machine on an Ubuntu host.
I created a folder /home/cl/share in the guest and mounted the shared folder /media/cl/system/virtual/share as root following the instructions from linux-kvm :

mount -t 9p -o trans=virtio,version=9p2000.L /host /home/cl/share

I am able to access (read) files and folders from shared folders, but I can not write to them.

An example: I am trying to save the file mount-share.txt to the folder /home/cl/share.

Both folders (host and guest) have read-write permissions, nevertheless I receive the error

Error opening file '/home/cl/share/mount-share.txt': Operation not permitted.
  • Host operating system: Ubuntu 15.10 desktop 64-bit
  • Guest operating system: Fedora 23 workstation 64-bit
  • Virtualization software: qemu qemu-kvm virt-manager
  • Host system location : 1st built-in SSD - ext4 format
  • Virtual storage location : 2nd built-in HDD - NTFS format
  • Shared folders location : 2nd built-in HDD - NTFS format

virt-manager

How can I share a directory between guest and host and allow the guest read-write access?

sudo chmod a+x /media/cl and sudo chmod -R 777 /media didn't change the situation.

Guest system:

ls -la /home/cl/share  
total 16  
drwxrwxrwx.  1 cl cl 4096 20. Jan 14:41 .  
drwx------. 18 cl cl 4096 24. Jan 19:11 ..  
drwxrwxrwx.  1 cl cl 4096 17. Dez 09:49 fedora  
drwxrwxrwx.  1 cl cl    0  5. Jan 11:43 solus  
drwxrwxrwx.  1 cl cl    0  6. Jan 12:10 ubuntu  
drwxrwxrwx.  1 cl cl 4096 24. Jan 16:58 various    

stat /home/cl/share  
  File: ‘/home/cl/share’  
  Size: 4096         Blocks: 8          IO Block: 4096   directory  
Device: 25h/37d    Inode: 135       Links: 1  
Access: (0777/drwxrwxrwx)  Uid: ( 1000/     cl)   Gid: ( 1000/      cl)  
Access: 2016-01-27 10:11:12.566303000 +0100  
Modify: 2016-01-26 21:34:48.647707300 +0100  
Change: 2016-01-26 21:34:48.647707300 +0100  
 Birth: -  

Host system:

ls -ld /media /media/cl/ /media/cl/system /media/cl/system/virtual/ /media/cl/system/virtual/share  
drwxr-xr-x  3 root root 4096 Okt 22 16:06 /media  
drwxr-x---+ 6 root root 4096 Jan 24 10:49 /media/cl/  
drwxrwxrwx  1 cl   cl   4096 Jan 19 15:28 /media/cl/system  
drwxrwxrwx  1 cl   cl   4096 Jan 22 13:43 /media/cl/system/virtual/  
drwxrwxrwx  1 cl   cl   4096 Jan 20 14:41 /media/cl/system/virtual/share  

getfacl /media/cl/  
getfacl: Removing leading '/' from absolute path names  
# file: media/cl/  
# owner: root  
# group: root  
user::rwx  
user:libvirt-qemu:--x  
user:cl:r-x  
group::---  
mask::r-x  
other::---

ps aux | grep virt
root       988  0.0  0.2 1207024 39888 ?       Ssl  12:48   0:01 /usr/sbin/libvirtd  
libvirt+  1204  0.0  0.0  45268  2720 ?        S    12:48   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper  
root      1207  0.0  0.0  45240   368 ?        S    12:48   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper  
cl        4204  0.0  0.0  15184  2532 pts/2    S+   14:06   0:00 grep --color=auto virt
  • Why are you using NTFS to share between two linux systems? have you tried this same set up with a more native file format? – Klaatu von Schlacker Jan 25 '16 at 19:14
  • 2
    @KlaatuvonSchlacker : The second HDD contains everything that is not operating system related and is formatted with ntfs to be flexible in case I want to access the data with other operating systems, such as Windows. When I use VirtualBox for virtualization, everything works correctly regarding folder sharing. – cl-netbox Jan 25 '16 at 19:24
  • Regarding the error message when attempting to write to the filesystem: do you get that error when you try to write from the host, or only when you try to write from the guest? – Wildcard Jan 28 '16 at 7:48
  • @Wildcard : I receive the error message when trying to write (store) something from within the guest. – cl-netbox Jan 28 '16 at 10:15
14
+300

I could reproduce the problem on my system.
Your main problem are the ACL restrictions of your host.
For this reason change the ACL attributes of the libvirt-qemu user :

sudo setfacl -R -m u:libvirt-qemu:rwx /media/cl

Change the Mode settings for Filesystem /host from Passthrough to Mapped.


Why? That's the reason why:

Your guest system runs as libvirt-qemu user and your ACL settings restrict the permissions of this user.

user:libvirt-qemu:--x

The correct output of getfacl should be :

user:libvirt-qemu:rwx
2

If your primary goal is just to share files back and forth, and you're open to using TCP, you could just share files over ssh or similar.

For instance, if you re-direct a local port to a sensible port on the guest, you should be able to use that port for access. I use SSH/SCP.

When launching my VM:

qemu-kvm [all your usual qemu options] -net nic -net user -redir tcp:22122::22

And then to access the VM, I use SSH; I open a terminal on my host machine:

scp -P22122 myfile.txt klaatu@localhost:~/ssh-share-dir

fish or sshfs in whatever GUI file manager you use works just as well, as long as you set the port.

  • 1
    What I would do: on your Ubuntu host, configure NFS server serving the shared dir (you can make it read-write to client). And simply mount it on the Fedora VM client. Since you have IP connectivity this will most likely work like a charm. – KWubbufetowicz Jan 27 '16 at 21:28

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.