Skip to main content

Deploy an ARM64 Fedora VM on your PC: 3 steps

Set up a virtual machine to test your applications, binaries, and container images on different architectures.
Image
What's your favorite IDE?

Image by StockSnap from Pixabay

Sometimes you need to quickly check an operating system feature running on a different architecture. There are several reasons you might work with different architectures, including:

This article is for you if you require a full operating system and can't test directly on a dedicated device. In the case of an ARM64-embedded device, doing this is straightforward. You can run a different architecture's virtual machine (VM) on standard x86_64 architecture, although it is not recommended for production. Because this is an emulation, you can't expect high performance. Your experience will depend on your PC's capabilities.

Objective

The main objective of this exercise is to set up a usable ARM64 Fedora VM as easily and quickly as possible. I have chosen the ARM64 architecture because it is the most popular for smartphones, Internet of Things (IoT), and other embedded devices.

[ Get the guide to installing applications on Linux. ]

Prerequisites

I recommend installing Fedora's complete virtualization group of packages on the host. Not all are needed for configuring and starting a VM, but you might find the additional tools useful later when working with your new VM.

Install the package group using DNF:

$ sudo dnf group install --with-optional virtualization

You can find more information about the virtualization group at Fedora's virtualization landing page.

You also need to install qemu-system-aarch64 to get the ARM64 virtualization:

$ sudo dnf install qemu-system-aarch64

Create and run the VM

Once you have installed the prerequisites, you can start building your VM.

[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]

1. Prepare the image using virt-builder

The quickest way to create a Fedora image is to use virt-builder. Generate a Fedora 35 image for ARM64 architecture using a 10GB raw image file:

$ virt-builder fedora-35 --arch aarch64 --size 10G --arch aarch64
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
[ 4.5] Downloading: http://builder.libguestfs.org/fedora-35-aarch64.xz
[ 5.2] Planning how to build this image
[ 5.2] Uncompressing
[ 10.1] Resizing (using virt-resize) to expand the disk to 10.0G
[ 31.2] Opening the new disk
[ 35.4] Setting a random seed
[ 35.5] Setting passwords
virt-builder: Setting random password of root to iPehMcWTKjxN3GEx
[ 36.4] Finishing off
Output file: fedora-35.img
Output size: 10.0G
Output format: raw
Total usable space: 10.0G
Free space: 8.9G (89%)

If you don't enter an option for the root password, virt-builder generates a random one, which is visible in the command output.

NOTE: virt-builder has a limited number of image variations for architectures other than x86_64. You can list them by executing virt-builder --list. In this example, I use Fedora 35, even though Fedora 36 is available. The newest version for the ARM64 target is delayed. If that is a problem in your setup, I recommend either upgrading the VM during runtime or proceeding to the Alternative approaches section below.

2. Provision the VM using virt-install

Once you have created the image, use virt-install to build a VM and run an operating system on it for the first time. This example creates a fedora-35-aarch64 profile with 4GB of RAM and 4 CPUs assigned using the previously created fedora-35.img:

$ sudo virt-install -v --name fedora-35-aarch64 --ram 4096 \
	--disk path=fedora-35.img,cache=none --nographics --os-variant fedora35  \
	--import --arch aarch64 --vcpus 4

After the first system boot, you can log in to your VM. The login prompt should indicate you are running the aarch64 kernel, as seen in the image below:

Image
VM booted and displaying the correct kernel
(Jakub Guzik, CC BY-SA 4.0)

3. Use virsh to manage the VM

virsh is the main interface for managing guest domains. You can use the tool to create, pause, and shut down domains. Once you create the VM using virt-install, it becomes visible to virsh:

$ sudo virsh list --all
 Id   Name                State
------------------------------------
 -    fedora-35-aarch64   shut off

Use the following command to start the VM:

$ sudo virsh start fedora-35-aarch64
Domain 'fedora-35-aarch64' started

Read 8 Linux virsh subcommands for managing VMs on the command line to learn more about virsh.

Alternative approaches

If the solution above does not suit your needs, you can familiarize yourself with these alternative approaches.

1. Use the official Fedora aarch64 image

You can use the official Fedora aarch64 image for alternative architectures, especially if the version you need has not landed in virt-builder yet. For example, to get a Fedora 36 Minimal raw image, enter:

$ wget https://download.fedoraproject.org/pub/fedora-secondary/releases/36/Spins/aarch64/images/Fedora-Minimal-36-1.5.aarch64.raw.xz -O f36.xz && unxz f36.xz

Pay attention to the last digits of the file. At the time of this writing, the newest available image was Fedora-Minimal-36-1.5.aarch64.raw.xz. In the future, you can update this command with a newer image version.

[ Cheat sheet: Get a list of Linux utilities and commands for managing servers and networks. ]

The previous command unpacked the image using unxz to f36, so it is ready to use. To provision an unpacked image, execute virt-install:

$ sudo virt-install -v --name fedora-36-aarch64 --ram 4096 \
	--disk path=f36,cache=none --nographics --os-variant fedora36  \
	--import --arch aarch64 --vcpus 4

The image is almost ready but needs additional configuration. After the initial startup, you will see a menu with five configuration options. To quickly get the image ready, you need to follow only steps 4) User creation or 5) Root password and continue as shown in the example below:

Image
configuration options menu
(Jakub Guzik, CC BY-SA 4.0)

After a brief configuration, the Fedora 36 VM is ready to be used.

2. Use qemu-system-aarch64 instead of virsh

If you don't want to use a managed VM and rely on virsh, there is a more traditional way to run a VM using qemu-system-aarch64 directly.

To run the f36 image from the previous section, enter:

$ qemu-system-aarch64 -nographic -m 4096M -cpu cortex-a57 -smp 4 \
	-netdev user,id=unet -device virtio-net-pci,netdev=unet \
    -drive file=f36 -M virt \
    -bios /usr/share/edk2/aarch64/QEMU_EFI.fd

If the virtualization package group is missing on your machine, you must install the edk2-aarch64 package to have QEMU_EFI.fd on your operating system.

Wrap up

This article only touched on the basics of the ARM64 guest operating system. You can install other Linux versions and distributions, but you need to do your own research to get ready-to-use images. virt-builder provides only a few configurable ARM64 image targets, with the more recent only for Fedora. Thankfully, Linux distributions usually offer examples for creating images for ARM64. You may need to adjust these images to your needs manually. If so, read Use libguestfs to manage virtual machine disk images to learn more about managing VM images.

Finally, every command I used has multiple command-line options that modify behavior. I encourage you to visit their respective man pages to consult these variations.

Topics:   Linux   Virtualization  
Author’s photo

Jakub Guzik

Jakub is a software engineer with a passion for Linux and system administration. He previously worked in the field of embedded systems and multi-arch solutions. He recently switched his interest to containers and orchestration. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.