Skip to content

VM base build

All three VMs start from the same base: Debian 13 on an encrypted disk, a serial console, SSH by key only, Docker, automatic security updates, and its network set inside the VM: a tagged VLAN for infra and standby, the Mac’s own untagged network plus one tagged leg for home. This chapter builds that base once per VM. Chapters 6, 7 and 14 then add what makes each VM different.

Do the whole chapter for infra now. Come back for home when chapter 7 sends you here (from-scratch path only: the restore path moves the existing VM instead), and for standby when chapter 14 does.

infra home standby
Memory 4096 MB 4096 MB 4096 MB
CPU cores 2 4 2
Disk 96 GB 64 GB 256 GB (see chapter 14 for sizing)
VLAN 2 5, plus 4 10
Address 10.0.2.5 10.0.5.2 and 10.0.4.2 10.0.6.2
Network file vm/infra/etc/network/interfaces vm/home/etc/network/interfaces vm/standby/etc/network/interfaces

UTM disks are sparse: a 96 GB disk takes only what the VM has written.

Restore path for infra. An infra VM already exists, built on 2026-11-25 with an encrypted disk and the right address. If you carried its bundle over in step 2.9, double-click it on the new Mac to add it to UTM, then do only steps 5.7 to 5.14 on it: they are written so that running them on an existing VM is safe. In its settings raise the memory to 4096 MB first, and grow the disk as shown at the end of this chapter.

Set these once in the Terminal window you work in, with the VM’s name:

Terminal window
export VM=infra # or home, standby

Why. The ISO is the root of trust of the VM. A checksum proves the download is the file Debian published.

Mac

Terminal window
mkdir -p ~/Downloads/debian && cd ~/Downloads/debian
curl -LO https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/SHA256SUMS
ISO=$(grep -o 'debian-13[0-9.]*-arm64-netinst.iso' SHA256SUMS | head -1)
curl -LO "https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/$ISO"
shasum -a 256 -c SHA256SUMS --ignore-missing

Verify. The last command prints debian-13.x.x-arm64-netinst.iso: OK.

Rollback. Delete the folder.

Why. The Apple Virtualization backend is the fast one on Apple silicon. Bridging puts the VM straight on the switch port, where it can tag its own VLAN. The serial device is the only console that shows the disk passphrase prompt.

Mac UTM: + > Virtualize > Linux

  1. Tick Use Apple Virtualization. Boot ISO Image: the ISO from step 5.1.
  2. Memory and CPU cores from the table above.
  3. Storage: the disk size from the table. Shared directory: skip.
  4. Name: infra, home or standby, exactly. The scripts find VMs by these names. Tick Open VM Settings, then Save.
  5. In the settings:
    • Network: Network Mode: Bridged (Advanced), Bridged Interface: en0. Write down the MAC address.
    • Devices > New > Serial: mode Pseudo-TTY Device.
    • Remove the Sound device if one is listed.
  6. Save.

Verify. $U list shows the VM as stopped.

Rollback. In UTM, right-click the VM > Delete.

Why. R5: the disk is encrypted from the first write. The installer runs on the Mac’s own network (Trusted, VLAN 5, untagged), which has DHCP and internet, so it needs no VLAN setup. Two throwaway secrets are used during the install because nothing can be pasted into the installer. Step 5.8 replaces both with the real ones from 1Password.

Mac Start the VM in UTM and choose Install (the text installer). Answer:

Screen Answer
Language, location, keyboard English, Canada, your keyboard
Network Automatic (DHCP). It gets a 10.0.5.x address
Hostname infra, home or standby
Domain name empty
Root password leave empty, twice. The installer then gives your user sudo
Full name, username admin
User password temp-install-1 (replaced in step 5.8)
Partitioning Guided - use entire disk and set up encrypted LVM, then All files in one partition
Erasing data Cancel the erase with Cancel: a new virtual disk holds nothing to overwrite
Encryption passphrase temp-install-1 (replaced in step 5.8)
Amount of volume group max
Software selection Untick everything except SSH server and standard system utilities

When the installer finishes, let it reboot, then stop the VM ($U stop $VM), open its settings, and clear the ISO from the CD/DVD drive.

Verify. $U status $VM prints stopped, and the VM’s CD/DVD drive is empty.

Rollback. Delete the VM and start again at step 5.2.

Why. On this backend the kernel’s console is the serial port. The UTM window stops at “Loading initial ramdisk” and looks frozen, while the VM is in fact waiting for the passphrase on the serial side.

Mac

Terminal window
$U start $VM
sleep 5; screen "$(vm-tty $VM)"

If vm-tty prints nothing, read Serial (TTY) in the VM’s details in UTM and use that path. Press Return. At Please unlock disk vda3_crypt: type temp-install-1. The device name can differ (vda4_crypt): it does not matter. Log in as admin with temp-install-1, then:

Terminal window
ip -br addr

Note the 10.0.5.x address of enp0s1. If the interface has another name, use it wherever this guide writes enp0s1, including in the network file. Leave screen open in this tab.

Mac (a second Terminal tab)

Terminal window
export VM=infra VMIP=10.0.5.x # the address you just read

Verify. ping -c 2 $VMIP answers.

Rollback. $U stop $VM.

Why. From here on you work over SSH with the key held in 1Password. The folder vm/common holds the settings shared by the three VMs.

Mac

Terminal window
ssh-copy-id -f -i ~/.ssh/mac-admin.pub admin@$VMIP # asks for temp-install-1 once
scp -r $INFRA/vm/common admin@$VMIP:/tmp/common
scp $INFRA/vm/$VM/etc/network/interfaces admin@$VMIP:/tmp/interfaces

Verify. ssh admin@$VMIP hostname prints the VM’s name after a Touch ID prompt, with no password asked.

Rollback. ssh admin@$VMIP 'rm ~/.ssh/authorized_keys'.

Why. vlan and ethtool make the tagged network possible, resolvconf applies the DNS servers named in the network file, and the others are the tools the verification steps use. They are installed now, while the VM still has plain internet on the Mac’s network: on the tagged VLAN nothing works until ethtool has turned checksum offload off.

VM (ssh admin@$VMIP)

Terminal window
sudo apt update
sudo apt install -y vlan ethtool resolvconf curl ca-certificates rsync ndisc6 netcat-openbsd \
tcpdump dnsutils cifs-utils unattended-upgrades zram-tools systemd-timesyncd jq

Verify. dpkg -l vlan ethtool resolvconf | grep -c '^ii' prints 3.

Rollback. sudo apt purge the same list.

5.7 Send the console to the serial port for good

Section titled “5.7 Send the console to the serial port for good”

Why. The last console= named on the kernel line receives the passphrase prompt and the boot log. Naming hvc0 last makes that explicit, and tty0 keeps a copy in the UTM window.

VM

Terminal window
sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=hvc0"/' /etc/default/grub
sudo update-grub

Verify. grep '^GRUB_CMDLINE_LINUX_DEFAULT' /etc/default/grub prints GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=hvc0".

Rollback. Put quiet back in that line and run sudo update-grub.

5.8 Replace the throwaway secrets with the real ones

Section titled “5.8 Replace the throwaway secrets with the real ones”

Why. The disk passphrase and the user’s password now come from 1Password, sent over SSH so they never appear on screen or in a file. The new passphrase is added and tested before the old one is removed, so a typing error cannot lock the disk.

Mac

Terminal window
DEV=$(ssh admin@$VMIP "lsblk -lnpo NAME,FSTYPE | awk '\$2==\"crypto_LUKS\"{print \$1}'"); echo $DEV # for example /dev/vda3
ssh -t admin@$VMIP "sudo cryptsetup luksAddKey $DEV"

It asks three things. [sudo] password: temp-install-1. Enter any existing passphrase: temp-install-1. Enter new passphrase and its confirmation: in another tab run op read "op://Infrastructure/LUKS $VM/password" | pbcopy, then paste twice. Then test the new passphrase, remove the old one, and set the user’s password:

Terminal window
op read "op://Infrastructure/LUKS $VM/password" | pbcopy
ssh -t admin@$VMIP "sudo cryptsetup open --test-passphrase $DEV && echo NEW-PASSPHRASE-OK" # paste
ssh -t admin@$VMIP "sudo cryptsetup luksRemoveKey $DEV" # type temp-install-1
op read "op://Infrastructure/VM $VM user/password" | pbcopy
ssh -t admin@$VMIP "passwd" # current: temp-install-1, new: paste twice
pbcopy < /dev/null

Verify. ssh -t admin@$VMIP "sudo cryptsetup luksDump $DEV | grep -c '^ [0-9]: luks2'" prints 1 (one key slot), and the test line above printed NEW-PASSPHRASE-OK.

Rollback. While temp-install-1 is still a valid passphrase nothing is lost. After its removal, the only passphrase is the one in 1Password: check the item opens before you run luksRemoveKey.

5.9 Harden SSH and pin the parent interface down

Section titled “5.9 Harden SSH and pin the parent interface down”

Why. Keys only, one user, no root login. The two small files keep the untagged parent interface from ever taking an address on the Mac’s network, and load the VLAN module at boot. The sudoers file lets your user run sudo without the VM password, which is what allows the Mac to drive a VM with one ssh vm 'sudo …' line in every later chapter. The gate is the SSH key: it lives in 1Password and asks for Touch ID on each use. The password still protects the console.

VM

Terminal window
sudo install -m 644 /tmp/common/etc/ssh/sshd_config.d/10-hardening.conf /etc/ssh/sshd_config.d/
sudo install -m 644 /tmp/common/etc/sysctl.d/90-enp0s1-no-slaac.conf /etc/sysctl.d/
sudo install -m 644 /tmp/common/etc/modules-load.d/8021q.conf /etc/modules-load.d/
sudo install -m 755 /tmp/common/verify.sh /usr/local/bin/verify.sh
sudo install -m 440 /tmp/common/etc/sudoers.d/10-admin-nopasswd /etc/sudoers.d/ && sudo visudo -c
sudo sshd -t && sudo systemctl reload ssh
sudo modprobe 8021q

Keep this SSH session open and test from a second tab before you close it.

Verify. From the Mac, ssh admin@$VMIP true still works, ssh admin@$VMIP 'sudo -n true && echo SUDO-OK' prints SUDO-OK, and ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password admin@$VMIP true is refused with Permission denied (publickey).

Rollback. sudo rm /etc/ssh/sshd_config.d/10-hardening.conf /etc/sudoers.d/10-admin-nopasswd && sudo systemctl reload ssh.

Why. Every service runs as a container. Docker’s own repository carries the current engine and the Compose plugin. The daemon file caps container logs so they cannot fill the disk.

VM

Terminal window
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo install -m 644 /tmp/common/etc/docker/daemon.json /etc/docker/daemon.json
sudo systemctl restart docker
sudo usermod -aG docker admin
sudo install -d -o admin -g admin /srv/stack

Log out and in again so the group applies.

Verify. docker run --rm hello-world | grep -c 'Hello from Docker' prints 1, and docker info --format '{{.LoggingDriver}}' prints local.

Rollback. sudo apt purge docker-ce docker-ce-cli containerd.io docker-compose-plugin.

5.11 Unattended security updates and a lean system

Section titled “5.11 Unattended security updates and a lean system”

Why. The house’s DNS server should receive security fixes without waiting for you. Compressed swap in memory avoids disk swap inside a VM, and a journal cap keeps logs bounded.

VM

Terminal window
echo 'unattended-upgrades unattended-upgrades/enable_auto_updates boolean true' | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive unattended-upgrades
sudo sed -i 's/^#\?ALGO=.*/ALGO=zstd/; s/^#\?PERCENT=.*/PERCENT=50/' /etc/default/zramswap
sudo systemctl restart zramswap
sudo mkdir -p /etc/systemd/journald.conf.d
printf '[Journal]\nSystemMaxUse=200M\n' | sudo tee /etc/systemd/journald.conf.d/size.conf
sudo systemctl restart systemd-journald
sudo systemctl disable --now man-db.timer e2scrub_all.timer
sudo timedatectl set-timezone America/Toronto

Unattended upgrades install fixes but never reboot the VM. Kernel updates take effect at the monthly restart of chapter 15.

Verify. systemctl is-enabled unattended-upgrades prints enabled, swapon --show | grep -c zram prints 1, and timedatectl show -p NTPSynchronized --value prints yes.

Rollback. sudo dpkg-reconfigure unattended-upgrades and answer No.

5.12 Switch the network to the VM’s own address

Section titled “5.12 Switch the network to the VM’s own address”

Why. Until now the VM sat on the Mac’s network with an address from DHCP. infra and standby belong in their own VLAN, tagged inside the VM. home stays in the Trusted network, untagged like the Mac (J27), with a fixed address and one tagged leg in IoT. The file turns checksum offload off on the parent interface: without that, ping works on the VLAN and every TCP and UDP connection fails. dhcpcd is disabled because it would keep an address on the Mac’s network and rewrite the DNS settings.

home only, before you go on: the file gives the VM 10.0.5.2. If chapter 7 told you to start at 10.0.5.20, edit /tmp/interfaces now as that chapter says.

VM, from the screen tab of step 5.4, not over SSH: the SSH session dies when the address changes.

Terminal window
sudo systemctl disable --now dhcpcd 2>/dev/null; sudo apt purge -y dhcpcd-base 2>/dev/null
sudo cp /etc/network/interfaces /etc/network/interfaces.installer
sudo rm -f /etc/network/interfaces.d/*
sudo install -m 644 /tmp/interfaces /etc/network/interfaces
sudo reboot

The VM restarts and asks for the passphrase in the same screen tab. If the tab closed, reopen it with screen "$(vm-tty $VM)". Paste the passphrase (op read "op://Infrastructure/LUKS $VM/password" | pbcopy in another tab). Log in with the password from VM <name> user.

Verify. On the console, ip -br addr shows the address from the table on enp0s1.<vlan> and no IPv4 address on enp0s1. For home it is the reverse: 10.0.5.2 on enp0s1 itself, and 10.0.4.2 on enp0s1.4. From the Mac, ssh $VM hostname answers (the short names come from step 4.8).

Rollback. On the console: sudo cp /etc/network/interfaces.installer /etc/network/interfaces && sudo apt install -y dhcpcd-base && sudo reboot. The VM returns to the Mac’s network by DHCP. Note that apt needs the network: if the tagged VLAN never worked, run sudo ip link set enp0s1 up && sudo dhcpcd enp0s1 after restoring the file to get an address by hand first.

If ping to the gateway fails on the tagged VLAN: on the Mac run sudo tcpdump -eni en0 vlan while the VM pings. Tagged frames shown means the Mac’s bridge passes them, so check step 3.5 (the port must carry that VLAN tagged, and Trusted untagged). For standby, also check that the Standby network exists (step 3.3).

Why. This is the routine after every restart of the Mac. Testing it now, on one VM, proves vm-unlock on your hardware before the house depends on it.

Mac

Terminal window
ssh $VM sudo poweroff; sleep 15
$U start $VM --hide
sleep 8; vm-unlock $VM
sleep 40; ssh $VM uptime

Verify. vm-unlock prints <vm>: passphrase sent, and uptime shows less than two minutes.

Rollback. If vm-unlock fails, unlock by hand as in step 4.12 and note the failure for chapter 16. Everything else in the guide works with the manual way.

Why. One read-only script answers “is this VM’s base healthy?” now and on any later day.

Mac

Terminal window
ssh $VM verify.sh 2 # the VLAN id of the VM's main network: 2 for infra, 5 for home, 6 for standby

Verify. Compare with this table:

Line Expected
offload tx-checksumming: off and rx-checksumming: off
addresses infra, standby: enp0s1 UP with no IPv4 address, enp0s1.<vlan> with the VM’s address. home: enp0s1 with 10.0.5.2, enp0s1.4 with 10.0.4.2
dhcpcd inactive, or nothing
resolv infra and standby: 1.1.1.2 and 1.0.0.2. home: 10.0.2.5 then 10.0.5.1
route dev enp0s1.<vlan>. home: dev enp0s1
mtu 0% packet loss
TCP OK
DNS an address for debian.org
grub console=tty0 console=hvc0
luks one line containing crypt
ssh permitrootlogin no and passwordauthentication no
updates enabled
clock yes
docker an empty list for now

On home, DNS answers only once the infra VM serves it (chapter 6), or through the second server 10.0.5.1.

Rollback. None needed, read only.

Why. A fixed entry in the controller stops DHCP from ever giving the VM’s address to something else, and shows the VM under its name. A copy of the bundle taken now is a clean base to return to.

UniFi Client Devices: find the client with the MAC address noted in step 5.2 (it appears on the VM’s VLAN). Settings: name it infra, home or standby, and set Fixed IP Address to its address.

Mac

Terminal window
ssh $VM sudo poweroff; sleep 20
mkdir -p ~/vm-base
cp -Rc ~/Library/Containers/com.utmapp.UTM/Data/Documents/$VM.utm ~/vm-base/$VM-base.utm
$U start $VM --hide; sleep 8; vm-unlock $VM

cp -c makes an instant copy that shares disk blocks, so it costs almost no space. Do not use one VM’s copy as the start of another VM: both would share the same disk master key.

Verify. The controller lists the VM under its name with the fixed address, and ls ~/vm-base shows the copy.

Rollback. Delete the copy. Remove the fixed address in the controller.

Mac, with the VM stopped: in UTM, the VM’s Settings > Drives > the disk > Resize. Then start and unlock the VM, and inside it:

Terminal window
DEV=$(lsblk -lnpo NAME,FSTYPE | awk '$2=="crypto_LUKS"{print $1}') # for example /dev/vda3
sudo apt install -y cloud-guest-utils
sudo growpart ${DEV%[0-9]*} ${DEV##*[a-z]}
sudo cryptsetup resize $(lsblk -lnpo NAME,TYPE | awk '$2=="crypt"{print $1}')
sudo pvresize $(sudo pvs --noheadings -o pv_name | tr -d ' ')
sudo lvextend -r -l +100%FREE $(findmnt -no SOURCE /)
df -h /

cryptsetup resize asks for the disk passphrase.

A VM that boots to a passphrase prompt on its serial console, unlocks from 1Password, answers at its fixed address on its own network, accepts SSH by key only, updates itself, and runs Docker. It serves nothing yet.