LXD Live Migration

Recommended reading Differences between OS Containers and Application Containers


LXC (LinuX Containers) provide an isolated operating system environment with its own file system, network, process and block I/O space. Source

LXC is a userspace interface for the Linux kernel containment features.
Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers. Source


LXD is a container “hypervisor” and a new user experience for LXC.

Specifically, it’s made of three components:

  • A system-wide daemon (lxd)
  • A command line client (lxc)
  • An OpenStack Nova plugin (nova-compute-lxd)



  • Create two virtual Linux machines and run them with an appropriate hypervisor.
  • Set up and configure a Linux container in one of the machines.
  • Manage the container with LXC and LXD. Demonstrate how to migrate it live from the first to the second virtual machine so that it keeps running there and the first machine can be shut down.
  • Discuss some of the tools such as Virt-Manager to manage virtual machines and containers.



  1. Create our VMs on our Hypervisor
  2. Set the Virtual Network
  3. Set the VN interfaces on VM1, VM2
  4. Set up LXD on VM1, VM2
  5. Create our container on VM1
  6. Create a migration profile on VM1, VM2
  7. Migrate our container



Running Windows 10 on my computer, I installed two Ubuntu Server 16.04 VMs over Virtualbox (I used this hypervisor given my previous experience with it while developping Android applications).

Setting the Virtual Network

Before you install Ubuntu in your VMs, make sure you first set up the internal network for the VMs in VirtualBox, the process of how we did that is explained here Setting a Virtual Network in VirtualBox.

Now we can proceed to install LXD and configure it to make our live migration possible.

Setting up LXD

These configuration steps apply for Ubuntu Server 16.04, for more information on other versions see Installing and Configuring LXD and its series.

Once you have your VM installed and configured, to set up LXD you have execute the following:

LXD supports a number of storage backends which should be considered in case we wanted to move containers or images in the future between backends. We’ll configure ZFS as it supports all the features LXD needs to offer the fastest and most reliable container experience.

To configure LXD to use it, simply run (do not set proxy nor bridging configuration):

Once you’ve got LXD set, we need to sort out the network configuration since LXD doesn’t listen to the network by default. The only way to talk to it is over a local unix socket at /var/lib/lxd/unix.socket.

To have it listen to the network, there are two useful keys to set:

It’s also good to set the configuration for the image management on LXD:

LXD does dynamic image caching. When instructed to create a container from a remote image, it will download that image into its image store, mark it as cached and record its origin. After a number of days without seeing any use (10 by default), the image is automatically removed. Every few hours (6 by default), LXD also goes looking for a newer version of the image and updates its local copy.

We repeat these steps for the second VM and at this point we should have a working version of the latest LXD release on both VMs.

Migrating a Container

On the VM we want to migrate from, we do:

To list all your containers, you can do:

To get more information from a specific container, you can do:

Finally, we have to add both of our LXDs as non unix-sockets remotes. For this we have to check what IP each VM has in the network running ifconfig on them.

Now we have our VMs connected and all the configuration set up, we need to install one last dependency:

And we should be able to do

We cover all these steps in the 2nd and 3rd part of the tutorial series:


LXD 2.0: Installing and configuring LXD [2/12]. (n.d.). Retrieved June 09, 2016, from https://www.stgraber.org/2016/03/15/lxd-2-0-installing-and-configuring-lxd-212/

LXD 2.0: Your first LXD container [3/12]. (n.d.). Retrieved June 09, 2016, from https://www.stgraber.org/2016/03/19/lxd-2-0-your-first-lxd-container-312/

LXD 2.0: Live migration [9/12]. (n.d.). Retrieved June 09, 2016, from https://www.stgraber.org/2016/04/25/lxd-2-0-live-migration-912/

Live Migration in LXD. (n.d.). Retrieved June 09, 2016, from https://insights.ubuntu.com/2015/05/06/live-migration-in-lxd/

Essential Concepts

Docker image vs container. (n.d.). Retrieved June 09, 2016, from http://stackoverflow.com/questions/23735149/docker-image-vs-container


What’s LXD? (n.d.). Retrieved June 09, 2016, from https://linuxcontainers.org/lxd/

What’s LXC? (n.d.). Retrieved June 09, 2016, from https://linuxcontainers.org/lxc/introduction/

What is the difference between Docker, LXD, and LXC. (n.d.). Retrieved June 09, 2016, from http://unix.stackexchange.com/questions/254956/what-is-the-difference-between-docker-lxd-and-lxc

LXC containers in Ubuntu Server 14.04 LTS. (n.d.). Retrieved June 09, 2016, from http://en.community.dell.com/techcenter/os-applications/w/wiki/6950.lxc-containers-in-ubuntu-server-14-04-lts