使用qemu安装aarch64架构的虚拟机
安装 qemu
源码安装
wget https://download.qemu.org/qemu-8.2.0.tar.xz
xz -d qemu-8.2.0.tar.xz
tar xvf qemu-8.2.0.tar
cd qemu-8.2.0
pip3 install Ninja
./configure --target-list=aarch64-softmmu
make -j 4
sudo make install
# 安装的可执行文件
$ ls -h /usr/local/bin/ | grep qemu
qemu-edid
qemu-ga
qemu-img
qemu-io
qemu-nbd
qemu-pr-helper
qemu-storage-daemon
qemu-system-aarch64
apt update
apt install qemu qemu-kvm virt-manager qemu-system-arm
创建虚拟机
mkdir arm64-qemu
qemu-efi
apt install qemu-efi
基于 img 镜像创建
wget https://cloud-images.ubuntu.com/jammy/20240126/jammy-server-cloudimg-arm64.img
创建虚拟硬盘
qemu-img create ubuntu22.04-arm64.img 16G
安装系统
#!/usr/bin/python3
import random
def randomMAC():
return [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
def MACprettyprint(mac):
return ':'.join(map(lambda x: "%02x" % x, mac))
if __name__ == '__main__':
print(MACprettyprint(randomMAC()))
$ python3 Generate_MAC.py
00:16:3e:65:81:f5
$ export randmac="00:16:3e:65:81:f5"
cp /usr/share/AAVMF/AAVMF_CODE.fd flash1.img
sudo qemu-system-aarch64 -enable-kvm \
-m 1024 \
-cpu host \
-M virt \
-nographic -pflash /usr/share/AAVMF/AAVMF_CODE.fd \
-pflash flash1.img \
-drive if=none,file=jammy-server-cloudimg-arm64.img,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev type=tap,id=net0 \
-device virtio-net-device,netdev=net0,mac=$randmac
基于 ISO 创建
下载 ISO
wget http://old-releases.ubuntu.com/releases/jammy/ubuntu-22.04.2-live-server-arm64.iso
下载 fd
wget http://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.fd
创建虚拟机
qemu-system-aarch64 -m 2048 \
-cpu cortex-a57 \
-smp 2 \
-M virt -bios ./QEMU_EFI.fd \
-nographic \
-drive if=none,file=./ubuntu-22.04.2-live-server-arm64.iso,id=cdrom,media=cdrom \
-drive if=none,file=./ubuntu22.04-arm64.img,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-scsi-device \
-device scsi-cd,drive=cdrom
- 选择
Try to Install Ubuntu Server
安装
使用 x86 安装 arm 性能不太好