Qemu安装arm虚拟机

安装aarch64虚拟机的依赖软件:

apt-get install qemu-system-arm
apt-get install qemu-efi-aarch64
apt-get install qemu-utils

创建flash文件镜像:

dd if=/dev/zero of=flash1.img bs=1M count=64
dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc

下载系统镜像,在此我们使用Ubuntu的网络启动镜像:

wget http://ports.ubuntu.com/ubuntu-ports/dists/focal-updates/main/installer-arm64/current/legacy-images/netboot/mini.iso

创建一个空的系统镜像文件:

qemu-img create ubuntu-image.img 10G

启动qemu安装系统:

qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 512M -cpu max -smp 1 \
-netdev user,id=vnet,hostfwd=:127.0.0.1:10022-:22 -device virtio-net-pci,netdev=vnet \
-drive file=ubuntu-image.img,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 \
-drive file=mini.iso,if=none,id=drive1,cache=writeback -device virtio-blk,drive=drive1,bootindex=1 \
-drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash
qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 512M -cpu max -smp 1 \
-netdev user,id=vnet,hostfwd=:127.0.0.1:10022-:22 -device virtio-net-pci,netdev=vnet \
-drive file=ubuntu-image.img,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 \
-drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash

如果装了KVM并且是运行在aarch64的主机上,可以添加-enable-kvm启用kvm。