Migrating containers from legacy LXC 1.x to current LXD 3.x

(Dragan Espenschied) #1

I am running a legacy LXC version 1.0.7 host with a dozen containers.

My current project requires to transfer these containers to a new host running LXD 3.

Since LXD 2, transferring of containers in between hosts is super easy, and I have done it several times. But I do not know how to package the LXC 1.x containers in a way that makes them accessible for LXD 3. There seems to be no export type of command available, and the container structure looks versy different in the file system.

Any advice would be much appreciated!

Migrating legacy overlayfs containers to ZFS-based storage
(Stéphane Graber) #2

If that’s an option, you could update the source to LXC 2.0 or 3.0, then use lxc-to-lxd to import the containers.

Though I suspect in this case, a manual approach may be simpler.

What you’d do for that is create very small new containers on LXD, possibly using a small image like Alpine, then with the container running (set it privileged with security.privileged=true), rsync the content of your old container over the new one, then reboot it and make sure everything works.

So that’s effectively rsync of the container’s rootfs and then tweaking any configuration that needs tweaking, just make sure your destination container is privileged if your source one was (pretty likely), you can always try making the container unprivileged afterwards, but you don’t want to mix and match during transfer.

(Dragan Espenschied) #3

Thank you Stéphane!
Unfortunately I cannot update the host system that hosts the LXC 1.0.7 containers.
Instead I rsynced the content of /var/lib/lxc to a separate directory on my LXC 3 host. Then I have tried to convert them using sudo lxc-to-lxd --lxcpath /lxc-migration/lxc --dry-run --debug <container>. I was able to comment out stuff from the configuration that are not required anymore. But the converter doesn’t recognize overlayfs.

Couldn't find the container rootfs 'overlayfs:/...'

All my containers are using overlayfs, and I have the data for all containers. They are all overlaid over a base ubuntu trusty container. I already tried to change the absolute paths in lxc.rootfs to point to the paths where all container data has been moved to, but lxc-to-lxd doesn’t seem to work when overlayfs is present at all.

Is there a way to “flatten” a chain over overlayfs?

(Vudududu) #4

I had same issue I created same os version lxd and moved rootfs with cp - rvp. After this lxc publish container and you are done. lxc start and it works as long as network is configured correctly

(Dragan Espenschied) #5

I have found a way to make a flattened rootfs for each of my overlayfs-based containers. Basically, manually mount them with overlayfs and then set the rootfs parameter in the LXC container config to that rootfs-mounted directory.

But, I am having trouble still to import the LXC containers into LXD: I am using LXD on ZFS.

the lxc-to-lxd converter apparently doesn’t support ZFS, the output looks like this:

console output
LXD container config:
 "architecture": "x86_64",
 "config": {
  "security.privileged": "true"
 "devices": {
  "convert_net0": {
   "hwaddr": "00:16:3e:4e:62:db",
   "nictype": "bridged",
   "parent": "lxcbr0",
   "type": "nic"
  "eth0": {
   "type": "none"
 "name": "ubuntu_trusty_amd64",
 "profiles": [
 "source": {
  "type": "none"
Creating the container
Copying container rootfs
Traceback (most recent call last):
  File "/usr/bin/lxc-to-lxd", line 621, in <module>
    container_name, args)
  File "/usr/bin/lxc-to-lxd", line 556, in convert_container
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/lxd/containers/ubuntu_trusty_amd64/rootfs'

I was wondering if @stgraber’s approach—just copying the rootfs into a dummy container—would work on ZFS, too?