使用 libvirt/qemu 对直通 (9p) 文件系统进行读/写访问?

lar*_*sks 17 virtualization filesystems libvirt qemu 9p

我最近开始尝试在最新版本的 KVM/QEMU/libvirt 中支持直通文件系统。使文件系统可用于读取访问“刚刚奏效”,但我对写入访问应该如何工作感到有些困惑。在客户机中挂载文件系统后:

# mount -t 9p -o trans=virtio /fs/data /mnt
Run Code Online (Sandbox Code Playgroud)

如果现有文件具有 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
Run Code Online (Sandbox Code Playgroud)

但是无论目录权限如何,我都无法创建新文件或目录:

# 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
Run Code Online (Sandbox Code Playgroud)

我能够找到的文档(例如,this)没有明确解决这个问题。我希望 Serverfault 的某个人可以帮助我设置一个直通文件系统,让我可以向来宾中的用户授予对主机文件系统的写访问权限。

小智 8

在我看来,这就像主机上的权限问题:

默认情况下,qemu/kvm 进程以非特权用户身份启动(Debian Wheezy 中的 libvirt-qemu)。因此,只有该用户可访问(或可写)的文件才能被 VM 来宾访问(可写)。

您可以尝试将目录的所有权设置为 qemu 运行的用户(请参阅 /etc/libvirt/qemu.conf 中的 user= 和 group=)

也许这对你的情况有帮助?

  • 在我的情况下,我已经尝试过,这与 [this question](https://serverfault.com/q/559726/206680) 相同,但即使关闭了 apparmor,我也无法让它工作。 (3认同)