qemu-system-aarch64使用记录
qemu-system-aarch64 使用記錄
- 下載安裝qemu
- 測試環(huán)境
- 查看是否支持KVM
- 機(jī)器配置
- 安裝ubuntu
- 記錄
- 運(yùn)行qemu
- 驗(yàn)證機(jī)器是否支持kvm
- -M
- 安裝ubuntu
- 改用ubuntu 18.04
- 問題
- 在arm機(jī)器上安裝安裝
- UEFI
- 內(nèi)核編譯
下載安裝qemu
#!/bin/bashout='> /dev/null' # out=echo ${HOME}gcc -v if [[ $? -ne 0 ]]; thensudo apt update ${out}sudo apt upgrade eval sudo apt-get install -y make gcc g++ gdb ${out} fininja --versionif [[ $? -ne 0 ]]; thencdif [[ ! -d ${HOME}/ninja ]]; thengit --versionif [[ $? -ne 0 ]]; theneval sudo apt-get install -y git ${out}figit clone https://gitee.com/gitmirror/ninja.gitif [[ $? -ne 0 ]]; thenecho " git clone ninja fail"exit 1fieval sudo apt-get install -y re2c ${out}ficd ${HOME}/ninjapython3 ./configure.py --bootstrap sudo cp ./ninja /usr/bin# 測試ninja --versionif [[ $? -ne 0 ]];thenecho " ninja install fail"exit 1fi ficd if [[ ! -d ${HOME}/qemu7 ]]; thenwget https://download.qemu.org/qemu-7.0.0.tar.xzif [[ $? -ne 0 ]];thenecho " qemu download fail"exit 1fi # 安裝依賴包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.xzmv qemu-7.0.0 qemu7 fi${HOME}/qemu7/build/qemu-system-aarch64 -versionif [[ $? -ne 0 ]]; thenecho "qemu not compile"cd ${HOME}/qemu7# arm64 編譯./configure --target-list=aarch64-softmmu --enable-debug --enable-debug-info --enable-kvm \--enable-trace-backends=simple --enable-virtfsif [[ $? -ne 0 ]];thenecho " qemu configure fail"exit 1fi# 開始編譯eval make -j$(nproc) ${out}if [[ $? -ne 0 ]];thenecho " qemu make fail"exit 1fi${HOME}/qemu7/build/qemu-system-aarch64 -version ficd測試環(huán)境
查看是否支持KVM
參考:
- ARM平臺(tái)檢測是否支持虛擬化的幾種常見方法
- 如何驗(yàn)證內(nèi)核是否支持KVM虛擬化?
- ARM對(duì)KVM支持概述
對(duì)于aarch64(arm64)架構(gòu),若支持KVM虛擬化,那么KVM代碼會(huì)直接編譯進(jìn)內(nèi)核
2020年3月,Linux 5.7 Kernel宣布將放棄支持 32位架構(gòu)的 KVM虛擬化支持,所以目前來看,要想較好的在ARM架構(gòu)上運(yùn)行KVM虛擬化,需要使用現(xiàn)代化的64位ARM架構(gòu)
# 如果/dev/kvm和/sys/module/kvm二者之一不存在說明KVM虛擬化是不支持的 ls -l /dev/kvm ls -l /sys/module/kvmcat /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機(jī)器配置
uname -a Linux firefly 5.10.110 #217 SMP Wed Oct 12 17:59:18 CST 2022 aarch64 aarch64 aarch64 GNU/Linuxfree -htotal used free shared buff/cache available Mem: 3.4Gi 2.7Gi 295Mi 115Mi 445Mi 590Mi Swap: 0B 0B 0Blscpu 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 lrcpc dcpop asimddp安裝ubuntu
# 創(chuàng)建鏡像 ${HOME}/qemu7/build/qemu-img create -f qcow2 ${HOME}/ubuntu.img 60Gsudo ${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
安裝成功后
記錄
運(yùn)行qemu
參考
- linux把用戶添加到組
- 使用 QEMU 啟動(dòng) ARM aarch64 架構(gòu) Ubuntu 虛擬機(jī)
- failed to find romfile “efi-virtio.rom“
- qemu 文檔
ubuntu-22.04.1-live-server-arm64.iso 下載
驗(yàn)證機(jī)器是否支持kvm
# 用戶添加到多個(gè)次要組中 usermod -a -G kvm ostest# 創(chuàng)建虛擬機(jī)硬盤 ${HOME}/qemu7/build/qemu-img create -f qcow2 ${HOME}/disk/ubuntu.img 100Gsudo ${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 argumentqemu-system-aarch64: The 'host' CPU type can only be used with KVM or HVF# qemu 文檔 -cpu modelSelect 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 pathSet 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 Abortedostest@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 machineostest@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
參考
- 編譯qemu/arm64的uefi
- 為QEMU創(chuàng)建基于UEFI的AARCH64虛擬機(jī)
在arm64上啟動(dòng)qemu虛擬機(jī)有兩種方式,一種是通過-kernel 的方式boot kernel,另一種是先啟動(dòng)uefi再boot kernel。
QEMU默認(rèn)將會(huì)采用seabios的啟動(dòng)方式
# 下載 QEMU_EFI.fd wget http://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.fd參考通過qemu-system-aarch64在x86上安裝aarch64虛擬機(jī)
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# 不知道為啥這個(gè)monitor 重定向到 vnc里去了# qemu 文檔 -monitor devRedirect 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 選項(xiàng)
改用ubuntu 18.04
- ubuntu-18.04-server-arm64.iso 下載地址
問題
- 虛擬機(jī)開機(jī)時(shí)出現(xiàn)Press ESC in 5 seconds to skip startup.nsh, any other key to continue問題的解決辦法
在arm機(jī)器上安裝安裝
參考 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 \-drive if=none,file=${HOME}/disk/ubuntu.img,id=hd0 \-device virtio-blk-device,drive=hd0 \-nographic
后面查看了官網(wǎng)項(xiàng)目一些文檔資料 , qemu 項(xiàng)目里面有UEFI固件
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- UEFI開發(fā)學(xué)習(xí)2 - 在qemu中運(yùn)行OVMF
- OVMF is an EDK II based project to enable UEFI support for Virtual Machines. OVMF contains sample UEFI firmware for QEMU and KVM.
- UEFI UBUNTU
內(nèi)核編譯
參考
- ARMv8架構(gòu)下修改Linux內(nèi)核并打開kvm硬件虛擬化支持
總結(jié)
以上是生活随笔為你收集整理的qemu-system-aarch64使用记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy_2(多维数组降为一维reva
- 下一篇: k-shingles与minhash技术