如何以最簡單的方式在Qemu下測試ARM Ubuntu?

如何以最簡單的方式在Qemu下測試ARM Ubuntu?

我想在 Qemu 下使用 ARM 版本的 Ubuntu(具有圖形支援),但我在找到有關如何最輕鬆地完成它的教程時遇到問題(我更願意只下載一些圖像並運行一個命令來執行它) 。如何以最少的麻煩實現這一目標?

答案1

在這個答案中:https://askubuntu.com/questions/281763/is-there-any-prebuilt-qemu-ubuntu-image32bit-online/1081171#1081171我已經描述了 Ubuntu 18.04 來賓/主機的以下工作設定:

  • 雲端映像arm64:最快的入門設置
  • debootstrap arm64:相當快,但允許更多圖像定制

這些設定提供預先建置的磁碟映像,並且不通過安裝程式。它們是迄今為止我見過的最好的選擇。

接下來,我還設法在 QEMU 上運行 arm64 伺服器映像。然而,這需要透過安裝程式進行,除非您不在具有 KVM 的 ARM 主機上,否則安裝速度非常慢,幾乎不切實際。這是特別痛苦的,因為需要數十次互動才能完成安裝。

這是在 Ubuntu 18.10 主機上測試的伺服器腳本:

#!/usr/bin/env bash

set -eux

# Tested on Ubuntu 18.10.
# - https://superuser.com/questions/942657/how-to-test-arm-ubuntu-under-qemu-the-easiest-way
# - https://askubuntu.com/questions/797599/how-to-run-ubuntu-16-04-arm-in-qemu

# Parameters.
# This filename may need updating, check http://cdimage.ubuntu.com/releases/18.04/release/
id=ubuntu-18.04.3-server-arm64   
#id=debian-9.6.0-arm64-xfce-CD-1
img="${id}.img.qcow2"
img_snapshot="${id}.img.snapshot.qcow2"
iso="${id}.iso"
flash0="${id}-flash0.img"
flash1="${id}-flash1.img"

# Images.
if [ ! -f "$iso" ]; then
  wget "http://cdimage.ubuntu.com/releases/18.04/release/${iso}"
fi
if [ ! -f "$img" ]; then
  qemu-img create -f qcow2 "$img" 1T
fi
if [ ! -f "$img_snapshot" ]; then
  qemu-img \
    create \
    -b "$img" \
    -f qcow2 \
    "$img_snapshot" \
  ;
fi
if [ ! -f "$flash0" ]; then
  dd if=/dev/zero of="$flash0" bs=1M count=64
  dd if=/usr/share/qemu-efi/QEMU_EFI.fd of="$flash0" conv=notrunc
fi
if [ ! -f "$flash1" ]; then
  dd if=/dev/zero of="$flash1" bs=1M count=64
fi

# Run.
#
# cdrom must be scsi or else the installation fails midway with:
#
# > Detect and mount CD-ROM
# >
# > Your installation CD-ROM couldn't be mounted. This probably means
# > that the CD-ROM was not in the drive. If so you can insert it and try
# > again.
# >
# > Retry mounting the CD-ROM?
# > Your installation CD-ROM couldn't be mounted.
#
# This is because the drivers for the default virtio are not installed in the ISO,
# because in the past it was not reliable on qemu-system-aarch64.
#
# See also:
# https://bazaar.launchpad.net/~ubuntu-testcase/ubuntu-manual-tests/trunk/view/head:/testcases/image/1688_ARM64_Headless_KVM_Guest
qemu-system-aarch64 \
  -cpu cortex-a57 \
  -device rtl8139,netdev=net0 \
  -device virtio-scsi-device \
  -device scsi-cd,drive=cdrom \
  -device virtio-blk-device,drive=hd0 \
  -drive "file=${iso},id=cdrom,if=none,media=cdrom" \
  -drive "if=none,file=${img_snapshot},id=hd0" \
  -m 2G \
  -machine virt \
  -netdev user,id=net0 \
  -nographic \
  -pflash "$flash0" \
  -pflash "$flash1" \
  -smp 2 \
;

GitHub 上游

另請參閱 Raspberry Pi 仿真:https://stackoverflow.com/questions/28880833/how-to-emulate-the-raspberry-pi-2-on-qemu/45814913#45814913

amd64 桌面顯示於:https://askubuntu.com/questions/884534/how-to-run-ubuntu-16-04-desktop-on-qemu/1046792#1046792

相關內容