17

I have recently started experimenting with the support for passthrough filesystems in recent versions of KVM/QEMU/libvirt. Making the filesystems available for read access has "just worked", but I'm a little puzzled about how write access is supposed to work. After mounting the filesystem in the guest:

# mount -t 9p -o trans=virtio /fs/data /mnt

I can modify an existing file if it has mode o+w:

# cd /mnt/work
# ls -l foo
-rw-rw-rw-. 1 root root 17 Dec 20 11:16 foo
# cat foo
this is line one
# echo this is line two >> foo
# cat foo
this is line one
this is line two

But regardless of the directory permissions, I cannot create a new file or directory:

# ls -ld /mnt/work
drwxrwxrwx. 2 root root 4096 Dec 20 11:16 /mnt/work
# cd /mnt/work
# touch bar
touch: setting times of `bar': No such file or directory
# mkdir bar
# mkdir: cannot create directory `bar': Operation not permitted

The documentation I've been able to find (e.g., this) does not explicitly address this issue. I'm hoping someone here at Serverfault can help me set up a passthrough filesystem that will let me grant write access to a user in the guest to a host filesystem.

Jacob
  • 9,114
  • 4
  • 44
  • 56
larsks
  • 41,276
  • 13
  • 117
  • 170
  • Are you sure you mounted the file system read/write? Can you create files? Are you creating files as root or regular user (yeah I see your # but you might have written that manually)? – Janus Troelsen Feb 09 '12 at 11:46
  • Did you manage to resolve this? I am having a similar issue of not being able to write to the mounted host fs path in the guest. – Shoan Jun 20 '13 at 03:01
  • I never really made any progress on this. It was kind of a niche application for me...I'm not generally running KVM guests in places where access to a local filesystem would be useful. I've taken to running VirtualBox on my desktop where I actually want this feature from time to time. – larsks Jun 20 '13 at 14:14
  • Do you see any selinux alert on the physical host or on the guest? – c4f4t0r Aug 31 '13 at 21:10
  • This might help? http://www.linux-kvm.org/page/9p_virtio – Danila Ladner Jan 21 '14 at 01:49

2 Answers2

8

This seems to me like a permission issue on the host:

By default, the qemu/kvm process is started as a non-privileged user (libvirt-qemu in Debian Wheezy). So only files accessible (or writable) by that user are accessible (writable) by the VM guests.

You might try setting ownership of the directory to the user qemu is run as (see user= and group= in /etc/libvirt/qemu.conf)

Maybe this helps in your case?

matt_gnu
  • 516
  • 3
  • 4
  • 3
    I've tried that in my case, which is the same as [this question](https://serverfault.com/q/559726/206680), but I can't get it to work, even with apparmor off. – Diagon Dec 17 '17 at 07:00
  • Same issue and no solution. Did anyone solve it? In my case host and guest have same UID. qemu-system-x86_64 is running under same UID. I'm able to remove or edit from guest, but not able to create new files and folders e.g. with `touch` or `mkdir`. Even if I temporary disable apparmor and give 777 to directory at both sides. – laimison Sep 12 '20 at 14:25
  • Okay, this `touch: setting times of` issue with 9P filesystem exists for a decade based on various Google searches without solution. So I questioned myself whether I should use not maintained technology and decided to NOT DO IT. It could have many more issues ahead. – laimison Sep 12 '20 at 15:06
0

when startup your qemu monitor in shell , should add "sudo" as prefix. I did it to resolve permission problem when create file or folder. my environment is ubuntu16.04 + qemu-2.12.

ianwang
  • 1
  • 1