qemu-system-aarch64使用记录

下载安装qemu

#!/bin/bash

out='> /dev/null'
# out=

echo ${HOME}

gcc -v 
if [[ $? -ne 0 ]]; then
    sudo apt update ${out}
    sudo apt upgrade 
    eval sudo apt-get install -y make gcc g++ gdb ${out}
fi

ninja --version

if [[ $? -ne 0 ]]; then
    cd
    if [[ ! -d ${HOME}/ninja ]]; then
        git --version
        if [[ $? -ne 0 ]]; then
            eval sudo apt-get install -y git ${out}
        fi
        git clone https://gitee.com/gitmirror/ninja.git
        if [[ $? -ne 0 ]]; then
            echo " git clone ninja fail"
            exit 1
        fi
        eval sudo apt-get install -y re2c ${out}
    fi
    cd ${HOME}/ninja
    python3 ./configure.py --bootstrap  
    sudo cp ./ninja  /usr/bin
    # 测试
    ninja --version

    if [[ $? -ne 0 ]];then
    echo " ninja install fail"
        exit 1
    fi 
fi

cd
if [[ ! -d ${HOME}/qemu7 ]]; then
    wget https://download.qemu.org/qemu-7.0.0.tar.xz
    if [[ $? -ne 0 ]];then
        echo " qemu download fail"
        exit 1
    fi 
    # 安装依赖包
    eval sudo apt-get install -y build-essential zlib1g-dev pkg-config libglib2.0-dev ${out}
    eval sudo apt-get install -y binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev ${out}
    # 支持enable-virtfs 共享文件
    eval sudo apt-get install -y libcap-ng-dev libattr1-dev ${out}
    tar xJf qemu-7.0.0.tar.xz
    mv qemu-7.0.0 qemu7
fi

${HOME}/qemu7/build/qemu-system-aarch64 -version

if [[ $? -ne 0 ]]; then
    echo "qemu not compile"
    cd ${HOME}/qemu7
    # arm64 编译
   ./configure --target-list=aarch64-softmmu --enable-debug --enable-debug-info  --enable-kvm  \
        --enable-trace-backends=simple --enable-virtfs
    if [[ $? -ne 0 ]];then
        echo " qemu configure fail"
        exit 1
    fi
    # 开始编译
    eval make -j$(nproc) ${out}
    if [[ $? -ne 0 ]];then
        echo " qemu make fail"
        exit 1
    fi
    ${HOME}/qemu7/build/qemu-system-aarch64 -version
fi

cd

测试环境

查看是否支持KVM

参考:

对于aarch64(arm64)架构,若支持KVM虚拟化,那么KVM代码会直接编译进内核

2020年3月,Linux 5.7 Kernel宣布将放弃支持 32位架构的 KVM虚拟化支持,所以目前来看,要想较好的在ARM架构上运行KVM虚拟化,需要使用现代化的64位ARM架构

# 如果/dev/kvm和/sys/module/kvm二者之一不存在说明KVM虚拟化是不支持的
ls -l /dev/kvm
ls -l /sys/module/kvm

cat /boot/config-`uname -r` | grep VIRTUAL
CONFIG_VIRTUALIZATION=y
# CONFIG_GKI_HIDDEN_VIRTUAL_CONFIGS is not set
# CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set
CONFIG_FB_VIRTUAL=y
CONFIG_ARCH_HAS_DEBUG_VIRTUAL=y
# CONFIG_DEBUG_VIRTUAL is not set

机器配置

uname -a
Linux firefly 5.10.110 #217 SMP Wed Oct 12 17:59:18 CST 2022 aarch64 aarch64 aarch64 GNU/Linux

free -h
              total        used        free      shared  buff/cache   available
Mem:          3.4Gi       2.7Gi       295Mi       115Mi       445Mi       590Mi
Swap:            0B          0B          0B

lscpu
Architecture:                    aarch64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
CPU(s):                          8
On-line CPU(s) list:             0-7
Thread(s) per core:              1
Core(s) per socket:              2
Socket(s):                       3
Vendor ID:                       ARM
Model:                           0
Model name:                      Cortex-A55
Stepping:                        r2p0
Flags:                           fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrc
                                 pc dcpop asimddp

安装ubuntu

# 创建镜像 
${HOME}/qemu7/build/qemu-img create -f qcow2 ${HOME}/ubuntu.img 60G

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
  -m 1G -cpu host -smp 2 -M virt -enable-kvm\
  -bios ${HOME}/qemu7/build/pc-bios/edk2-aarch64-code.fd \
  -drive if=none,file=${HOME}/ubuntu-18.04-server-arm64.iso,id=cdrom,media=cdrom \
  -device virtio-scsi-device -device scsi-cd,drive=cdrom \
  -drive if=none,file=${HOME}/ubuntu.img,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -vnc :1 \
  -monitor stdio

在这里插入图片描述
安装成功后

# 通过vnc 启动,并开启监控模式
sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
  -m 1G -cpu host -smp 2 -M virt -enable-kvm\
  -bios ${HOME}/qemu7/build/pc-bios/edk2-aarch64-code.fd \
  -drive if=none,file=${HOME}/ubuntu.img,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -vnc :1 \
  -monitor stdio

# 通过vnc 启动,不需要监控模式
sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
  -m 1G -cpu host -smp 2 -M virt -enable-kvm\
  -bios ${HOME}/qemu7/build/pc-bios/edk2-aarch64-code.fd \
  -drive if=none,file=${HOME}/ubuntu.img,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -vnc :1 \
  -monitor none

在这里插入图片描述

记录

运行qemu

参考

ubuntu-22.04.1-live-server-arm64.iso 下载

验证机器是否支持kvm
# 用户添加到多个次要组中
usermod -a -G kvm ostest

# 创建虚拟机硬盘
${HOME}/qemu7/build/qemu-img create -f qcow2 ${HOME}/disk/ubuntu.img 100G

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
     -m 2048M -smp 4 -M virt -enable-kvm  \
     -boot order=dc \
     -drive file=${HOME}/disk/ubuntu.img,index=0,media=disk,format=qcow2  \
     -cdrom ${HOME}ubuntu-22.04.1-live-server-arm64.iso  \
     -vnc :1
qemu-system-aarch64: KVM is not supported for this guest CPU type
qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument

qemu-system-aarch64: The 'host' CPU type can only be used with KVM or HVF

# qemu 文档
-cpu model
	Select CPU model (-cpu help for list and additional feature selection)

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -M virt \
    -m 2048M -smp 4 \
    -cpu host \
    -enable-kvm  \
    -boot order=dc \
    -drive file=${HOME}/disk/ubuntu.img,index=0,media=disk,format=qcow2  \
    -cdrom ${HOME}/ubuntu-22.04.1-live-server-arm64.iso  \
    -vnc :1
qemu-system-aarch64: failed to find romfile "efi-virtio.rom"

# 查看qemu 文档
-L  path
	Set the directory for the BIOS, VGA BIOS and keymaps.
	To list all the data directories, use -L help.

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -M virt \
    -m 2048M -smp 4 \
    -cpu host \
    -enable-kvm  \
    -L /home/ostest/qemu7/pc-bios/ \
    -boot order=dc \
    -drive file=${HOME}/disk/ubuntu.img,index=0,media=disk,format=qcow2  \
    -cdrom ${HOME}/ubuntu-22.04.1-live-server-arm64.iso  \
    -vnc :1

在这里插入图片描述

在这里插入图片描述

-M
ostest@firefly:~$ ${HOME}/qemu7/build/qemu-system-aarch64  -M help | grep a7
ostest@firefly:~$ ${HOME}/qemu7/build/qemu-system-aarch64  -M help | grep A7
ast2600-evb          Aspeed AST2600 EVB (Cortex-A7)
bletchley-bmc        Facebook Bletchley BMC (Cortex-A7)
fuji-bmc             Facebook Fuji BMC (Cortex-A7)
mcimx6ul-evk         Freescale i.MX6UL Evaluation Kit (Cortex-A7)
mcimx7d-sabre        Freescale i.MX7 DUAL SABRE (Cortex-A7)
orangepi-pc          Orange Pi PC (Cortex-A7)
rainier-bmc          IBM Rainier BMC (Cortex-A7)
tacoma-bmc           OpenPOWER Tacoma BMC (Cortex-A7)
ostest@firefly:~$ ${HOME}/qemu7/build/qemu-system-aarch64  -M help | grep A5
xlnx-zcu102          Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5Fs based on the value of smp
ostest@firefly:~$ ${HOME}/qemu7/build/qemu-system-aarch64  -M help | grep a5
ostest@firefly:~$                                                                                                  

测试记录

ostest@firefly:~$ sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
>     -M ast2600-evb \
>     -m 1G -smp 2 \
>     -cpu host \
>     --enable-kvm  \
>     -bios ${HOME}/QEMU_EFI.fd \
>     -drive if=none,file=${HOME}/ubuntu-22.04.1-live-server-arm64.iso,id=cdrom,media=cdrom\
>     -drive file=${HOME}/disk/ubuntu.img,index=1,media=disk,format=qcow2,id=ubuntuhd \
>     -vnc :1 \
>     -monitor none
Unexpected error in arm_cpu_realizefn() at ../target/arm/cpu.c:1471:
qemu-system-aarch64: Cannot enable KVM when guest CPU has EL3 enabled
Aborted

ostest@firefly:~$ sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
>     -M orangepi-pc   \
>     -m 1G -smp 4 \
>     -cpu host \
>     --enable-kvm  \
>     -bios ${HOME}/QEMU_EFI.fd \
>     -drive if=none,file=${HOME}/ubuntu-22.04.1-live-server-arm64.iso,id=cdrom,media=cdrom\
>     -drive file=${HOME}/disk/ubuntu.img,index=1,media=disk,format=qcow2,id=ubuntuhd \
>     -vnc :1 \
>     -monitor none
qemu-system-aarch64: BIOS not supported for this machine

ostest@firefly:~$ sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
>     -M orangepi-pc   \
>     -m 1G -smp 4 \
>     -cpu cortex-a7 \
>     --enable-kvm  \
>     -drive if=none,file=${HOME}/ubuntu-22.04.1-live-server-arm64.iso,id=cdrom,media=cdrom\
>     -drive file=${HOME}/disk/ubuntu.img,index=1,media=disk,format=qcow2,id=ubuntuhd \
>     -vnc :1 \
>     -monitor none
qemu-system-aarch64: Cannot enable KVM when guest CPU has EL3 enabled
安装ubuntu

参考

在arm64上启动qemu虚拟机有两种方式,一种是通过-kernel 的方式boot kernel,另一种是先启动uefi再boot kernel。

QEMU默认将会采用seabios的启动方式

# 下载 QEMU_EFI.fd
wget http://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.fd

在这里插入图片描述

参考通过qemu-system-aarch64在x86上安装aarch64虚拟机

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -M virt \
    -m 2G -smp 6 \
    -cpu cortex-a57 \
    -bios ${HOME}/QEMU_EFI.fd \
    -drive if=none,file=${HOME}/ubuntu-22.04.1-live-server-arm64.iso,id=cdrom,media=cdrom \
    -device virtio-scsi-device -device scsi-cd,drive=cdrom \
    -drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \
    -vnc :1 \
   	-monitor stdio
   
# 不知道为啥这个monitor 重定向到 vnc里去了

# qemu 文档
-monitor dev
	Redirect the monitor to host device dev (same devices as the serial port). 
	The default device is vc in graphical mode and stdio in non graphical mode. 
	Use -monitor none to disable the default monitor.

在这里插入图片描述
带上kvm 选项


sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -M virt \
    -m 2G -smp 6 \
    -cpu host \
    -enable-kvm  \
    -bios ${HOME}/QEMU_EFI.fd \
    -drive if=none,file=${HOME}/ubuntu-22.04.1-live-server-arm64.iso,id=cdrom,media=cdrom \
    -device virtio-scsi-device -device scsi-cd,drive=cdrom \
    -drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \
    -vnc :1 \
    -monitor stdio

在这里插入图片描述

改用ubuntu 18.04
ostest@firefly:~/disk$ sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -m 2048 -cpu host -smp 2 -M virt -enable-kvm\
    -bios ${HOME}/QEMU_EFI.fd \
   -nographic \
     -drive if=none,file=${HOME}/disk/ubuntu-18.04-server-arm64.iso,id=cdrom,media=cdrom \
     -device virtio-scsi-device -device scsi-cd,drive=cdrom \
     -drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \
     -device virtio-blk-device,drive=hd0
[=3h
[=3h
[=3h
[=3h
[=3h
[=3h
Killed
问题

在arm机器上安装安装

参考 virt-manage 使用 通过,virt-manage 安装成功后,然后
使用virt-manage 的UEFI 固件成功安装

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -m 1G -cpu host -smp 2 -M virt -enable-kvm\
    -bios /usr/share/AAVMF/AAVMF_CODE.fd \
    -nographic \
    -drive if=none,file=${HOME}/disk/ubuntu-18.04-server-arm64.iso,id=cdrom,media=cdrom \
    -device virtio-scsi-device -device scsi-cd,drive=cdrom \
    -drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \
    -device virtio-blk-device,drive=hd0

安装成功后

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
    -m 1G -cpu host -smp 2 -M virt -enable-kvm\
    -bios /usr/share/AAVMF/AAVMF_CODE.fd \
    -drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -nographic

在这里插入图片描述
在这里插入图片描述

后面查看了官网项目一些文档资料 , qemu 项目里面有UEFI固件
在这里插入图片描述

sudo ${HOME}/qemu7/build/qemu-system-aarch64 \
  -m 1G -cpu host -smp 2 -M virt -enable-kvm\
  -bios ${HOME}/qemu7/build/pc-bios/edk2-aarch64-code.fd \
  -nographic \
  -drive if=none,file=${HOME}/disk/ubuntu-18.04-server-arm64.iso,id=cdrom,media=cdrom \
  -device virtio-scsi-device -device scsi-cd,drive=cdrom \
  -drive if=none,file=${HOME}/disk/ubuntu1.img,id=hd0 \
  -device virtio-blk-device,drive=hd0

在这里插入图片描述

UEFI

参考详写 UEFI & BIOS 安装 Arch Linux

ostest@ubuntu:~$ ls /sys/firmware/efi/efivars
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0001-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0002-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0003-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0004-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0005-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0006-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0007-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c
certdb-d9bee56e-75dc-49d9-b4d7-b534210f637a
certdbv-d9bee56e-75dc-49d9-b4d7-b534210f637a
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c
ErrOut-8be4df61-93ca-11d2-aa0d-00e098032b8c
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c
Key0000-8be4df61-93ca-11d2-aa0d-00e098032b8c
Key0001-8be4df61-93ca-11d2-aa0d-00e098032b8c
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c
MTC-eb704011-1402-11d3-8e77-00a0c969723b
OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformRecovery0000-8be4df61-93ca-11d2-aa0d-00e098032b8c
SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
SetupMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
SignatureSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c
Timeout-8be4df61-93ca-11d2-aa0d-00e098032b8c
VarErrorFlag-04b37fe8-f6ae-480b-bdd5-37d98c5e89aa
VendorKeys-8be4df61-93ca-11d2-aa0d-00e098032b8c

内核编译

参考

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
qemu-system-aarch64是一个运行ARM64架构的虚拟机的命令行工具。当我们在运行这个命令时,如果没有指定虚拟机类型,也没有默认设置,就会出现 "qemu-system-aarch64: no machine specified, and there is no default" 的报错信息。 这个报错的原因是因为在运行qemu-system-aarch64命令时,我们需要指定要运行的虚拟机的类型。虚拟机类型是根据具体的应用或需求来选择的,例如rpi3表示树莓派3型号的虚拟机,virt表示通用的虚拟机类型等等。如果没有指定虚拟机类型,qemu无法确定具体要运行哪个虚拟机,因此会出现这个错误。 解决这个问题的方法是在运行qemu-system-aarch64命令时,使用"-machine"参数来指定要运行的虚拟机类型。例如,如果我们想运行rpi3类型的虚拟机,命令可以修改为: "qemu-system-aarch64 -machine rpi3"。同时,也可以通过"-M"参数来指定虚拟机类型,例如: "qemu-system-aarch64 -M rpi3"。 此外,这个报错信息也提示我们当前没有默认设置的虚拟机类型。要设置默认虚拟机类型,可以使用"-machine"或"-M"参数,加上要设置的虚拟机类型,例如: "qemu-system-aarch64 -machine virt"。这样,当我们运行qemu-system-aarch64命令时,就默认使用指定的虚拟机类型。 综上所述,qemu-system-aarch64: no machine specified, and there is no default报错信息是因为运行qemu-system-aarch64命令时没有指定虚拟机类型,并且也没有默认设置。需要使用"-machine"或"-M"参数来指定当前要运行的虚拟机类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值