记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

How to install Ubuntu Server for Arm in a QEMU aarch64 virtual machine

QEMU 模拟 aarch64虚拟机中安装ubuntu arm版系统

Follow the steps below to install Ubuntu Server 20.04 on a QEMU aarch64 (Armv8) virtual machine from the Linux command line. The x86 host system was running Ubuntu 18.04.  The virtual machine uses UEFI boot firmware.

Ubuntu Server is console based and so everything in these steps uses a console and no GUI.  I may show the steps for Ubuntu desktop with a GUI in a future post.

Prerequisites

1. Install QEMU

$ sudo apt-get install qemu-system-arm

2. Install a pre-built UEFI image for QEMU

$ sudo apt-get install qemu-uefi

3.  Download an Ubuntu distro install ISO image.   In this example we are using the Server variant of Ubuntu.   You can find 20.04 release images here: http://cdimage.ubuntu.com/ubuntu/releases/20.04/release/ 

$ wget -O ubuntu-20.04-live-server-arm64.iso http://cdimage.ubuntu.com/ubuntu/releases/20.04/release/ubuntu-20.04-live-server-arm64.iso

Prepare flash and disk images

The UEFI image will be placed in a 64MB simulated flash and an empty simulated 64MB flash will be used for UEFI variable.

1. Place the UEFI image in a 64MB simulated flash.

$ cp /usr/share/qemu-efi-aarch64/QEMU_EFI.fd flash0.img
$ truncate -s 64M flash0.img

2.  Create an empty 64MB flash image to hold UEFI variables.

$ truncate -s 64M flash1.img

3.  Set up empty disk qcow2 image (16G in this example) where Ubuntu will be installed.  For info on qcow images see https://en.wikipedia.org/wiki/Qcow.

$ qemu-img create -f qcow2 hda.qcow2 16G

Boot the virtual machine and run the Ubuntu installer

The install image ISO will appear as a CD drive to the virtual machine and will automatically launch the installer.  We doing a Ubuntu Server install and so everything is console based and there is no GUI.

$ qemu-system-aarch64 -M virt -cpu cortex-a57 -m 2048 \
-device virtio-net-pci,netdev=net0,romfile="" \
-netdev type=user,id=net0 \
-device virtio-blk-pci,drive=drv0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-pci,rng=rng0 \
-drive format=qcow2,file=hda.qcow2,if=none,id=drv0 \
-drive if=pflash,format=raw,file=flash0.img,readonly \
-drive if=pflash,format=raw,file=flash1.img \
-nographic \
-device virtio-scsi \
-device scsi-cd,drive=cd \
-drive if=none,id=cd,file=/local/install-images/ubuntu-20.04-live-server-arm64.iso

At the boot menu that appears select “Install Ubuntu Server”. 

 Follow the prompts until the installation is complete.

After the installation is complete shutdown the virtual machine and QEMU will exit to the host Linux prompt:

 $shutdown now

Boot the newly installed virtual machine 

Run QEMU to boot your newly installed virtual machine, but this time without the install media.

$ qemu-system-aarch64 -M virt -cpu cortex-a57 -m 2048 \
-device virtio-net-pci,netdev=net0,romfile="" \
-netdev type=user,id=net0 \
-device virtio-blk-pci,drive=drv0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-pci,rng=rng0 \
-drive format=qcow2,file=hda.qcow2,if=none,id=drv0 \
-drive if=pflash,format=raw,file=flash0.img,readonly \
-drive if=pflash,format=raw,file=flash1.img \
-nographic

You should arrive at an Ubuntu login prompt.

Congrats!



转载请标明出处【QEMU 模拟 aarch64虚拟机中安装ubuntu arm版系统】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论