This section details the steps involved in setting up VirtFS (Plan 9 folder sharing over Virtio - I/O virtualization framework) between the guest and host operating systems. The instructions are followed by an example usage of the mentioned steps.
Contents |
1. Download the latest kernel code (2.6.36.rc4 or newer) from http://www.kernel.org to build the kernel image for the guest.
2. Ensure the following 9P options are enabled in the kernel configuration.
CONFIG_NET_9P=y
CONFIG_NET_9P_VIRTIO=y
CONFIG_NET_9P_DEBUG=y (Optional)
CONFIG_9P_FS=y
CONFIG_9P_FS_POSIX_ACL=y
3. Get the latest git repository from http://git.qemu.org/ or http://repo.or.cz/w/qemu.git.
4. Configure QEMU for the desired target. Note that if the configuration step prompts ATTR/XATTR as 'no' then you need to install libattr & libattr-dev first.
For debian based systems install packages libattr1 & libattr1-dev and for rpm based systems install libattr & libattr-devel. Proceed to configure and build QEMU.
5. Setup the guest OS image and ensure kvm modules are loaded.
To start the guest add the following options to enable 9P sharing in QEMU
-fsdev fsdriver,id=[id],path=[path to share],security_model=[mapped|passthrough|none][,writeout=writeout][,readonly]
[,socket=socket|sock_fd=sock_fd] -device virtio-9p-pci,fsdev=[id],mount_tag=[mount tag]
You can instead use the following also, which is just a short-cut of the above command.
-virtfs fsdriver,id=[id],path=[path to share],security_model=[mapped|passthrough|none][,writeout=writeout][,readonly]
[,socket=socket|sock_fd=sock_fd],mount_tag=[mount tag]
Options:
If using libvirt for management of QEMU/KVM virtual machines, the <filesystem> element can be used to setup 9p sharing for guests
<filesystem type='mount' accessmode='$security_model'> <source dir='$hostpath'/> <target dir='$mount_tag'/> </filesystem>
In the above XML, the source directory will contain the host path that is to be exported. The target directory should be filled with the mount tag for the device, which despite its name, does not have to actually be a directory path - any string 32 characters or less can be used. The accessmode attribute determines the sharing mode, one of 'passthrough', 'mapped' or 'squashed'.
There is no equivalent of the QEMU 'id' attribute, since that is automatically filled in by libvirt. Libvirt will also automatically assign a PCI address for the 9p device, though that can be overridden if desired.
You can mount the shared folder using
mount -t 9p -o trans=virtio [mount tag] [mount point] -oversion=9p2000.L
Other options that can be used include:
An example usage of the above steps (tried on an Ubuntu Lucid Lynx system):
1. Download the latest kernel source from http://www.kernel.org
2. Build kernel image
3. Get the latest QEMU git repository in a fresh directory using
git clone git://repo.or.cz/qemu.git
4. Configure QEMU
For example for i386-softmm with debugging support, use
./configure '--target-list=i386-softmmu' '--enable-debug' '--enable-kvm' '--prefix=/home/guest/9p_setup/qemu/'
If this step prompts ATTR/XATTR as 'no', install packages libattr1 and libattr1-dev on your system using:
sudo apt-get install libattr1
sudo apt-get install libattr1-dev
5. Compile QEMU
make
make install
6. Guest OS installation (Installing Ubuntu Lucid Lynx here)
dd if=/dev/zero of=/home/guest/9p_setup/ubuntu-lucid.img bs=1M count=2000
mkfs.ext4 /home/guest/9p_setup/ubuntu-lucid.img
mount -o loop /home/guest/9p_setup/ubuntu-lucid.img /mnt/temp_mount
For installing a Debain system you can use package debootstrap
debootstrap lucid /mnt/temp_mount
Once the OS is installed, unmount the guest image.
umount /mnt/temp_mount
7. Load the KVM modules on the host (for intel here)
modprobe kvm
modprobe kvm_intel
8. Start the Guest OS
/home/guest/9p_setup/qemu/bin/qemu -drive file=/home/guest/9p_setup/ubuntu-lucid.img,if=virtio \ -kernel /path/to/kernel/bzImage -append "console=ttyS0 root=/dev/vda" -m 512 -smp 1 \ -fsdev local,id=test_dev,path=/home/guest/9p_setup/shared,security_model=none -device virtio-9p-pci,fsdev=test_dev,mount_tag=test_mount -enable-kvm
The above command runs a VNC server. To view the guest OS, install and use any VNC viewer (for instance xclientvncviewer).
9. Mounting shared folder
Mount the shared folder on guest using
mount -t 9p -o trans=virtio test_mount /tmp/shared/ -oversion=9p2000.L,posixacl,cache=loose
In the above example the folder /home/guest/9p_setup/shared of the host is shared with the folder /tmp/shared on the guest.