Skip to content

Provision workers with QEMU

QEMU is an open source virtualization tool, which allows you to launch VMs on many different architectures. Using QEMU together with meltcloud is handy to quickly get a node joined to your meltcloud clusters.

Prerequisites

  1. Create an iPXE Boot Artifact or reuse an existing one
  2. Download the ipxe.iso file used to launch the QEMU virtual machine.

Launch a Virtual Machine with QEMU

Directly launch a virtual machine using QEMU and the previously generated ipxe.iso boot image.

shell
# install QEMU
brew install qemu

# setup a path to store your QEMU VM files
disk_path=$HOME/qemu/melt-vm
mkdir -p ${disk_path}

# create a disk for the ephemeral root device that holds docker images
qemu-img create -f qcow2 ${disk_path}/melt-node.qcow2 10g

# iPXE ISO path - adjust if needed
ipxe_iso="$HOME/Downloads/ipxe.iso"

# assign a UUID - be aware that creating a new UUID will create a new machine in meltcloud
machine_uuid=$(uuidgen)

mem=3G # requires at least 3GB - give more for more workload
cpus=6 # no minimum requirement for CPU, but let's give it some power!

# start the machine (Ctrl-a, release, hit x to exit)
qemu-system-aarch64 \
  -uuid $machine_uuid \
  -m $mem \
  -smp $cpus \
  -device nec-usb-xhci,id=usb-bus \
  -device usb-storage,drive=ipxe-iso,removable=true,bootindex=0,bus=usb-bus.0 \
  -drive if=none,id=ipxe-iso,media=cdrom,file=${ipxe_iso},readonly=on \
  -drive file=$(brew --prefix qemu)/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw \
  -drive file=${disk_path}/melt-node.qcow2,if=virtio \
  -netdev user,id=n1 \
  -device virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19 \
  -nographic \
  -cpu host \
  -machine type=virt-9.0,accel=hvf
shell
# install QEMU
sudo apt install qemu-system libvirt-clients libvirt-daemon-system
sudo adduser `id -un` libvirt
sudo adduser `id -un` kvm

# create a disk for the ephemeral root device
DISK_PATH=~/melt-node.qcow2
qemu-img create -f qcow2 $DISK_PATH 10g

# give QEMU access to the disk file
sudo chown libvirt-qemu:kvm "$DISK_PATH"
pushd $(dirname $DISK_PATH)
setfacl -m user:libvirt-qemu:--x $(pwd)
while [[ $(pwd) != $HOME ]]; do
  cd ..
  pwd
  setfacl -m user:libvirt-qemu:--x $(pwd)
done
popd

# iPXE ISO path (Download from meltcloud foundry)
IPXE_ISO=~/Downloads/ipxe.iso

# assign a UUID - be aware that creating a new UUID will create a new machine in meltcloud
machine_uuid=$(uuidgen)

# start the machine (To exit press Alt + 2, then type "quit")
sudo qemu-system-x86_64 \
  -uuid $machine_uuid \
  -m size=3276800k \
  -accel kvm \
  -smp 2,sockets=2,cores=1,threads=1 \
  -object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":3355443200}' \
  -machine pc-i440fx-mantic,usb=off,vmport=off,dump-guest-core=off,memory-backend=pc.ram,hpet=off,acpi=on \
  -cdrom $IPXE_ISO \
  -display curses \
  -cpu host \
  -netdev user,id=hostnet0 \
  -device e1000,netdev=hostnet0,bus=pci.0,addr=0x3 \
  -drive file=$DISK_PATH,if=virtio \
  -boot order=d