Converting Proxmox VMs to Containers Easily!
If you've got a Proxmox Server, you'll know how awesome it is to run everything as (LXC) Containers, they're light & resource-efficient, easier to manage and can be templated. But often, you start off with a VM, set it up the way you want and have no way of easily converting. Now you can, quite easily!
Introducing proxmox-vm-to-ct
With Proxmox VM to CT you can easily convert your existing VMs to a Container by passing in some basic options. Plus it has some extra lean DietPi optimisations for an even more resource efficient DietPi container!
As it’s a self-contained bash script, you can grab it easily from the github repo:
We just finished migrating just over 200 VMs to containers and templating a few for future musings.
For instance, suppose you have a VM called the-matrix
that you want to convert to a container named matrix-reloaded
and your Proxmox storage is called local-zfs
, you can simply call the script like so:
You can even convert VM’s that you’ve installed Docker, Podman or containerd installations, you can use the --default-config-containerd
switch:
If you want to keep the source output from the script for future containers, use the --source-output
switch:
Then you can reuse that same template to create more containers:
The --source
switch supports two different types of inputs:
- SSH: IP or Hostname (Eg.
192.168.0.101
orthematrix.fritz.box
) - Archive: GZip root file system (Eg.
*.tar.gz
)
Which renders out something similar to this - on our test rig named gandalf
:
Securely set passwords
By default, the script will auto-generate a password for you and set it on the container, but you can opt to have it prompt you for a password with the --prompt-password
switch.
It will whip open a whiptail
window asking you for a password!
Default Configurations
The default configuration for the script is quite basic, but you can opt to create your own machine/cluster specific configurations inside a (sort of an) env file.
Following the example default.config, create a file with only the settings you want to change from the default:
Then load the configuration overiding the default options:
DietPi optimisations
If your VM is based on DietPi (6.x to 9.x), you can have the script optimise it for Containers by default which is documented here.
- Sets the
.dietpi_hw_model_identifier
from 21 (x86_64) to 75 (container) as per documentation - Sets up first-login install sequence (even if you’ve done it already) so each container gets updates and updating of passwords instead of any randomly generated ones from the script by modifying
/boot/dietpi/.installstage
. - Stops DietPi-CloudShell which is CloudHell when you reboot as a container in Proxmox otherwise.
- Adds the purging of
grub-pc tiny-initramfs linux-image-amd64
packages which aren’t required as a container - see Michalng’s comment.
They can be disabled with --ignore-dietpi
and won’t be done on non-dietpi VMs (like Debian etc).
Acknowledgements
This script uses the handiwork by @my5t3ry/machine-to-proxmox-lxc-ct-converter and in particular the change by blauskaerm that tar’s up the filesystem.