Booting Debian VM in a second

I wanted to have a fast boot virtual machine image to do a quick test and run containers. So I tried to trim down a cloud image from Debian.

The end result is a VM that can boot from QEMU command line into login prompt with roughly one second.

I could get below 1 second by not installing docker but since that is a common tool and demostrates a featureful environment rather than being absolute minimalistic.

The method I used is mainly inspecting dmesg and systemd-analyze outputs, and find components that take long time in the critical chain.

Here are the list of things I changed:

  1. Kernel rebuilt from upstream tree. Only include necessary modules as Y, and avoid any expensive probing or detecting such as raid6, ata, mouse.
  2. Comment out optional /etc/fstab entries
  3. Disable a bunch of systemd services after checking out systemd-analyze critical-chain, including /lib/systemd/system/systemd-binfmt.service

I used dhcpcd service in the VM which is not the fastest to configure the guest network. Using a static config will likely allow faster ssh access.

Published by