x86架构的Ubuntu20利用QEMU运行arm64环境
需要在arm64的环境下测试开发的软件,但是手里没有arm64架构的电脑,用qemu模拟一下,qemu最好配合kvm使用。
原文:How to launch ARM aarch64 VM with QEMU from scratch. (opens new window)
要启动一个aarch64虚拟机,我们首先需要安装一些依赖项,包括QEMU和QEMU -ef -aarch64包,其中包含efi固件
apt-get install qemu-system-arm
apt-get install qemu-efi-aarch64
apt-get install qemu-utils
1
2
3
2
3
创建正确大小的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
1
2
3
2
3
下载你要安装的镜像。 例如,使用Ubuntu安装程序
wget http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/main/installer-arm64/current/images/netboot/mini.iso
1
创建一个空的Ubuntu镜像文件,我们将把Ubuntu安装到里面。 我们将为这个文件使用20g的空间。
qemu-img create ubuntu-image.img 20G
1
使用安装程序启动QEMU。
qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 512M -cpu max -smp 4 \
-netdev user,id=vnet,hostfwd=:127.0.0.1:0-: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
1
2
3
4
5
2
3
4
5
安装完成后,可以使用-a x
退出QEMU
然后在没有安装程序映像的情况下,使用以下命令重新启动QEMU
qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 512M -cpu max -smp 4 \
-netdev user,id=vnet,hostfwd=:127.0.0.1:0-: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
1
2
3
4
2
3
4
上次更新: 2024/01/07, 07:44:52