exporting LXC from Proxmox to non-Proxmox LXD host

Jul 25, 2018
3
0
21
41
Hello,

I am just starting with the platform and liking it very much.

I am trying to move a Proxmox LXC container to a non-Proxmox host. I tried two methods, but neither worked:

1. I stopped the container and took a full backup and used gzip to compress it. Then I copied the resulting vzdump*.tar.gz file into the other server and attempted to issue "lxc image import <vzdump file path>". I got this:
Code:
Error: Could not extract image metadata.yaml from tar: Failed to run: tar -O -zxf /var/lib/lxd/images/lxd_build_646308358/lxd_post_154669997 metadata.yaml: tar: metadata.yaml: Not found in archive
tar: Exiting with failure status due to previous errors (tar: metadata.yaml: Not found in archive)

2. I stopped the container and in the web UI I right-clicked and used "Convert to template" from the context menu. But then I could not find where this template was created in the filesystem. It was not in /var/lib/vz/template/cache.

I did multiple google searches but did not come up with anything. Bulk of the material talks about backup and restoring on the same Proxmox node or between multiple Proxmox node. But nothing about portability between Proxmox and non-Proxmox LXD host.

Thanks,
Adam
 
See here[1] (The 'split image' section) for how lxd images work. You can use the vzdump tarball as a filesystem-only tarball and have to create a metadata file in an extra tarball. From what I can tell it should be enough to provide the architecture and creation_date entries (the creation date just needs to be not zero;-) ) for lxc to import the image. The link should tell you more about additional properties you might want to add to the metadata.yaml file, but that seems mostly optional.

[1] https://stgraber.org/2016/03/30/lxd-2-0-image-management-512
 
Hi to all,

I have managed to "export" a Container from Proxmox and import it in a bare naked LXD installation. I give you some context: I want to use Proxmox Containers to deploy application written in my company. Then we will distribute those images, publishing the application on client's server, using a basic LXD/LXC installation.

Conventions used in this message:
I will call the proxmox server: "[PVE]", and the other server, the one with the bare LXD: "[CLN]". I will write the subject of commands in the squared parenthesis written after the procedure step number. I also will indicate the bash shell of the machine with "$".

the procedure that I have used is this:
  1. [PVE] Create a CT in Proxmox and use it;
  2. [PVE] Converte the CT in a Template;
  3. [PVE] Take a backup, so i have in my filesystem a file named: vzdump-lxc-<CTID>-timestamp.tar.gz
  4. [PVE] From CLI, using pct config <CTID> i read the architecture of the container;
  5. [PVE] With this information I can create a metadata.yaml so i open a text editor and write down only the mandatory field (I had found this information here: https://linuxcontainers.org/lxd/docs/master/image-handling).
    In my case the metadata.yaml is:
    Code:
    architecture: x86_64
    creation_date: 1424284563
    I know the architecture from pct config <CTID>. Creation_date is a random timestamp.
  6. [PVE] Now i will compress the yaml file with tar -czvf metadata.tar.gz metadata.yaml.
  7. [PVE/CLN] Now that I have this two files I copy both on the other server with LXD installed, for your information, the server for the migration.
  8. [CLN] now I can import the machine using lxc image import <metadata.tar.gz> <rootfs.tar.gz>
    In my case i got:
    Code:
    $ lxc image import metadata.tar.gz vzdump-lxc-105-2020_11_11-17_31_29.tar.gz
    Transferring image: 100% (171.27MB/s)
    Image imported with fingerprint: 65a7914d9cafa321cad8df1ec56d302c4e61100a9e1b90d4fe686b0076143b48
  9. [CLN] Finally I can use lxc launch <fingerprint>
    in my case:
    Code:
    $ lxc launch 65a7914d9cafa321cad8df1ec56d302c4e61100a9e1b90d4fe686b0076143b48
    Creating the instance
    Retrieving image: Unpack: 100% (12.92MB/s)
    Instance name is: rare-alpaca
    Starting rare-alpaca
  10. [CLN] Now the LXC containre is started. I can see it with:
    Code:
    $ lxc list
    +-------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
    | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
    +-------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
    | rare-alpaca | RUNNING | 192.168.1.25 (eth0) | fd42:c91a:13a5:989a:216:3eff:fefd:87a7 (eth0) | CONTAINER | 0 |
    +-------------+---------+----------------------+-----------------------------------------------+-----------+-----------+

Note for the point number 5:
I know that during exporting LXD put metadata.yaml and rootfs inside a single tar.gz, but if I try to append the metadata.yaml file in the vzdump-lxc-<CTID>-timestamp.tar.gz archive manually I got this error:
Code:
$ tar -rf vzdump-lxc-105-2020_11_11-17_31_29.tar.gz metadata.yaml
tar: Cannot update compressed archives
tar: Error is not recoverable: exiting now
it would be very convenient to have these files together in one archive, but I can't figure out how to do that.

Sorry for my english, but I am not a native speaker so my vocabulary is limited and I also do a lot of grammar mistake.

Feedbacks are welcome.

Best regards.
 
Last edited:
Thanks for this Slntswrd, worked a treat to move my Proxmox LXC containers to QNAP LXD containers. Cheers!

 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!