Difference between revisions of "Convert OpenVZ to LXC"

From Proxmox VE
Jump to navigation Jump to search
Line 143: Line 143:
==== PTY Allocation ====
==== PTY Allocation ====
When ssh to VPS then you experience error "lxc Server refused to allocate pty":
When ssh to VPS then you experience error "lxc Server refused to allocate pty":
# Enter to VPS edit /etc/rc.sysinit
# Enter to VPS, edit /etc/rc.sysinit
# Find /sbin/start_udev then comment out: #/sbin/start_udev
# Find /sbin/start_udev then comment out: #/sbin/start_udev
# Reboot VPS
# Reboot VPS

Revision as of 13:18, 29 May 2016


This article describes the migration of OpenVZ containers to Linux containers (LXC). OpenVZ is not available for Kernels above 2.6.32, therefore a migration is necessary. Linux Container technology is available in all mainline Linux kernels and a future proof technology introduced in Proxmox VE 4.x series.

Move an OpenVZ container to LXC in 5 steps

General overview

Basically you have to follow these steps:

on the Proxmox VE 3.x node

  1. note the network settings used by the container
  2. make a backup of the OpenVZ container

on the Proxmox VE 4.x node:

  1. restore/create a LXC container based on the backup
  2. configure the network with the previous settings
  3. boot and voilà, it works

Note that all the steps mentioned here can be done with the Web GUI. However, it is easier to split the steps in command line actions. This allows to script the steps if there is a bigger number of containers to convert.

Unsupported OpenVZ templates

Not all OpenVZ templates are supported. If you try to convert OpenVZ template with unsupported OS then you will get error message during pct restore command and restore will fail.

unsupported fedora release 'Fedora release 14 (Laughlin)'

Step by step conversion

Login with ssh on your Proxmox VE 3.x node:

Suppose you want to migrate three different containers: a CentOS container, an Ubuntu, and a Debian container.

      100         20 running   -               centos6vz.proxmox.com
      101         18 running   -               debian7vz.proxmox.com
      102         20 running  ubuntu12vz.proxmox.com

Get the network configuration of the OpenVZ containers, and note it somewhere

A) If your container uses a venet device, you get the address directly from the command line:

   vzlist 102
   102         20 running  ubuntu12vz.proxmox.com

B) If your container uses veth, the network configuration is done inside the container. How to find the network configuration depends on which OS is running inside the container:

If you have a CentOS based container, you can get the network configuration like this:

   # start a root shell inside the container 100
   vzctl enter 100
   cat /etc/sysconfig/network-scripts/ifcfg-eth0

There may be more than one network interface in CentOS that will be seen using ifcfg-eth1 and the like in the above command.

If you have a Debian, Ubuntu or Turnkey Linux appliance (all network interfaces are available in one go here):

   vzctl enter 101
   cat /etc/network/interfaces

Make a backup of your containers

First choose on which storage you want to backup the containers.

   #list available storages
   pvesm status
   freenas     nfs 1        27676672             128        27676544 0.50%
   local       dir 1         8512928         2122088         6390840 25.43%
   nas-iso     nfs 1      2558314496       421186560      2137127936 16.96%

For example, you can use the "local" storage, which corresponds to the directory /var/lib/vz/dump on a standard Proxmox VE installation. By default, this storage does not allow backups to be stored, so make sure you enable it for backup contents. (see http://pve.proxmox.com/wiki/Storage_Model#Storage_type_Content)

Then backup all the containers

   # stop the container, and
   # start a backup right after the shutdown
   vzctl stop 100 && vzdump 100 -storage local
   vzctl stop 101 && vzdump 101 -storage local
   vzctl stop 102 && vzdump 102 -storage local

At that point you can either:

  • A) Upgrade your Proxmox VE 3.x node to Proxmox VE 4.x
  • B) Copy the backups to a Proxmox VE 4.x node, and do the conversion on the Proxmox VE 4.x node

Suppose you follow option B) (copy the backups to the Proxmox VE 4.x node, and convert to LXC format)

   # copy each container tar backup to the pve4 node via ssh
   scp /var/lib/vz/dump/vzdump-openvz-100-2015_08_27-10_46_47.tar root@pve4:/var/lib/vz/dump
   scp /var/lib/vz/dump/vzdump-openvz-101-2015_08_27-10_50_44.tar root@pve4:/var/lib/vz/dump
   scp /var/lib/vz/dump/vzdump-openvz-102-2015_08_27-10_56_34.tar root@pve4:/var/lib/vz/dump

Restore/Create LXCs based on your backup

Now switch to the Proxmox VE 4 node, and create containers based on the backup:

   pct restore  100 /var/lib/vz/dump/vzdump-openvz-100-2015_08_27-10_46_47.tar
   pct restore  101 /var/lib/vz/dump/vzdump-openvz-101-2015_08_27-10_50_44.tar
   pct restore  102 /var/lib/vz/dump/vzdump-openvz-102-2015_08_27-10_56_34.tar

At that point you should be able to see your containers in the web interface, but they still have no network.

Add network configuration based on the original settings

LXCs uses virtual network adapter which are bridged to the physical interface of your host. This works very similar to the way veth devices work in OpenVZ.

In Proxmox VE 3.x the configuration of each container using a veth device had to be done inside the container. In Proxmox VE 4.x you can do this directly from the host.

Add network configuration via the GUI

For each container:

  • Select the container by clicking on it
  • Go to the Network tab
  • Click Add device
  • On the veth device panel, add a device with the parameters:
ID: net0
name eth0
put your IP address and the corresponding netmask in the following format
Add network configuration via the CLI
pct set 101 -net0 name=eth0,bridge=vmbr0,ip=,gw=
pct set 102 -net0 name=eth0,bridge=vmbr0,ip=,gw=

Start the containers

pct start 100
pct start 101
pct start 102 

and voilà, you can now log in to a container and check that your services are running

pct enter 100

Optional steps

Graphical console

If you have not yet done it before, you can add a console to your container, so you can log in to the containers via the web GUI.

OpenVZ bind mounts

If you use OpenVZ bind mounts, you need to recreate them in LXC. See LXC Bind Mounts

PTY Allocation

When ssh to VPS then you experience error "lxc Server refused to allocate pty":

  1. Enter to VPS, edit /etc/rc.sysinit
  2. Find /sbin/start_udev then comment out: #/sbin/start_udev
  3. Reboot VPS

Video tutorials


See also