Convert OpenVZ to LXC
- 1 Introduction
- 2 Move an OpenVZ container to LXC in 5 steps
- 3 Step by step conversion
- 3.1 Get the network configuration of the OpenVZ containers, and note it somewhere
- 3.2 Make a backup of your containers
- 3.3 Create LXCs based on your backup
- 3.4 Add network configuration based on the original settings
- 3.5 Start the containers
- 3.6 Optional steps
- 4 Video tutorials
- 5 See also
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, currently in beta status.
Move an OpenVZ container to LXC in 5 steps
Basically you have to follow these steps:
on the Proxmox VE 3.x node
- note the network settings used by the container
- make a backup of the OpenVZ container
on the Proxmox VE 4.x node:
- create a LXC container based on the backup
- configure the network with your previous settings
- you 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 you to script the steps if you have a bigger number of containers to convert.
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.
vzlist CTID NPROC STATUS IP_ADDR HOSTNAME 100 20 running - centos6vz.proxmox.com 101 18 running - debian7vz.proxmox.com 102 20 running 192.168.15.142 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 CTID NPROC STATUS IP_ADDR HOSTNAME 102 20 running 192.168.15.142 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 exit
If you have a Debian, Ubuntu or Turnkey Linux appliance:
vzctl enter 101 cat /etc/network/interfaces exit
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
- B) Copy the backups to a Proxmox VE 4 node, and do the conversion on the Proxmox VE 4 node
Suppose you follow option B) (copy the backups to the Proxmox VE 4 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
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 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 192.168.5.75/24
Add network configuration via the CLI
pct set 101 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.144/24,gw=192.168.15.1 pct set 102 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.145/24,gw=192.168.15.1
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
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
- this works 2015-09-13 using lxc-pve: 1.1.3-1 .
- add this to the .conf file in /etc/pve/lxc
lxc.mount.entry=/bkup bkup none bind 0 0
note do not put a '/' before the target