Is it possible to use a folder shared from the host to the guest via virtfs/9p as the root file system inside the guest?

Loosely related to my previous question: Can virtfs/9p be used to share the same host folder with multiple guests?

  • I never tried to 9p as root FS, but I think that with proper initrd there is nothing that can block you from doing that. Commented Oct 6, 2013 at 17:19
  • 1
    jor1k does this Commented Feb 26, 2015 at 14:13
  • What would be beautiful is if we could use overlayfs with / and the 9p mount as lowers, then chroot into it. But it fails to be very useful because writes to the lowers are undefined... There are however other FUSER filesystems that allow that I think, but I haven't reached it yet. Commented Oct 17, 2018 at 16:01

3 Answers 3


Yes, see for instance how to boot a VM with the FS of the host:

Add the 9p modules to the host initramfs (that's the easiest way albeit not the cleanest, to have an initrd with the needed modules):

printf '%s\n' 9p 9pnet 9pnet_virtio | sudo tee -a /etc/initramfs-tools/modules
sudo update-initramfs -u

qemu -kernel "/boot/vmlinuz-$(uname -r)" \
  -initrd "/boot/initrd.img-$(uname -r)" \
  -fsdev local,id=r,path=/,security_model=none \
  -device virtio-9p-pci,fsdev=r,mount_tag=r \
  -nographic \
  -append 'root=r ro rootfstype=9p rootflags=trans=virtio console=ttyS0 init=/bin/sh'

If you run it as a normal user, there are files it won't be able to access, but you should be able to get the the shell prompt and it won't do any damage:

[    0.000000] Linux version 3.10-3-amd64 ([email protected]) (gcc version 4.7.3 (Debian 4.7.3-7) ) #1 SMP Debian 3.10.11-1 (2013-09-10)
[    0.000000] Command line: root=r rootfstype=9p rootflags=trans=virtio console=ttyS0 init=/bin/sh
Loading, please wait...
[    0.564122] systemd-udevd[52]: starting version 204
Begin: Loading essential drivers ... [    1.007951] FS-Cache: Loaded
[    1.009958] 9p: Installing v9fs 9p2000 file system support
[    1.012880] FS-Cache: Netfs '9p' registered for caching
Begin: Running /scripts/init-premount ... done.
sh-4.2# ls /
bin   home            lib32       media    opt   safe  tmp      vmlinuz.old
boot  initrd.img      lib64       mnt      proc  sbin  usr
dev   initrd.img.old  libx32      old      root  srv   var
etc   lib             lost+found  old-tmp  run   sys   vmlinuz
sh-4.2# poweroff -f
[   56.958724] ACPI: Preparing to enter system sleep state S5
[   56.960332] Power down.
  • 2
    Additionally, you could use 'security_model=mapped' to be able to fully access the underlying file-system since it stores ownership and other privileged file information in extended attributes of the file. This also allows you to mount the fs read-write instead of readonly. See also link Commented Jan 4, 2014 at 20:03
  • 1
    Modern Linux seems to ignore the "root=r" command line option and unconditionally looks for the mount_tag "/dev/root". Any objection to updating the answer to reflect that? Commented Mar 14, 2018 at 19:17
  • I second that /dev/root comment. Here it always looks for /dev/root too, no matter what mount_tag I use. Commented Oct 19, 2021 at 21:43

As sensible an idea as this seems at first, do not do this. 9P in its current state cannot handle some fairly basic operations, including:

9P at present is not in a fit state to be used in production.

While you can make a bootable system with 9P as the root file system, operating that VM will cause significant grief - if using Debian, the defect listed above will prevent apt-get upgrade from working. Patches to fix this problem have gone nowhere for years.

If you insist on doing this, the rootflags should be "rootflags=trans=virtio,cache=mmap", otherwise read/write memory mapping will not work (used by, for example, MariaDB).

  • Even though I don't like it, thanks for the input. I am currently pondering placing boot and root in a proper file container and some of the data that is supposed to be shared into 9p ... Commented Apr 11, 2020 at 23:40

Yes, sure. Add to kernel command line:

root=host rootfstype=9p rootflags=trans=virtio

And you may boot without initrd (if 9P is compiled into the kernel, rather than as modules).

You must log in to answer this question.

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