28

I am trying to mount a shared folder using qemu-kvm/9p and it fails to work if I add it to the fstab file. I get an error at boot that the device cannot be mounted, yet after start if I run "mount -a" the device will be mounted.

fstab line:

src_mnt /src 9p trans=virtio 0 0

From dmesg I can see:

[    7.606258] 9p: Could not find request transport: virtio

And a few lines later I see the "virtio-pci" entries. I'm not clear on how I would defer mounting until that device is available however.

4 Answers 4

31

Don't know if it's the ideal solution, but on an Ubuntu 12.04 guest I got it to work by adding the 9p modules to the initramfs.

Added to /etc/initramfs-tools/modules:

9p
9pnet
9pnet_virtio

Then:

sudo update-initramfs -u
5
  • Thank you - I think its reasonable to say this is the ideal solution. The problem is that the module is not mounted during file-system mount, your solution is to add it to the list of modules loaded at mount-time.
    – Greg
    Apr 4, 2013 at 10:28
  • Why is this ideal?
    – lindhe
    Mar 7, 2016 at 21:03
  • If your kernel doesn't need these modules to start init, then adding them to the initramfs is not enough. You need to also force the kernel or init system to load them explicitly. For init systems that support explicit module loading (incl. systemd), add modules_load=9pnet_virtio,9p to your kernel command line. Jul 6, 2020 at 10:03
  • @TendersMcChiken update-initramfs takes care of that. He didn't add them to the initramfs, he added them to the file /etc/initramfs-tools/modules. This is just a text file in Debian listing modules that your system will need for a proper boot prior to mounting the root partition. Once you call update-initramfs, it will take care of everything else for you.
    – Mecki
    May 17, 2022 at 19:50
  • Actually adding 9pnet_virtio to /etc/initramfs-tools/modules should already be enough. I only added this one line and it solved the problem for me.
    – Mecki
    May 17, 2022 at 19:51
16

In 2020, a better way to delay the mount until the time when we have access to the 9p modules from /lib/modules is to add _netdev as a mount parameter:

/data   /data   9p  trans=virtio,rw,_netdev 0   0
2
  • This worked for me, without needing to make any adjustments to the initramfs Dec 14, 2021 at 15:15
  • This is not a good solution. _netdev only tells systemd to not mount that file system as long as the system has no network connectivity. Yet when transport is virtio, then 9p is not even used over network and on the other hand, the system may have network connectivity before it has access to /lib/modules (e.g. if network drivers are on initramfs). If that isn't the case on your system, then this is coincident but you must not rely that this will always for sure be the case.
    – Mecki
    May 17, 2022 at 19:11
5

On Ubuntu 14.04 only the 9pnet_virtio module needs preloading as per bhassel's answer.

The dmesg a few lines before the quoted one shows that the other two are already loaded but cannot find the required transport.

[ 1.370611] 9pnet: Installing 9P2000 support 
[ 1.376384] 9p: Installing v9fs 9p2000 file system support 
[ 1.376754] 9pnet: Could not find request transport: virtio 

Tested with Ubuntu 14.04 guest on qemu/KVM on openSUSE 13.2.

4
  • Hi Tim, and welcome to the site. Keep in mind that the ordering of the answers can change both by community voting as well as user preferences, so try to always be explicit about which answer you are referring to. I have fixed this for now in your post; please do so yourself in the future. Thanks!
    – user
    Feb 17, 2015 at 15:50
  • This works on ubuntu 16.04 as well.
    – stalet
    Aug 11, 2016 at 8:30
  • This also works on Ubuntu 18.04
    – jackkamm
    Oct 27, 2019 at 20:47
  • This worked for Ubuntu 20.04 guest. Seems like a module dependency bug? 9pnet_virtio should automatically be loaded before the 9pnet module.
    – CR.
    Aug 7, 2021 at 20:28
0

The problem here is how the virtio mount is set up on the host. There are two ways to fix this problem.

Solution 1: Use mapped instead of transport

<filesystem type='mount' accessmode='mapped'>
  <source dir='/src_dir'/>
  <target dir='src'/>
</filesystem>

This works, but all files will be owned by the user libvirt is running as. This doesn't work well for tmp or log file systems.

Solution 2: Run libvirt as root and use passthrough

vi /etc/libvirt/qemu.conf

Then uncomment or add:

user=root
group=root

Reboot the host or restart all libvirt and qemu/kvm processes, and use passthrough:

<filesystem type='mount' accessmode='passthrough'>
  <source dir='/src_dir'/>
  <target dir='src'/>
</filesystem>

While there could be some security implications for the host, this makes the uid:gid of files on the host the same as on the guest, which works well for log and tmp file systems. This happens to be what I do in this situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .