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.
Conversion (
Disk Shrinker (
Distro is auto-detected from
Dependencies (auto-installed by
Table of Contents
Scripts
This project includes two scripts:| Script | Purpose |
|---|---|
lxc-to-vm.sh | Converts an LXC container into a bootable VM. Main script. |
shrink-lxc.sh | Shrinks 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 —
--shrinkshrinks 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 onens18 - 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-dirto 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
ttyS0serial 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 -Pfor 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 Family | Detected IDs | Package Manager | Notes |
|---|---|---|---|
| Debian/Ubuntu | debian, ubuntu, linuxmint, pop, kali | apt | Primary target, most tested |
| Alpine | alpine | apk | OpenRC init system configured automatically |
| RHEL/CentOS | centos, rhel, rocky, alma, fedora | yum/dnf | Kernel + GRUB2 |
| Arch Linux | arch, manjaro, endeavouros | pacman | Kernel + GRUB |
/etc/os-release inside the container. The script uses the appropriate package manager and bootloader installation commands for each family.Requirements
| Requirement | Details |
|---|---|
| Proxmox VE | Version 7.x, 8.x or 9.x |
| Source LXC | Debian, Ubuntu, Alpine, CentOS/RHEL/Rocky, or Arch based container |
| Root access | Scripts must run as root on the Proxmox host |
| Free disk space | Filesystem space ≥ disk image size (LVM/ZFS storage cannot be used as temp space — see Disk Space Management) |
| Network | Internet access (to install kernel/GRUB packages inside chroot) |
Dependencies (auto-installed by lxc-to-vm.sh)
parted— disk partitioningkpartx— partition mapping for loop devicesrsync— filesystem copye2fsprogs— 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: