qemu microvm

MicroVM is a lightweight way to do VMs, inspired by Firecracker.
Boot is handled by qboot, you still need to bring your own kernel (and initramfs) and root filesystem.

You don’t have PCI, so any “hardware” needs to be using virtio devices.
In this case, you can get a virtio-blk-device for disks, and a virtio-net-device for networking.

Step 0: Obtain a Gentoo VM image.

Find a recent version of the Gentoo VM images.

$ wget https://distfiles.gentoo.org/releases/amd64/autobuilds/20260811T083102Z/di-amd64-console-20260811T083102Z.qcow2 -O image.qcow2

Step 1: Extract the kernel and initramfs

Here we use app-emulation/libguestfs.

$ virt-copy-out -a image.qcow /boot .

Step 2: Run Qemu

$ cat run.sh
#!/bin/bash
QEMU_ARGS=(
    qemu-system-x86_64

    # Machine Type - As native as possible
    -M microvm
    --enable-kvm -cpu host

    # Machine size
    -smp 1 -m 1024M

    # Open a TTY that clients can detach from
    -nodefaults -no-user-config -nographic
    -serial pty:serial.pty

    # Kernel / initramfs
    -kernel ./boot/kernel-*
    -append "earlyprintk=ttyS0 console=ttyS0 root=/dev/vda2"
    -initrd ./boot/initramfs-*.img

    # Rootfs
    -device virtio-blk-device,drive=img0
    -drive file=./image.qcow2,if=none,format=qcow2,id=img0

    # Networking
    # User mode networking always works
    -device virtio-net-device,netdev=qemu0
    -netdev user,id=qemu0

    # Consider bridge networking too
    #-device virtio-net-device,netdev=qemu1
    #-netdev bridge,id=qemu1,br=br0
)
exec "${QEMU_ARGS[@]}"


Open the pty with a dialer of your choice

$ minicom -D ./serial.pty

Results

# systemd-analyze
Startup finished in 725ms (kernel) + 604ms (initrd) + 2.005s (userspace) = 3.336s
graphical.target reached after 2.002s in userspace.

Okay, that’s quick for a VM. And reasonable for a container. But not quite the milliseconds promised.
There’s definitely room for improvement here, with a different choice of base image.