This document details the steps for setting up VirtFS 9P "virtio-9pfs" (Plan 9 folder sharing over Virtio - I/O virtualization framework) filesystem passthrough between CentOS 7 guest and CentOS 7 host operating systems.
git clone https://github.com/AlekseyChudov/qemu-kvm-virtfs.git
cd qemu-kvm-virtfs
docker run -it --privileged -v "$PWD/rpmbuild:/root/rpmbuild" \
docker.io/centos:7 /root/rpmbuild/build
Upon successful completion you will have the following packages
rpmbuild/RPMS/x86_64/qemu-img-virtfs-<version>.x86_64.rpm
rpmbuild/RPMS/x86_64/qemu-kvm-common-virtfs-<version>.x86_64.rpm
rpmbuild/RPMS/x86_64/qemu-kvm-tools-virtfs-<version>.x86_64.rpm
rpmbuild/RPMS/x86_64/qemu-kvm-virtfs-<version>.x86_64.rpm
rpmbuild/RPMS/x86_64/qemu-kvm-virtfs-debuginfo-<version>.x86_64.rpm
rpmbuild/SRPMS/qemu-kvm-virtfs-<version>.src.rpm
Install the previously created QEMU packages on the hypervisor host as usual, using the files or local Yum repository. During installation, new packages remove previously installed packages, if any, and correctly replace them due to RPM dependencies.
yum -y install centos-release-qemu-ev
yum -y install \
cloud-utils \
libvirt-client \
libvirt-daemon-config-network \
libvirt-daemon-config-nwfilter \
libvirt-daemon-driver-interface \
libvirt-daemon-driver-qemu \
virt-install \
rpmbuild/RPMS/x86_64/qemu-img-virtfs-<version>.x86_64.rpm \
rpmbuild/RPMS/x86_64/qemu-kvm-common-virtfs-<version>.x86_64.rpm \
rpmbuild/RPMS/x86_64/qemu-kvm-virtfs-<version>.x86_64.rpm
systemctl restart libvirtd
curl https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2 \
-o /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2
qemu-img resize /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2 10G
qemu-img convert -O qcow2 -o preallocation=falloc \
/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1907.qcow2 \
/var/lib/libvirt/images/centos7.localhost.qcow2
mkdir -p cloud-init
cat << EOF > cloud-init/meta-data
instance-id: centos7.localhost
local-hostname: centos7.localhost
EOF
cat << EOF > cloud-init/user-data
#cloud-config
chpasswd:
expire: false
password: your-ssh-password-is-here
ssh_pwauth: true
runcmd:
- yum -y update
- yum -y --enablerepo centosplus install kernel-plus
- grub2-set-default 0
- echo "virtfs /mnt/virtfs 9p trans=virtio,version=9p2000.L,nofail,_netdev,x-mount.mkdir 0 0" >> /etc/fstab
- reboot
EOF
cloud-localds /var/lib/libvirt/images/centos7.localhost.iso \
cloud-init/user-data cloud-init/meta-data
Note the DAC (user, group, access) and MAC (SELinux) permissions on the shared folder.
mkdir -p /var/lib/libvirt/qemu/virtfs/centos7.localhost
chown -R qemu:qemu /var/lib/libvirt/qemu/virtfs
chmod -R 0770 /var/lib/libvirt/qemu/virtfs
virt-install \
--name centos7.localhost \
--memory 1024 \
--vcpus 1 \
--cpu host \
--import \
--disk /var/lib/libvirt/images/centos7.localhost.qcow2,device=disk,bus=virtio \
--disk /var/lib/libvirt/images/centos7.localhost.iso,device=cdrom \
--filesystem /var/lib/libvirt/qemu/virtfs/centos7.localhost,virtfs \
--network default \
--graphics none \
--virt-type kvm \
--os-variant centos7.0
Default username is "centos" and default password is "your-ssh-password-is-here". Press "Ctrl + ]" to exit the guest console.
Filesystem passthrough "virtio-9pfs" support in KVM in RHEL7