---
title: "Plain QEMU"
description: "The Colima setup done by hand with plain QEMU, Lima or Colima on an Apple silicon Mac, without the tutorial scripts."
source: "EQTY Notary"
---
This page does what the [Colima](./colima.mdx) tutorial's scripts do, by hand, for a plain QEMU
VM. The result is an Ubuntu VM under QEMU with HVF acceleration, a vTPM attached that the notary
manages, with its seed and IAK in the Secure Enclave, and any container started with
`--device /dev/tpmrm0` able to use it.

Docker Desktop, OrbStack, Podman machine, Apple's `container` and Tart cannot do this. They run
on Apple's Virtualization.framework or their own VMM, and none of those has a TPM device. You need
a hypervisor that runs QEMU: plain QEMU, or Colima or Lima with `--vm-type qemu`. The
[Virtualization.framework](../virtualization-framework.mdx) setup is the exception, with a kernel
driver of its own.

## 1. Requirements

- An Apple silicon Mac and an admin account.
- Homebrew, for QEMU and a few tools: `brew install qemu xorriso`.
- The notary, 0.0.5 or later, and swtpm-notary installed; see [Install](../../notary-backed-vtpm/install.mdx). On
  notary 0.0.5 or 0.0.6, also set `EQTY_VTPM_SWTPM`, `EQTY_VTPM_BACKING=identity` and
  `EQTY_VTPM_EPS=1` in the notary's plist, as the Colima tutorial's step 3 does.

Check them:

```sh
eqty-notaryctl --version
/opt/eqty/swtpm-notary/bin/swtpm socket --help | grep -E -- '--eps|--extkey'
```

## 2. Create a vTPM

For your own user, so that QEMU runs without root:

```sh
sudo eqty-notaryctl vtpm create --id docker1 --client-uid "$(id -u)" --client-gid "$(id -g)"
eqty-notaryctl vtpm show docker1
```

The output shows `backing=identity`, `hardwareEps=true` and the emulator
`/opt/eqty/swtpm-notary/bin/swtpm`. QEMU needs the control socket,
`/var/run/eqty-notary/vtpm/docker1.sock.ctrl`.

## 3. Prepare the VM

An Ubuntu cloud image. On first boot, cloud-init installs Docker and tpm2-tools and authorizes
your SSH key.

```sh
mkdir -p ~/vtpm-vm && cd ~/vtpm-vm
curl -LO https://cloud-images.ubuntu.com/releases/26.04/release/ubuntu-26.04-server-cloudimg-arm64.img
qemu-img create -f qcow2 -F qcow2 -b ubuntu-26.04-server-cloudimg-arm64.img disk.qcow2 20G
cp "$(brew --prefix qemu)/share/qemu/edk2-arm-vars.fd" vars.fd

[ -f ~/.ssh/id_ed25519 ] || ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519
mkdir -p seed
cat > seed/meta-data <<EOF2
instance-id: vtpm-vm
local-hostname: vtpm-vm
EOF2
cat > seed/user-data <<EOF2
#cloud-config
users:
  - name: ubuntu
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: [docker, tss]
    shell: /bin/bash
    ssh_authorized_keys: ["$(cat ~/.ssh/id_ed25519.pub)"]
packages: [docker.io, tpm2-tools]
EOF2
xorriso -as mkisofs -quiet -o seed.iso -V cidata -J -r seed
```

## 4. Boot with the vTPM

```sh
CTRL=/var/run/eqty-notary/vtpm/docker1.sock.ctrl
qemu-system-aarch64 -machine virt,accel=hvf -cpu host -m 4096 -smp 4 \
  -drive if=pflash,format=raw,readonly=on,file="$(brew --prefix qemu)/share/qemu/edk2-aarch64-code.fd" \
  -drive if=pflash,format=raw,file=vars.fd \
  -drive if=virtio,file=disk.qcow2 \
  -drive if=virtio,format=raw,readonly=on,file=seed.iso \
  -chardev socket,id=chrtpm,path="$CTRL" \
  -tpmdev emulator,id=tpm0,chardev=chrtpm \
  -device tpm-tis-device,tpmdev=tpm0,ppi=off \
  -netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=n0 \
  -display none -serial file:console.log -daemonize -pidfile qemu.pid
```

The three TPM lines are what matters: `-chardev` points at the notary's swtpm, and
`tpm-tis-device` is the TPM device for the arm64 `virt` machine. Keep `ppi=off`: QEMU 11.1 and
later abort under HVF without it, with `HV_BAD_ARGUMENT`
([qemu#4587](https://gitlab.com/qemu-project/qemu/-/issues/4587)). It turns off only the Physical
Presence Interface.

The first boot takes a minute or two while cloud-init installs packages. Then:

```sh
ssh -p 2222 ubuntu@127.0.0.1 'ls -l /dev/tpm0 /dev/tpmrm0; cloud-init status --wait'
```

## 5. Use the TPM from a container

Build a small image with tpm2-tools, then pass the TPM in with `--device /dev/tpmrm0`. Use the
resource-managed `tpmrm0`, not `tpm0`, so that several containers can share it.

```sh
ssh -p 2222 ubuntu@127.0.0.1 'printf "FROM ubuntu:26.04\nRUN apt-get update && apt-get install -y tpm2-tools openssl\n" | docker build -t tpm2 -'
ssh -p 2222 ubuntu@127.0.0.1
docker run --rm -it --device /dev/tpmrm0 -e TPM2TOOLS_TCTI=device:/dev/tpmrm0 tpm2 bash
```

Inside the container, read the IAK certificate from NV, issued by the notary, then take a quote
with the IAK, which the Secure Enclave signs, and verify it:

```sh
cd /tmp
tpm2_nvread 0x01c90100 -o iak.der
openssl x509 -inform der -in iak.der -noout -subject -issuer
# subject=O=EQTY, CN=vTPM docker1 IAK
# issuer=O=EQTY, CN=EQTY Notary SK <id>

tpm2_readpublic -c 0x81020001 -f pem -o iak.pem
tpm2_quote -c 0x81020001 -l sha256:0,7 -q c0ffee -m q.msg -s q.sig -o q.pcr -g sha256
tpm2_checkquote -u iak.pem -m q.msg -s q.sig -f q.pcr -q c0ffee -g sha256 && echo verified
```

Containers can also create and use ordinary TPM keys. A container started without `--device`
sees no TPM. In Compose, `devices: ["/dev/tpmrm0:/dev/tpmrm0"]`.

## 6. Run docker from the Mac

Drive the VM's Docker engine from macOS with the `docker` CLI and an SSH context:

```sh
cat >> ~/.ssh/config <<EOF2
Host vtpm-vm
  HostName 127.0.0.1
  Port 2222
  User ubuntu
EOF2
docker context create vtpm-vm --docker host=ssh://vtpm-vm
docker context use vtpm-vm
docker run --rm --device /dev/tpmrm0 tpm2 tpm2_getrandom 8 --hex
```

## Colima or Lima instead of plain QEMU

Colima starts VMs through Lima, and Lima runs whatever `QEMU_SYSTEM_AARCH64` names instead of
`qemu-system-aarch64`. A wrapper that appends the three TPM arguments to the VM boot, and only to
the boot, since Lima also runs QEMU for `--version` and capability probes, does the job. Lima
looks for UEFI firmware at `<wrapper dir>/../share/qemu`, so the wrapper lives in a `bin/`
directory next to a `share` link to Homebrew's.

```sh
CTRL=/var/run/eqty-notary/vtpm/colima.sock.ctrl
W=~/.local/share/colima-tpm
mkdir -p "$W/bin" && ln -sfn "$(brew --prefix)/share" "$W/share"
cat > "$W/bin/qemu-system-aarch64" <<EOF2
#!/bin/bash
Q=$(brew --prefix)/bin/qemu-system-aarch64
case " \$* " in
  *" -qmp "*) exec "\$Q" "\$@" -chardev socket,id=chrtpm,path=$CTRL \\
                -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0,ppi=off ;;
  *) exec "\$Q" "\$@" ;;
esac
EOF2
chmod +x "$W/bin/qemu-system-aarch64"

QEMU_SYSTEM_AARCH64=~/.local/share/colima-tpm/bin/qemu-system-aarch64 \
  colima start -p tpm --vm-type qemu --cpu 4 --memory 4
colima ssh -p tpm -- ls -l /dev/tpm0 /dev/tpmrm0
```

Set `QEMU_SYSTEM_AARCH64` on **every** `colima start` of this profile, or the VM boots with no
TPM. Lima on its own works the same way with `vmType: qemu`; do not also set Lima 2.2's
`tpm: true`, which starts Lima's own stock swtpm, not rooted in the notary. Rancher Desktop
bundles an older Lima and its own QEMU and is untested.

## Day to day

- **Shutting down.** When the VM powers off, QEMU tells swtpm to shut down and the vTPM stops.
  Start it before the next boot with `eqty-notaryctl vtpm start docker1`, then boot as in step 4.
  The vTPM keeps its state and its EK stays the same: the seed is re-derived in the Secure
  Enclave.
- **Restarting the notary**, or the Mac, stops the vTPM too. Start it again the same way.
- **Several VMs.** One vTPM per VM. All containers in one VM share that VM's vTPM, and with it one
  EK and one IAK. To tell workloads apart, create an AK per workload under the IAK, or give each
  workload its own VM.
- **Deleting** stops the vTPM and deletes its Secure Enclave keys. Its state cannot be recovered
  on this or any other Mac: `sudo eqty-notaryctl vtpm delete docker1`.

## Troubleshooting

| Symptom                                                              | Fix                                                                                                                |
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `vtpm create` fails and the notary log mentions `--eps`              | The notary is running stock swtpm. Install swtpm-notary and restart the notary, or set `EQTY_VTPM_SWTPM`           |
| `eqty-notaryctl` has no `vtpm` command                               | The notary is older than 0.0.5                                                                                     |
| QEMU: `Failed to connect socket ... sock.ctrl`                       | The vTPM is not running (`vtpm list`, then `vtpm start <id>`), or the socket belongs to another user (`--client-uid`) |
| QEMU aborts at start with `HV_BAD_ARGUMENT`                          | `ppi=off` is missing from `-device tpm-tis-device`                                                                 |
| No `/dev/tpm*` in the guest                                          | Check `dmesg \| grep -i tpm` in the guest and that the three TPM lines are present                                 |
| `colima start` fails immediately                                     | Look in `~/.colima/_lima/colima-tpm/ha.stderr.log`. No firmware: the `share` link next to `bin/` is missing. TPM socket: the vTPM is not running |