Can I restore a Vzdump tar archive to an LXD/LXC container

Solution 1:

So after 2 weeks of research and reading many, many blog posts, I finally figured out how to do it.

It's not particularly staright forward, but it's not rocket science either, I do however get the feeling (and the hostility) from asking in the proxmox forums that they would rather you didn't move away from the proxmox platform, temporary or otherwise.

Anyway, the steps you need to follow are essentially

  1. at the proxmox command line, "pct list" to get the ID of the container you want to copy.

  2. at the same command line "vzdump -compress gzip -dumpdir /tmp" , you don't need the dump dir parameter, but the default is nested a stupid amount of folders deep, so I'd advise to use the tmp dir for easiness.

  3. you then need to create a "meta data file" using the following commands (Please NOTE: the # symbols need to be changed to BACKTICKS before you copy and paste/use the command, I've had to use the # symbol as markdown in a SO post cannot display the backtick symbol due to the way markdown uses it) :

    echo architecture: #pct config $1 | grep arch: | awk '{print $2}'# > metadata.yaml

    echo creation_date: #date +%s# >> metadata.yaml

    tar -czvf metadata.tar.gz metadata.yaml

    rm metadata.yaml
  1. Move the ".tar.gz" files that you created, across to the target machine running a modern version of LXD, I used rsync for this.

  2. ON the command line of your LXD machine, use the following command to import the metadata and dump file into an lxc image:

    sudo lxc image import metadata.tar.gz <vzdump name>.tar.gz

This will import the container as an image, which is not directly runnable, type

lxc image list

and get the fingerprint of the image you just created

LXC image list

  1. still at the LXD command line, using the fingerprint from your image use:

    lxc launch <fingerprint> <name you want to give your container>

At this point, you'll have a new container, that is an exact duplicate of your original proxmox one running.

What you may not have are the same network settings however. For me, I have everything on my network running off of DHCP, including the static leases, so it was important that my new containers had the same MAC address, that was easily done by using

pct config <container id>

on the proxmox cli to display the hardware configuration, then copy and pasting the MAC address from that, followed by

lxc stop <container name>
lxc config set <container name> volatile.eth0.hwaddr <copied mac address>
lxc start <container name>

If your DHCP static leases are driven from the mac address, then this will ensure that they get the same IP address, as long as your LXD host is set up to bridge IP's on the same network as your original proxmox host.

I've written a blog post which can be found at : https://shawtyds.wordpress.com/2021/11/16/converting-containers-from-proxmox-ve-back-to-plain-old-lxd-lxc/ that goes into a little more detail.

Once your copied container is running, then it's just a matter of using lxc to delete the temporary image (unless you want to keep it) and to erase the ".tar.gz" files from both servers, and possibly removing the old container from proxmox if you no longer need it.