Skip to content

fix(proxmox): stop leaking unused disks on reinstall#140

Merged
v0l merged 1 commit into
masterfrom
fix/reinstall-unused-disks
Jun 23, 2026
Merged

fix(proxmox): stop leaking unused disks on reinstall#140
v0l merged 1 commit into
masterfrom
fix/reinstall-unused-disks

Conversation

@v0l

@v0l v0l commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #94

During VM reinstall on Proxmox hosts, a lot of unused[n] disks were being left attached to VMs (observed 62 on VM 1100).

Root cause

The reinstall pipeline imports the template disk into scsi0 via qm set --scsi0 <storage>:0,import-from=.... When scsi0 is still populated, Proxmox moves the existing disk to an unused[n] config entry instead of deleting it. Because the pipeline has a retry policy, a transient failure re-runs the import step and orphans the previous disk each time — so they accumulate indefinitely.

Fix

  • import_disk now force-removes scsi0 + any unused[n] before importing, making the import idempotent across retries (covers both the create and reinstall pipelines).
  • unlink_primary_disk sweeps unused[n] alongside scsi0.
  • New delete_unused_disks trait method (default no-op; Proxmox removes only unused[n], never the live scsi0) is run for every live VM in the periodic patch_host flow, so already-accumulated orphans across all VMs/hosts get cleaned up automatically over time.
  • Added get_vm_config_raw to read dynamic unused[n] keys (the typed VmConfig drops them).

Tests

  • test_cleanup_vm_disks_removes_unused — asserts only unused[n] (not scsi0) are force-unlinked.
  • test_cleanup_vm_disks_noop_when_nothing_to_remove — no unlink request when nothing to clean.
  • All proxmox unit tests pass; clippy/fmt clean.

Manual remediation

For already-affected VMs, remove the orphans on the host:

ids=$(qm config <vmid> | awk -F: '/^unused[0-9]+:/{print $1}' | paste -sd,)
qm unlink <vmid> --idlist "$ids" --force

No API surface change.

Repeated/retried reinstalls imported into an already-populated scsi0
slot, causing Proxmox to move the previous disk to an unused[n] config
entry instead of deleting it. With the reinstall pipeline's retry policy
these accumulated indefinitely (observed 62 unused disks on one VM).

- import_disk now force-removes scsi0 + any unused[n] before importing,
  making import idempotent across retries (covers create + reinstall)
- unlink_primary_disk sweeps unused[n] alongside scsi0
- new delete_unused_disks trait method (Proxmox removes only unused[n],
  never the live scsi0) is run for every live VM in the periodic
  patch_host flow to clean up already-accumulated orphans

Adds get_vm_config_raw to read dynamic unused[n] keys and regression
tests for the cleanup logic.
@v0l v0l merged commit ae6cb06 into master Jun 23, 2026
7 checks passed
@v0l v0l deleted the fix/reinstall-unused-disks branch June 23, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reinstall image leave unattached disks on proxmox

1 participant