返回

qemu使用9pfs共享宿主机文件

之前踩了好多坑,特此记录

 

预置条件

kernel开启相关配置项:

CONFIG_9P_FS=y
CONFIG_9P_FS_POSIX_ACL=y
CONFIG_9P_FS_SECURITY=y
CONFIG_NETWORK_FILESYSTEMS=y
CONFIG_NET_9P=y
CONFIG_NET_9P_DEBUG=y
CONFIG_NET_9P_VIRTIO=y
CONFIG_PCI=y
CONFIG_PCI_HOST_COMMON=y
CONFIG_PCI_HOST_GENERIC=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BLK=y
CONFIG_VIRTIO_NET=y
CONFIG_VIRTIO_MMIO=y
CONFIG_FUSE_FS=y
CONFIG_VIRTIO_FS=y
CONFIG_VIRTIO_INPUT=y

宿主机支持相关库

sudo apt install -y libcap-dev
sudo apt install -y libattr
sudo apt install -y libattr-dev

qemu编译支持virtfs

./configure --target-list=aarch64-softmmu --enable-kvm --enable-virtfs --enable-slirp --enable-debug

执行步骤

path/to/share:设置成自己在宿主机的要共享的目录

qemu-system-aarch64 \
    -M virt,secure=on -m 4G -nographic \
    -machine firmware=bl31.bin \
    -fsdev local,id=shareid,path=/path/to/share,security_model=none \
    -device virtio-9p-device,fsdev=shareid,mount_tag=share \
    -device loader,addr=0x1002000000,file=tee.elf \
    --kernel Image \
    --initrd rootfs.cpio.gz
Licensed under CC BY-NC-SA 4.0
Built with Hugo
主题 StackJimmy 设计
© Licensed Under CC BY-NC-SA 4.0