aev-vm 0.1.0

Manage QEMU virtual machines in Rust and open their consoles in Aen
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# Aev VM

Aev VM is a Rust VM manager with a native Aen console. It uses QEMU/KVM for
hardware virtualization while Rust owns VM definitions, process lifecycle,
QMP control, the bounded RFB client, and the native console. [KnottCompositor](https://github.com/Tknott95/KnottCompositor)

The Rust manager creates qcow2 VMs and controls QEMU through QMP. The native
Aen console displays guest RFB pixels and forwards keyboard and pointer input.
Private socket tests cover this transport; complete guest boot and physical
display acceptance remain separate release checks.

```text
KnottCompositor <- native Aen frames <- KnottVM Rust console
                                             |
                                      private Unix RFB
                                             |
                                          QEMU/KVM
                                             |
                                       private Unix QMP
                                             |
                                      KnottVM lifecycle
```

## Requirements

- Linux x86-64 with Rust 1.88 or newer
- `qemu-system-x86_64` and `qemu-img`
- `/dev/kvm` access for hardware acceleration; TCG is the automatic fallback
- OVMF/EDK2 for the default UEFI firmware
- An SMM-capable OVMF Secure Boot image for optional `uefi-secure` mode
- A running native Aen session on KnottCompositor

On Arch Linux, the headless host packages are `qemu-base` and `edk2-ovmf`.

## Install

```bash
cargo install aev-vm --locked
```

Run `aev-vm` in a terminal to create a VM or select one to open. On KnottOS,
open **Aev VM** in Applications or the App Store to launch the same menu in
Lios. The bundled `knottvm` command uses the existing VM definitions and
storage directories.

## Build from source

```bash
cargo build --release
```

The binary is `target/release/aev-vm`.

## KnottCompositor

Use the native Aen session already managed by KnottDesktop. The console resolves
`AEN_WINDOW_SOCKET`, then `KNOTT_COMPOSITOR_SHELL_SOCKET` with `.windows` appended,
then `$XDG_RUNTIME_DIR/knottx-shell.sock.windows`.

For an explicitly configured existing session:

```bash
export AEN_WINDOW_SOCKET="$XDG_RUNTIME_DIR/knottx-shell.sock.windows"
aev-vm doctor
```

`doctor` verifies a native configure handshake without uploading a visible
frame; it does not certify scanout or guest boot. No compositor restart or
hardware display takeover is needed to open a console. See
[the native Aen guide](docs/native-aen.md) for frame limits and input behavior.
The opt-in `scripts/e2e-headless.sh` test uses a private native-only software
compositor and QEMU.

## First VM

```bash
aev-vm doctor
aev-vm init workstation \
  --iso "$HOME/Downloads/installer.iso" \
  --disk-size 128G \
  --memory 8192 \
  --cpus 8 \
  --firmware uefi
aev-vm run workstation
```

`run` starts a stopped VM and opens its console. Closing the console leaves the
VM running. Reopen it with `aev-vm console workstation`.
Add `--tpm2` to `aev-vm init` when the guest needs a software TPM 2.0.

```bash
aev-vm status workstation
aev-vm pause workstation
aev-vm resume workstation
aev-vm reset workstation
aev-vm balloon workstation show
aev-vm stop workstation
aev-vm kill workstation
```

`stop` first requests an ACPI shutdown and escalates to QMP `quit` after the
configured timeout. `kill` means immediate QMP `quit`; it does not send a Unix
signal to an unverified PID.

## Screenshots

Capture a running VM's current QEMU framebuffer without opening a console:

```bash
aev-vm screenshot workstation workstation.ppm
```

Screenshots are binary PPM files. QEMU writes to a fixed file inside the VM's
private runtime directory; KnottVM validates the format and 256 MiB size limit
before publishing the requested destination with owner-only permissions.
Existing files and symlinks are never replaced.

## Runtime Memory

Every VM includes a virtio memory balloon. A running VM can cooperatively return
memory to the host without changing its next-boot configuration:

```bash
aev-vm balloon workstation show
aev-vm balloon workstation set 4096
aev-vm balloon workstation restore
```

Targets are limited to 256 MiB through the VM's configured boot memory.
`restore` requests that configured maximum again. Balloon changes are
asynchronous and require a functioning guest virtio-balloon driver; `show`
reports QEMU's current guest-reported byte count. Targets are runtime-only and
reset when QEMU restarts.

## Guest Agent

Every VM includes a private virtio-serial channel named
`org.qemu.guest_agent.0`. Install and enable `qemu-guest-agent` inside the
guest to use OS-aware controls:

```bash
aev-vm agent workstation ping
aev-vm agent workstation info
aev-vm agent workstation shutdown
aev-vm agent workstation shutdown reboot
```

The channel is proxied through an owner-only Unix socket. `agent shutdown`
asks the guest operating system to perform the action; `stop` remains the
QMP/ACPI lifecycle fallback when an agent is unavailable.

## Snapshots

Internal snapshots are intentionally offline so disk mutation cannot race a
running guest:

```bash
aev-vm stop workstation
aev-vm snapshot workstation create clean-install
aev-vm snapshot workstation list
aev-vm snapshot workstation revert clean-install
aev-vm snapshot workstation delete clean-install
```

Snapshots cover only the qcow2 system disk; they do not include UEFI variable or
software TPM state. To prevent a disk rollback from being paired with newer TPM
state, KnottVM rejects snapshot creation and reversion for VMs with software
TPM 2 enabled. Existing snapshots can still be listed or deleted. Portable
backups include the stopped VM's software TPM state.

## Cloning

Cloning is offline and creates an independent full qcow2 copy rather than a
fragile backing-file chain:

```bash
aev-vm stop workstation
aev-vm clone workstation workstation-lab
aev-vm run workstation-lab
```

The clone receives its own disk, UEFI variable file, runtime sockets, and
deterministic MAC identity. Installation-media configuration is retained, while
host port forwards are cleared to prevent listener conflicts.

## Backup And Restore

Portable backups are offline, independent, and self-verifying:

```bash
aev-vm stop workstation
aev-vm backup create workstation /mnt/backups/workstation-2026-07-10
aev-vm backup verify /mnt/backups/workstation-2026-07-10
aev-vm backup restore /mnt/backups/workstation-2026-07-10 workstation-restored
```

A backup directory contains an independent qcow2 image, portable TOML
definition, optional UEFI variables, and a versioned JSON manifest with SHA-256
and exact-size checks for every artifact. Verification also runs `qemu-img
check`. Restore verifies first, publishes the new definition last, assigns a new
MAC identity, clears host port forwards, and does not retain installation-media
paths.

## Deletion

Deletion requires an explicit confirmation and a stopped VM:

```bash
aev-vm delete workstation-restored --yes
```

KnottVM removes only its definition, managed `system.qcow2`, UEFI variables,
and runtime metadata. A manually configured disk outside the VM's managed data
directory is reported and preserved. Unknown files in the data directory are
also left untouched. Before creation, launch, or disk mutation, ownership checks
compare canonical paths and file identities across definitions and pending
deletions. They also detect another VM's reference to a managed path before its
disk file exists; unreadable or unresolved peer references fail closed. A
private cross-process lock serializes ownership scans, and deletion holds it
until the disk and its tombstone are cleared.

## Configuration

VM definitions use strict, versioned TOML under
`$XDG_CONFIG_HOME/knottvm/vms`. Disks and UEFI variables live under
`$XDG_DATA_HOME/knottvm/vms`. Owner-only sockets, PID metadata, and operation
locks live under `$XDG_RUNTIME_DIR/knottvm`.

Example definition:

```toml
schema_version = 1
name = "workstation"
generation_id = "7d845e9b-b00f-4d7c-b845-e0bffb33d063"
memory_mib = 8192
vcpus = 8
acceleration = "auto"
firmware = "uefi"
audio = "none"
install_media = "/home/user/Downloads/installer.iso"

[disk]
path = "/home/user/.local/share/knottvm/vms/workstation/system.qcow2"
format = "qcow2"

[network]
mode = "user"

[[network.forwards]]
protocol = "tcp"
host_address = "127.0.0.1"
host_port = 2222
guest_port = 22
```

Remove `install_media` after installation if the ISO should no longer be
attached, or manage it without editing TOML:

```bash
aev-vm media workstation show
aev-vm media workstation attach ~/Downloads/tools.iso
aev-vm media workstation detach
```

Media changes require the VM to be stopped. `aev-vm command NAME` prints the
exact argument-safe QEMU launch for inspection.

## USB Passthrough

An exact Linux USB bus and device address can be cold-plugged into a stopped
VM. Use `lsusb` to identify the current numbers:

```bash
aev-vm stop workstation
aev-vm usb workstation add --bus 1 --address 4
aev-vm usb workstation list
aev-vm run workstation
```

The guest receives the entire physical device through QEMU's `usb-host`
backend. The invoking user must already have permission to open its
`/dev/bus/usb` node; KnottVM never elevates privileges or changes device
permissions. Do not run KnottVM as root or pass through host hubs, keyboards,
or other devices needed to control the host.

USB addresses can change after reconnect. Stop the VM and update the binding
before restarting it:

```bash
aev-vm usb workstation remove --bus 1 --address 4
```

Host USB bindings are intentionally cleared from clones and portable backups.
An absent, inaccessible, busy, or unsupported device makes VM startup fail
rather than silently booting without it. Up to 14 host devices can be assigned
to one VM.

## Host Directory Shares

KnottVM can expose an existing host directory through QEMU's built-in
virtio-9p transport without an external helper. Shares default to read-only and
are changed while the VM is stopped:

```bash
aev-vm share workstation add host-data "$HOME/VM-Share"
aev-vm share workstation list
aev-vm run workstation
```

On a Linux guest with 9p support, mount the tag with:

```bash
mount -t 9p -o trans=virtio,version=9p2000.L host-data /mnt/host-data
```

Guest writes require explicit opt-in:

```bash
aev-vm stop workstation
aev-vm share workstation remove host-data
aev-vm share workstation add host-data "$HOME/VM-Share" --writable
```

Writable shares let guest software modify or delete files as the host user
running QEMU. KnottVM uses `mapped-xattr`, never changes host permissions, and
does not treat 9p as an isolation boundary. Share paths are host-local and are
therefore cleared from clones and portable backups. Up to 16 shares can be
configured per VM.

## Storage Growth

System disks can only grow, never shrink, and the VM must be stopped:

```bash
aev-vm disk workstation info
aev-vm disk workstation grow 40G
```

After growing the virtual disk, expand the partition and filesystem inside the
guest using its operating-system tools.

## Port Forwarding

User-mode networking can expose guest services on IPv4 loopback without root
or a bridge:

```bash
aev-vm stop workstation
aev-vm port workstation add --host-port 2222 --guest-port 22
aev-vm port workstation list
aev-vm run workstation
ssh -p 2222 localhost
```

Remove it while the VM is stopped:

```bash
aev-vm port workstation remove --host-port 2222
```

TCP and UDP are supported. Listener addresses are restricted to loopback by
configuration validation so a typo cannot expose a guest service publicly.

## Compute And Audio

Compute, accelerator, network, and audio settings are changed atomically while
the VM is stopped:

```bash
aev-vm configure workstation \
  --memory 16384 \
  --cpus 8 \
  --acceleration auto \
  --network user \
  --audio pipewire
```

Audio is disabled by default. `--audio pipewire` creates an Intel HDA duplex
device connected directly to the user's PipeWire session; this is a QEMU/host
integration and does not require compositor-specific audio APIs.

## Machine Identity

Each new VM receives a stable UUID exposed through QEMU's `vmgenid` device.
KnottVM automatically generates a different identity for clones and restores,
and changes it after snapshot rollback so modern guests can detect duplicated
or rolled-back machine state.

```bash
aev-vm identity workstation show
aev-vm stop workstation
aev-vm identity workstation regenerate
```

## Firmware And Secure Boot

New VMs use standard UEFI by default. Hosts with an SMM-capable OVMF Secure
Boot image can select the secure firmware profile at creation or while the VM
is stopped:

```bash
aev-vm doctor
aev-vm init workstation-secure --firmware uefi-secure
aev-vm configure workstation --firmware uefi-secure
```

The secure profile uses Q35 with SMM enabled, read-only secure OVMF code, a
protected writable pflash device, and per-VM variable storage. `doctor` reports
the matched `uefi-secure-code` and `uefi-secure-vars` paths. `bios`, `uefi`,
and `uefi-secure` are the supported modes.

Selecting `uefi-secure` provides firmware capable of enforcing Secure Boot; it
does not enroll keys. Enrollment and verification policy remain guest/firmware
operations. The per-VM UEFI variables containing enrollment state are retained
by clones and included in verified backups.

## Design Choices

- QEMU/KVM is the hypervisor instead of an incomplete new device model.
- All control and display channels are Unix sockets inside mode-0700 runtime
  directories. RFB security type `None` is accepted only on that local socket.
- The console uses the native Aen window SDK with bounded opaque BGRA frames,
  configure revisions and explicit frame acknowledgement credit.
- Native GPU import and explicit synchronization remain prerequisites for an
  accelerated console presenter.
- Guest-controlled dimensions, names, clipboard messages, rectangles, and
  framebuffer allocations are bounded before allocation or copying.

See `docs/ARCHITECTURE.md` for component and failure-boundary details.
See `COMPOSITOR_NEEDED.md` for requirements that must be implemented in
KnottCompositor rather than worked around in the VM manager.

## Current Limits

- One x86-64 system disk and one optional installation ISO
- CPU frame scaling and native socket uploads; GPU presentation is pending
- Native compositor-resolved keysyms, with a basic evdev fallback; primary
  touch maps to guest pointer input, while IME text commits and multitouch remain
  pending
- Absolute tablet input remains the default; `aev-vm configure NAME
  --pointer-device mouse` opts into relative QEMU input and Aen capture. Escape
  releases capture, and a deliberate click requests it again.
- USB passthrough is cold-plug only and uses reconnect-sensitive Linux bus and
  address selectors; no USB hotplug or stable physical-port matching yet
- Host directory sharing uses virtio-9p and primarily targets Linux guests;
  `virtiofsd` is not installed on the current validation host
- Framebuffer screenshots are bounded binary PPM files; image conversion is
  intentionally left to external user tools
- No bridged networking, live migration, host-side Secure Boot enrollment UI,
  or atomic focus-generation fence from host clipboard read through final guest
  delivery. Host-to-guest paste is disabled by default; the unsafe
  `--unsafe-unfenced-host-clipboard-paste` option explicitly opts in despite
  that delivery race. Guest-to-host copy is an explicit shortcut scoped to the
  focused Aen window.
- `aev-vm init --tpm2` enables a persistent per-VM TPM 2.0. It requires the
  external `swtpm` and `swtpm_ioctl` helpers; KnottVM does not install them.
  Backups retain TPM state, while clones start with a fresh TPM identity.
- KnottCompositor itself still needs broader toolkit compatibility, production
  input semantics, GPU composition, and session mediation

This is a tested foundation, not a claim of feature parity with mature desktop
products. The process boundaries allow those features to be added without
replacing VM definitions, QMP control, or the compositor-native console.

## Development

```bash
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings
cargo test --all-targets
bash scripts/e2e-headless.sh
```

The end-to-end test requires the sibling KnottCompositor debug binary. It boots
real temporary QEMU VMs, validates QMP, screenshots, secure UEFI, balloon
control, storage, host shares, network, USB configuration, snapshots, clone,
backup/restore, and deletion, opens the RFB/native Aen console for three seconds,
and cleans all temporary state.

## Local verification — 2026-11-08

Offline all-target tests passed 154 library, 1 main, and 6 console-socket
cases. Strict Clippy and formatting pass. The headless end-to-end script now
creates private mode-0700 XDG directories before its doctor check and passes
against KnottCompositor's headless backend. QEMU used TCG because `/dev/kvm`
is not accessible here. The run exercises VM lifecycle/QMP, screenshots,
storage, shares, snapshots, clone/backup/restore, and the native Aen console;
it does not qualify KVM acceleration, complete guest OS boot, or physical
display. Its temporary `/tmp` state is cleaned on exit.

Licensed under either Apache-2.0 or MIT.