Overview
Thesmolvm cleanup command removes VMs and their associated resources (TAP devices, network rules, state entries) from your system. By default, it targets stale VMs and auto-created VMs with the vm- prefix.
Basic Usage
- Stale VMs (VMs with state entries but no running processes)
- Auto-created VMs (those with the default
vm-prefix)
Command Syntax
Options
Delete all VMs, not just stale or auto-created ones. Use with caution.
VM ID prefix to target for cleanup. Only VMs starting with this prefix (or marked as stale) will be deleted.
Print which VMs would be deleted without actually deleting them. Useful for previewing cleanup.
Examples
Preview Cleanup Targets
Before deleting anything, see what would be removed:Clean Auto-Created VMs
Remove all VMs with the defaultvm- prefix:
Clean VMs with Custom Prefix
Target VMs with a specific naming pattern:Delete All VMs
Remove every VM known to SmolVM:The
--all flag ignores the --prefix option and removes every VM regardless of naming.Combine Dry Run with All
Preview what--all would delete:
What Gets Cleaned
When a VM is deleted,smolvm cleanup removes:
- VM Process: Stops the running Firecracker/QEMU process
- TAP Device: Deletes the network TAP interface
- Network Rules: Removes associated nftables rules and chains
- State Entry: Deletes the VM record from
~/.local/state/smolvm/smolvm.db - Resources: Cleans up any temporary files or sockets
Reconciliation
Before performing cleanup, the command runs reconciliation to identify stale VMs:- VMs that have state entries but no running process
- VMs with leftover resources (TAP devices, network rules) but no active VM
Exit Codes
- 0: Success - all targets cleaned successfully (or no targets found)
- 1: Partial failure - one or more VMs failed to delete
Failure Handling
If some VMs fail to delete, cleanup continues for remaining targets:1
Permissions
Cleaning network resources (TAP devices, nftables rules) requires elevated privileges. If you run cleanup without sudo, you may see warnings:Common Patterns
Clean Before Testing
Ensure a clean slate before running integration tests:Clean Specific Environments
Use prefixes to organize and clean VMs by environment:Scheduled Cleanup
Run periodic cleanup via cron to reclaim resources:Safety Features
Dry Run Default
Always preview before deleting:Prefix-Based Targeting
By default, only VMs with thevm- prefix are targeted. VMs with custom IDs are protected:
--prefix or --all:
No Matching VMs
If no VMs match the cleanup criteria:0 (success)
Integration with Scripts
Use cleanup in automation scripts:Troubleshooting
Cleanup Hangs
If cleanup appears to hang, a VM process may be unresponsive:TAP Devices Persist
If TAP devices remain after cleanup:State Database Corruption
If the state database is corrupted:See Also
- CLI Overview - General CLI usage
- Doctor Command - Validate your environment
- SmolVM API - VM lifecycle management