Home · Volume 4 · Chapter 05

📖 Chapter 05 — VMs with KVM

Full operating systems in software. The right tool when containers aren't enough.

v0.1 · draft Vol 4 · Ch 05
~12 min

Learning Objectives

Introduction

From Chapter 03: containers are the default. Reach for VMs when you need a different OS, kernel access, or strong isolation. This chapter is the practical VM: how to create one, install an OS, configure the basics, and use it.

When to use a VM

Use a VM when:

TrueNAS and KVM

TrueNAS Scale uses KVM (the Linux kernel's hypervisor) for VMs. The setup is in the TrueNAS web UI:

  1. Virtualization → Add.
  2. Choose an operating system (Linux, Windows, FreeBSD, etc.).
  3. Upload or specify an installer ISO. (You'll need to download this — Ubuntu, Debian, Fedora, Windows installer ISOs are all available from their respective sites.)
  4. Configure the VM:
    • Name: the VM's name (e.g., "dev-vm")
    • CPU: number of virtual CPUs (start with 2-4)
    • RAM: in MB or GB (start with 4-8 GB for a Linux dev VM, 8-16 GB for a Windows VM)
    • Disk: create a new zvol (block device in ZFS) for the VM's main disk
    • Network: attach to a virtual network (the default bridge is fine)
  5. Save. The VM is created. Click "Start" to boot it.

On first boot, the VM boots from the ISO (you attached). Install the OS. After installation, eject the ISO and reboot. The VM is now running the installed OS.

Resource sizing

The right amount of CPU, RAM, and disk for a VM depends on the workload:

VM typevCPUsRAMDisk
Linux dev VM2-44-8 GB50-100 GB
Linux server VM2-44-8 GB50-100 GB
Linux desktop VM48 GB100 GB
Windows 11 VM4-88-16 GB100-200 GB
K8s/k3s node2-44-8 GB50 GB

Start small. You can always increase resources; shrinking is harder (you'd have to resize the disk).

Networking in a VM

By default, the VM is on a virtual network bridge. It can reach the host and the internet. From the host (or any other device on the LAN), you can reach the VM at its IP address (assigned by the VM's DHCP, which is the host's built-in DHCP for the virtual network).

For a static IP, configure it in the VM's network settings (the standard OS network configuration). For port forwarding (e.g., expose the VM's web server on port 80 to the LAN), use the host's NAT/port forwarding in the TrueNAS VM settings.

For an isolated VM (one that can reach the internet but not the LAN), create a separate virtual network with no bridge to the host's physical network. The VM is on a private subnet, can reach the internet through the host's NAT, but is invisible to other LAN devices.

Accessing the VM

Three ways:

For most home lab use, SSH (Linux) or RDP (Windows) is the right answer. The console is for the initial setup only.

Storage for VMs

Two options:

For most home lab VMs, qcow2 files are fine. They're easy to back up, easy to copy, easy to delete. For VMs that need every bit of I/O performance (database servers, large compilation jobs), use a zvol.

Snapshots for VMs

TrueNAS lets you snapshot a VM. The snapshot is a frozen copy of the VM's disk and state. You can roll back to it if the VM gets into a bad state.

To snapshot a VM:

  1. Stop the VM (or take a live snapshot if the filesystem supports it — most modern filesystems do).
  2. TrueNAS → Virtualization → Select the VM → Snapshot.
  3. The snapshot is a ZFS snapshot of the zvol or a copy-on-write snapshot of the qcow2 file.

For the "I just installed the OS, before I start customizing" moment, take a snapshot. For the "I just installed all the apps, before I start using them" moment, take another. Roll back to the snapshot if something breaks.

Backing up VMs

VMs are just files (or zvols). Back them up like any other data.

For qcow2 files: copy the file to a backup location. Compress it for smaller backups. Use qemu-img convert to convert between formats if needed.

For zvols: use zfs send | zfs receive to replicate the zvol. This is the same pattern as the dataset replication from Volume 3, Chapter 5.

For ongoing VM backups, a simple cron job that copies the qcow2 file to a backup dataset, once a day or once a week, is sufficient. For most home lab VMs, the data on the VM is more important than the VM itself (the OS is reproducible; the data is not).

The "VM as development environment" pattern

For software development, the right pattern is often: a VM that matches your production environment, and your laptop is just a thin client.

The benefit: the dev environment is reproducible. If your laptop dies, you can spin up a new VM and have the same dev environment. The laptop is just the editor; the VM is the workspace.

The "Windows VM" pattern

For Windows-only apps (Microsoft Office, Adobe Creative Cloud, a piece of software that only ships for Windows), a Windows VM is the right answer. The setup:

  1. Create a Windows VM in TrueNAS.
  2. Install Windows from an ISO.
  3. Activate Windows with a license (or use it unactivated with the watermark).
  4. Install the Windows-only apps.
  5. Connect from your laptop via RDP.

For best performance, dedicate 8+ GB of RAM and 4+ vCPUs to the Windows VM. Enable RemoteFX or the equivalent GPU acceleration if your hardware supports it.

The "VM as honeypot or sandbox" pattern

For security research, a VM you don't trust anything in is the right answer. Examples:

Use a VM with no access to the family network. Take a snapshot before each session. Roll back to the snapshot (or delete the VM) after the session. The blast radius of a malicious app is the VM, not the host.

Common mistakes

Engineering Note

VMs are for things containers can't do. Don't reach for VMs out of habit. They're heavier (more RAM, more CPU, more disk), slower to start, and harder to manage than containers. The default is containers. The exception is when the workload really needs a different OS, kernel access, or strong isolation. The default is more efficient.

Summary

VMs in TrueNAS: KVM-based, configured in the web UI. One VM per workload. Use a zvol for performance-sensitive VMs, a qcow2 file for most. SSH for Linux, RDP for Windows. Snapshots before changes. Back up the VM files. Don't over-allocate resources. Don't store irreplaceable data only in a VM. Use VMs when containers aren't enough; use containers when VMs aren't needed.

Checklist

Looking Ahead

Chapter 06 is reverse proxies and TLS: how to expose services to the internet with HTTPS, the right way. Traefik, Caddy, and Nginx are the tools. The chapter that turns "I have a service running on port 8080" into "I have a service available at https://app.mydomain.com with a real certificate."

Ch 05 · v0.1 · drafted from the original ChatGPT conversation, July 2026