基于ARM64的Qemu/KVM学习环境搭建2

发布时间 2023-12-13 21:47:41作者: 摩斯电码

基于ARM64的Qemu/KVM学习环境搭建中介绍了搭建环境的方法。

使用新的Qemu版本:qemu-8.0.0

#!/bin/bash

../configure --prefix=`pwd` \
        --target-list=x86_64-softmmu,aarch64-softmmu \
        --enable-virtfs \
        --enable-kvm \
        --enable-sdl \
        --enable-slirp

运行模式

ARMv8运行虚拟机有两种模式,一种是Hyp mode,一种是VHE mode。

image

VHE是ARMv8.1引入的,如果要使用VHE模式,需要使用支持这个特性的CPU。

使用Hyp Mode

Cortext-A72或者A53

sudo /home/pengdl/work/qemu-8.0.0/build/aarch64-softmmu/qemu-system-aarch64 \
        -M virt,gic-version=3,virtualization=on,type=virt \
        -cpu cortex-a72 \
        -nographic \
        -m 8G \
        -smp 8 \
        -kernel /home/pengdl/work/Qemu/arm64/$kernel/arch/arm64/boot/Image \
        -append "noinitrd root=/dev/vda rootfstype=ext4 rw console=ttyAMA0 crashkernel=256M" \
        -fsdev local,security_model=passthrough,id=fsdev0,path=/home/pengdl/work/Qemu/arm64/share \
        -device virtio-9p-pci,id=fs1,fsdev=fsdev0,mount_tag=hostshare \
        -drive if=none,format=qcow2,file=/home/pengdl/work/Qemu/arm64/ubuntu20.qcow2,id=hd0 \
        -device virtio-blk-device,drive=hd0 \
        -netdev user,id=eth0,hostfwd=tcp::8080-:22 -device virtio-net-device,netdev=eth0 \
        -nographic

可以看到启动日志里有如下内容:

[    2.341397] kvm [1]: Hyp mode initialized successfully

使用VHE mode

使用Cortext-A76,实现了ARMv8.2扩展

sudo /home/pengdl/work/qemu-8.0.0/build/aarch64-softmmu/qemu-system-aarch64 \
        -M virt,gic-version=3,virtualization=on,type=virt \
        -cpu cortex-a76 \
        -nographic \
        -m 8G \
        -smp 8 \
        -kernel /home/pengdl/work/Qemu/arm64/$kernel/arch/arm64/boot/Image \
        -append "noinitrd root=/dev/vda rootfstype=ext4 rw console=ttyAMA0 crashkernel=256M" \
        -fsdev local,security_model=passthrough,id=fsdev0,path=/home/pengdl/work/Qemu/arm64/share \
        -device virtio-9p-pci,id=fs1,fsdev=fsdev0,mount_tag=hostshare \
        -drive if=none,format=qcow2,file=/home/pengdl/work/Qemu/arm64/ubuntu20.qcow2,id=hd0 \
        -device virtio-blk-device,drive=hd0 \
        -netdev user,id=eth0,hostfwd=tcp::8080-:22 -device virtio-net-device,netdev=eth0 \
        -nographic

可以从启动日志中看到:

[    2.444577] kvm [1]: VHE mode initialized successfully