[TUTORIAL] Proxmox LXC to VM Converter

ArMaTeC

New Member
Feb 12, 2026
2
2
3
A robust Bash toolkit that converts Proxmox LXC containers into fully bootable QEMU/KVM virtual machines — directly on your Proxmox VE host. Includes a companion disk-shrink script and handles disk creation, filesystem copy, kernel/GRUB installation, networking reconfiguration, and VM provisioning automatically.

Table of Contents


Scripts

This project includes two scripts:

ScriptPurpose
lxc-to-vm.shConverts an LXC container into a bootable VM. Main script.
shrink-lxc.shShrinks an LXC container's disk to used space + headroom. Standalone or use --shrink in lxc-to-vm.sh.


Features

Conversion (lxc-to-vm.sh)

  • One-command conversion — turn any LXC into a bootable VM
  • Multi-distro support — Debian, Ubuntu, Alpine, CentOS/RHEL/Rocky, Arch Linux (auto-detected)
  • BIOS & UEFI boot — MBR/SeaBIOS (default) or GPT/OVMF with --bios ovmf
  • Integrated disk shrink--shrink shrinks the LXC disk before conversion, auto-sets disk size
  • Dry-run mode — preview every step without making changes (--dry-run)
  • Network preservation — keep original network config with --keep-network, or replace with DHCP on ens18
  • Auto-start & health checks — boot the VM and verify guest agent, IP, and reachability (--start)
  • Post-conversion validation — automatic 6-point check (disk, boot order, network, agent, EFI)
  • Interactive & non-interactive modes — use CLI flags for scripting or answer prompts manually
  • Auto-dependency installation — missing tools (parted, kpartx, rsync, etc.) installed automatically
  • Input & storage validation — catches invalid IDs, missing storage, format errors before work begins
  • Smart disk space management — checks available space, auto-selects mount points with room, explains LVM vs filesystem constraints
  • Custom working directory--temp-dir to place the temporary disk image on any mount point
  • LXC config inheritance — memory, CPU cores pulled from the source container config
  • Serial console support — enables ttyS0 serial console for Proxmox terminal access
  • Colored output — color-coded progress messages (auto-disabled when piped)
  • Full logging — all operations logged to /var/log/lxc-to-vm.log
  • Safe cleanup — trap-based cleanup removes temp files and loop devices on exit or error
  • Wizard mode — interactive TUI with progress bars and guided setup (--wizard)
  • Parallel batch processing — run N conversions concurrently (--parallel N)
  • Pre-flight validation — comprehensive checks without converting (--validate-only)
  • Cloud/remote export — export VM disks to S3, NFS, or SSH destinations (--export-to)
  • VM template creation — convert to Proxmox template with optional sysprep (--as-template)
  • Auto-rollback — automatically restore container if conversion fails (--rollback-on-failure)
  • Configuration profiles — save and reuse common conversion settings (--save-profile, --profile)
  • Resume capability — resume interrupted conversions from partial state (--resume)
  • Auto-cleanup — destroy original LXC after successful conversion (--destroy-source)

Disk Shrinker (shrink-lxc.sh)

  • Shrinks LXC disks to actual usage + configurable headroom
  • Smart minimum detection — queries resize2fs -P for the true filesystem minimum size
  • Auto-retry — if resize2fs fails, automatically increments by 2GB and retries (up to 5 attempts)
  • Multi-backend — supports LVM-thin, LVM, directory (raw/qcow2), and ZFS storage
  • Dry-run mode — preview the shrink plan without making changes
  • Safety confirmation — prompts before destructive operations
  • Prints ready-to-use conversion command after shrinking

Supported Distros


Distro FamilyDetected IDsPackage ManagerNotes
Debian/Ubuntudebian, ubuntu, linuxmint, pop, kaliaptPrimary target, most tested
AlpinealpineapkOpenRC init system configured automatically
RHEL/CentOScentos, rhel, rocky, alma, fedorayum/dnfKernel + GRUB2
Arch Linuxarch, manjaro, endeavourospacmanKernel + GRUB
Distro is auto-detected from /etc/os-release inside the container. The script uses the appropriate package manager and bootloader installation commands for each family.

Requirements


RequirementDetails
Proxmox VEVersion 7.x, 8.x or 9.x
Source LXCDebian, Ubuntu, Alpine, CentOS/RHEL/Rocky, or Arch based container
Root accessScripts must run as root on the Proxmox host
Free disk spaceFilesystem space ≥ disk image size (LVM/ZFS storage cannot be used as temp space — see Disk Space Management)
NetworkInternet access (to install kernel/GRUB packages inside chroot)

Dependencies (auto-installed by lxc-to-vm.sh)

  • parted — disk partitioning
  • kpartx — partition mapping for loop devices
  • rsync — filesystem copy
  • e2fsprogs — ext4 formatting and filesystem tools (mkfs.ext4, resize2fs, e2fsck)
  • dosfstools — FAT32 formatting for UEFI ESP (only when using --bios ovmf)

For more details see https://github.com/ArMaTeC/lxc-to-vm

 
Last edited:
"Bug Fix Edition" — Critical boot and cleanup fixes

Fixed FEATURE_C12 Boot Error — Properly disable metadata_csum and related ext4 features to prevent initramfs boot failures
Fixed Cleanup Trap — Properly unmount virtual filesystems (dev/pts, dev, proc, sys) before temp directory removal
Added Metadata Checksum Verification — Verify metadata_csum is actually disabled before proceeding with conversion
Improved tune2fs Error Handling — Fail conversion if ext4 feature disabling fails (no silent failures)

https://github.com/ArMaTeC/lxc-to-vm/releases/tag/v6.0.2

Full Changelog: 6.0.0...v6.0.2
 
I wanted to migrate my OpenClaw LXC to a VM and asked Perplexity for advice. The first method that came up was your script. It took only a few minutes, and the VM was ready and running without any issues. Well done!
 
  • Like
Reactions: ArMaTeC