Skip to content
Matthias Schiffer edited this page Dec 14, 2023 · 2 revisions

Running Gluon in a Virtual Machine is possible on a number of different VM host applications. Our x86-64 and x86-generic targets provide images in VDI (VirtualBox), VMDK (VMware) and raw .img image (qemu/generic). Starting with the upcoming Gluon 2023.2 release, the images can be booted both via UEFI and legacy BIOS boot; older releases do not provide UEFI support.

2023.2 will also support the armsr-armv7 and armsr-armv8 targets, which can be used for virtualization of 32bit and 64bit ARM systems with UEFI (tested on qemu).

qemu

qemu can be a valuable tool for quickly running tests on a Gluon build without the need to flash actual hardware.

Useful arguments when running qemu in a terminal:

  • -m 256M assigns 256MiB of RAM to the VM
  • -chardev stdio,id=char0,signal=off -serial chardev:char0: Enable a serial console and connect to stdio. signal=off causes Ctrl-C and similar key combinations to be passed into the VM instead of terminating qemu
  • -display none -vga none: Disable graphical output, as it is unneeded when using the serial console
  • -net nic,macaddr=xx:xx:xx:xx:xx:xx -net user,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:7080-:80: Add a network interface allowing IPv4 WAN access; qemu will internally run NAT for IP packages. The forwards allow accessing the VM's SSH and HTTP servers on the host ports 127.0.0.1:2222 and 127.0.0.1:7080. The VM's Ethernet interface needs to use the IP address 10.0.2.15 for the forwards to work (assigned via DHCP automatically when the interface is used as WAN and the node is not in config mode)

When using a VM image with the same architecture as the host and KVM is supported by the kernel and the hardware, the options -enable-kvm -cpu host should be passed to enable KVM to enable native virtualization rather than full emulation of the CPU.

x86

Use qemu-system-x86_64 -machine q35 for x86-64 and qemu-system-i386 -machine q35 for x86-generic.

For UEFI boot, a UEFI firmware must be passed to qemu using the -bios argument. Matching firmwares can be found in the ovmf and ovmf-ia32 packages on Debian and in the edk2-ovmf package on Arch Linux. They will be installed under the following paths:

  • /usr/share/OVMF/OVMF_CODE.fd (x86-64, Debian)
  • /usr/share/edk2/x64/OVMF_CODE.fd (x86-64, Arch Linux)
  • /usr/share/OVMF/OVMF32_VARS_4M.fd (x86-generic, Debian)
  • /usr/share/edk2/ia32/OVMF_CODE.fd (x86-generic, Arch Linux)

Note: Only x86-64 boot on Arch Linux has been tested with UEFI at the time of writing.

ARM

Use qemu-system-aarch64 -machine virt for armsr-armv8 and qemu-system-arm -machine virt for armsr-armv7.

The ArmSR targets always require a UEFI firmware to be passed via the -bios argument. Firmwares can be found in the qemu-efi-aarch64 and qemu-efi-arm packages on Debian and in the edk2-aarch64 and edk2-arm packages on Arch Linux.

  • /usr/share/AAVMF/AAVMF_CODE.fd (armsr-armv8, Debian)
  • /usr/share/edk2/aarch64/QEMU_CODE.fd (armsr-armv8, Arch Linux)
  • /usr/share/AAVMF/AAVMF32_CODE.fd (armsr-armv7, Debian)
  • /usr/share/edk2/arm/QEMU_CODE.fd (armsr-armv7, Arch Linux)

Note: Only boot on Arch Linux has been tested (for both ARMv7 and ARMv8) at the time of writing. Native virtualization using KVM has not been tested on ARM at the time of writing.

Examples

Boot x86-64 via UEFI with KVM, serial console and one network interface:

qemu-system-x86_64 \
	-bios /usr/share/edk2/x64/OVMF_CODE.fd \
	-enable-kvm \
	-machine q35 \
	-cpu host \
	-m 256M \
	-display none -vga none \
	-chardev stdio,id=char0,signal=off \
	-serial chardev:char0 \
	-net nic,macaddr=xx:xx:xx:xx:xx:xx \
	-net user,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:7080-:80 \
	gluon-x86-64.img

Boot armsr-armv7 with full emulation, serial console and one network interface:

qemu-system-arm \
	-bios /usr/share/edk2/arm/QEMU_CODE.fd \
	-machine virt \
	-m 256M \
	-display none -vga none \
	-chardev stdio,id=char0,signal=off \
	-serial chardev:char0 \
	-net nic,macaddr=xx:xx:xx:xx:xx:xx \
	-net user,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:7080-:80 \
	gluon-armsr-armv7.img

When emulating an ArmSR target on x86 for development purposes, ARMv7 yields much better performance than ARMv8.

Clone this wiki locally