4

Is there a standard way (or standard tools) to migrate physical machines into LXC containers for Ubuntu? I'm working with 12.04.5 machines. I have come across

But it is specifically for debian. The procedure seems to be

  1. copy root file system
  2. delete unneeded files
  3. configure container

It seems like an easy process but I am totally new to LXC and hoping for something a little less error prone. Another idea I had was to create an ubuntu container from a template and then copy over that file system. I bet plenty of /etc would be wrongfully clobbered though.

1 Answer 1

7

Since I posted this question I have done this process half a dozen times without too much trouble. I thought I would add some hints from what I've learned in the hope that someone finds them useful:

All you need to do is copy the root file system into the container's rootfs directory (/var/lib/lxc/YOUR_CONTAINER/rootfs/ for disk based backing storage). Exclude /proc, /dev, /sys and /tmp.

Afterwards:

  • Make fstab empty in the container
  • Ensure a minimal set of device files under /dev. I copy the device files from a sample container that I created using a template.
  • If you are going to use lxcbr0 for networking, set the network interface to DHCP in /etc/network/interfaces
  • If you are going to bridge to a physical interface, set the interface to static or manual. If manual, put the IP address in the container's config. Do not set to DHCP.
  • be sure you set a hwaddr in your container config. If you don't LXC will randomly generate one when the container loads causing a lot of stale ARP entries on your network.
  • read through /usr/share/lxc/templates/lxc-ubuntu. Pay special attention to the configure_ubuntu() function. You probably want to run most of those commands in your container.

After the container is up, go through all the processes in pstree, removing those that aren't needed in containers (udevd, ntpdate, mdadm, etc). Feel free to remove all kernel packages.

Here is a sample container configuration for completeness. This configuration is for a trusty host. The container in this instance is precise.

lxc.include = /usr/share/lxc/config/ubuntu.common.conf
lxc.start.auto=1
lxc.rootfs = /var/lib/lxc/myhost/rootfs
lxc.mount = /var/lib/lxc/myhost/fstab
lxc.utsname = myhost
lxc.arch = amd64

# Network configuration
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.ipv4 = 172.27.3.13/24
lxc.network.ipv4 = 172.27.3.15/24
lxc.network.ipv4.gateway = 172.27.3.1
lxc.network.hwaddr = 52:12:a1:a5:d3:23

If the host OS is precise, you'll want this in your config as well. The common file won't be available.

lxc.devttydir = lxc
lxc.tty = 4
lxc.pts = 1024
lxc.cap.drop = sys_module mac_admin
lxc.pivotdir = lxc_putold

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .