[TUTORIAL] FabU: Copy files between Host and a VM by using 9p (to/from Linux for now...)

UdoB

Distinguished Member
Nov 1, 2016
2,514
1,257
243
Germany

How can I copy files between the PVE Host and a VM?​

There are many ways, ssh/sshfs being the recommendation usually. One possible alternative does not need a network: 9p.
  • this is for temporary usage e.g. maintenance or initial setup. 9p is local, so the VM can not migrate anymore
  • for this reason I simply use “root”, which generally is not a good advise for “normal” day-by-day usage
  • and: this approach is not supported officially
For this article:
  • on the host exists some folder with data, I chose /tmp/hoststorage
  • it is okay to have data in it, we do not destroy anything

On the host​

While the VM is turned off add this single line manually to your /etc/pve/local/qemu-server/<vmid>.conf file:
Code:
args: -fsdev local,security_model=passthrough,id=fsdev0,path=/tmp/hoststorage  -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare
Now start your VM.

Linux Guest​

The guest should start as usual, everything should work normal. Open a root shell and run:
Code:
mkdir /mnt/host
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt/host
That’s all. You can read and write files using any file manager you want. On the host all of them are owned by root.

Windows Guest​

No success for me :-(
Seems to be missing: https://github.com/virtio-win/kvm-guest-drivers-windows/issues/126
Is this a valid attempt? https://virtio-fs.gitlab.io/howto-windows.html -- no: “Virtio-fs and virtio-9p are two different two different devices serving the same purpose from user point of view.”

References​



Side note: we need a place for FAQs like this, just to find them easier...
 
Just wanted to thank you, UdoB! Had about 100 GB of files on a USB-Storage mounted to a Linux-VM that I wanted to save outside the VM, on the host, to be exactly. Your Tutorial told me how to do this without using network protocols.

Greetings :)
 
  • Like
Reactions: UdoB
This is exactly what I was looking for, to avoid going from the host to a vm using a network share. I've been testing it for couple of days and I've had no issues so far. While not natively supported, looks like 9p has been supported on qemu for a long time. I'm using it for an OpenMediaVault VM that being Debian based, also support 9p natively. Thanks!
 
  • Like
Reactions: Johannes S and UdoB