4

I've looked all over, but can't see if there is a way. I have a couple LXC containers running Ubuntu 14.04 on top of a Ubuntu 14.04 Host. They've become pretty important to me, so I want to be able to easily backup / migrate the LXC containers to another server if the host's hardware should fail.

I've built a new Ubuntu 15.1 server now with LXD and have logged out and back in and see the new group. For testing, I tar'd one of my existing LXC containers up with the --numeric-owner switch on my 14.04 Host:

tar --numeric-owner -czvf ContToBeMoved.tgz /var/lib/lxc/my_container

---then on new server ---

tar --numeric-owner -xzvf ContToBeMoved.tgz -C /var/lib/lxc/

...and have successfully restored the LXC container on the new server 15.1 server.

When I run the LXD commands though, LXD doesn't see the container. I tried moving the container to the /var/lib/lxd/containers directory and still, LXD doesn't see it. Is there a way to edit / clone / migrate the LXC container so that we can use LXD moving forward?

Thanks in advance.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43
Mark
  • 41
  • 1
  • 5

1 Answers1

5

LXD uses a sqlite database for container configuration so just dumping the container's rootfs in place won't be quite enough.

The easiest way to do what you want is to create a new container with LXD, then remove its rootfs from /var/lib/lxd/containers/NAME/rootfs and substitute the one from your original host.

Note that LXD runs unprivileged containers by default, if your source container was privileged (/var/lib/lxc/NAME/rootfs is owned by root:root instead of 100000:100000), then you'll want to run the following too:

lxc config set NAME security.privileged true
stgraber
  • 256
  • 1
  • 5
  • Thanks so much for the feedback, and your info makes perfect sense. I'll give it a shot as soon as I'm able to. Right now have configured a backup LXC server, but live migration with LXD is just too impressive to pass up! =) Cheers. – Mark Nov 30 '15 at 22:56
  • Thank you a lot for this useful answer, however, this seems to not take into account the IPv4 network configuration, probably exactly because only the rootfs contents are copied over.. I just stumbled upon the https://github.com/lxc/lxd/blob/master/scripts/lxc-to-lxd script, but that also doesn't seem to like the `lxc.network.ipv4` configuration key(s)? – djvdorp Jan 30 '17 at 13:56