HOWTO use lxd-p2c

I had great difficulty in getting lxd-p2c to work so I have written some notes on the process which will hopefully help someone get up and running faster. Feel free to improve these notes, put them on the wiki or whatever.

LXD 3.x introduced lxd-p2c, a go program to ease the process of migrating an existing Linux server (most likely physical, but it could be another type of VM) into an LXD container. The LXD devs have decided not to bundle lxd-p2c in either their Ubuntu packages nor the LXD snap so it has to be manually built from the LXD github repo. It is expected that the source machine is likely to not have a version of go new enough to build lxd-p2c in which case it can be built on a newer machine and then the static build transferred over.

Building lxd-p2c

You should run the exact same version of lxd-p2c on the machine being containerised as is running on the lxd server, otherwise you may get rsync errors preventing the transfer starting.

If the machine to be containerised is running a 64 bit Linux OS and your lxd server is running LXD 3.8, for example, you would build lxd-p2c like so:

~$ go get
~$ cd go/src/
~/go/src/$ git checkout lxd-3.8
~/go/src/$ go get

If the build completes successfully, the lxd-p2c binary should be under ~/go/bin .

If the machine to be containerised is running a 32 bit Linux OS and you’re bullding lxd-p2c on a 64 bit OS, you would do the same but the last command would be replaced with:

$ env GOOS=linux GOARCH=386 go get

Preparing to run lxd-p2c

lxd-p2c depends upon TLS to work and so it will fail if the clocks of the machine being containerised and the LXD server are out of sync so its best to ensure NTP is enabled on both beforehand.

When you run lxd-p2c, it will request you enter an admin password before the transfer begins. This is the password created when you are configuring the bridge interface to be used by lxd when you run lxd init on the lxd server to do the initial configuration. In case you have forgot what that password was, it can be reset by running:

$ sudo lxc config set core.trust_password some-password

It is recommended to stop the active services (eg web servers, databases etc) before running lxd-p2c. Failure to do so could result in data loss or corruption. At the bare minimum you should at least stop the logging services before running lxd-p2c, which under recent releases of Ubuntu can be achieved by running:

$ sudo systemctl disable rsyslog
$ sudo systemctl stop rsyslog
$ sudo systemctl mask systemd-journald
$ sudo systemctl stop systemd-journald

Running lxd-p2c

Simply stopping rsyslog isn’t enough because systemd automatically restarts rsyslog when data is written to the system log socket.Running lxd-p2cIf you only have one filesystem / mount point to containerise (the root fs) and you wanted to create a container called test, then a simple invocation of lx2-p2c would look like:

$ sudo ./lxd-p2c https://lxdserver:8443 test /

Doing the same but omitting /var/cache by passing an rsync option would look like:

$ sudo ./lxd-p2c https://lxdserver:8443 test / --rsync-args="--exclude=/var/cache"

Excellent notes! Do you have any suggestions on how to handle this issue I’m encountering trying to migrate a 32 bit CentOS 5.11 system to LXD?

[root@localhost /]# ./lxd-p2c centos5-test /

Error: Failed to setup the source: Failed to make / read-only: device or resource busy

I’ve tried shutting down various services and mounting / ro, but that won’t work either since /tmp is not on a separate partition.

Hi Brian

No, I’ve not encountered that error when using lxd-p2c but please let us know if you work out what causes it or how to fix it.

Thank you for these notes, great help.

Some additional notes:

  1. After the transfer was finished my container was having troubles, services not starting. It relates to this discussion: So you may need to clean out your /etc/fstab which I did and after reboot everything was working nicely.

  2. My original ubuntu 18 server had some networking setup, hardcoded in /etc/network/interfaces and was not using netplan. The container would not be assigned an IP… So I removed the interfaces file and setup netplan as discussed here: and rebooted the container and now networking is good and it is assigned an IP automatically.

  3. Before doing the transfer i did a service --status-all to see what services I had going and stopped most to quiet things down.

The lxd-p2c tool works great and made a difficult task much much easier. Cheers!