安装AARCH的qemu工具和efi固件
apt-get install qemu-system-arm
apt-get install qemu-efi-aarch64
apt-get install qemu-utils
创建flash image
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
下载需要安装的镜像(ARM64版本)
例如我下载的是ubuntu的server版本ubuntu-20.04.3-live-server-arm64.iso
wget http://mirrors.dpu.tech/ubuntu-cdimage/releases/20.04/release/ubuntu-20.04.3-live-server-arm64.iso
创建空的image用来安装ubuntu
qemu-img create ubuntu-image.img 20G`
启动Qemu用来安装ubuntu
qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 4096M -cpu max -smp 8 \
-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=ubuntu-20.04.3-live-server-arm64.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
接下来将会正确安装ubuntu的镜像,推出qemu命令是 ctrl+A+X
或者通过virt-install安装
virt-install -n ubuntu1604arm64 --memory 2048 --arch aarch64 --vcpus 4 \
--disk /home/jeff/ubuntu-image.img,device=disk,bus=virtio \
--os-type=generic \
--boot uefi \
--video vga \
--graphics vnc,port=5999 \
--noautoconsole \
--noreboot \
--network bridge=virbr0 \
--cdrom ubuntu-20.04.3-live-server-arm64.iso
安装完成之后正常启动的命令是
正常启动命令
qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 4096M -cpu max -smp 8 \
-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
设置网络
-
关闭cloud-init
sudo touch /etc/cloud/cloud-init.disabled sudo apt-get purge cloud-init sudo shutdown -h now
-
设置网络
设置virbr0的网段IP网络即可通信
小结
通过上面的步骤,就可以在x86平台模拟一个arm的环境,在ARM硬件资源不足够的情况下可以在此环境开发、调试
参考:
https://gist.github.com/yen3/884bf14ec8286df35de67953a561eee8