OS migration to OpenVZ container

       In this article I want to tell how easy it is to transfer a Linux system from a physical server or full virtualization (KVM, XEN, VMware) into an OpenVZ container. There are enough materials on this topic, but I will talk about the easiest way.
       First, some theoretical calculations. What are the main advantages you can get from container virtualization:
    • Minimum Virtualization Overhead
    • Transparency of the container file system from the host machine
    • High container loading speed
    • Ease of Live Migration

    But there are also disadvantages:
    • Virtualization Container Uses Host System Kernel
    • OpenVZ patches are not included in the standard kernels of popular Linux distributions.

       I needed to convert a VMware virtual machine with CentOS5. Specifically, I was interested in the VirtualPBX project , the necessary bundle for its work is not easy to configure, but the author of the project uploads a VMware image for quick deployment, the image is based on CentOS 5.
       So, for starters, download and run the VirtualPBX image using VMware player, everything works fine, but it works fine, but for permanent work, it’s not convenient for me to use a VMware image. At my disposal are several Proxmox VE 2.1 servers with KVM, OpenVZ virtualization and web-based management. Therefore, without thinking twice, we proceed to transfer VirtualPBX from the VMware image to the OpenVZ container. To transfer the OS, we will use the tar method, ideally it is better to use rsync for this.
       On the host with Proxmox, download the template for CentOS 5 and create a CT container using this template, setting the parameters you need! We launch the created container and check its operation (by connecting via ssh or to the container console via the Proxmox web interface), then stop it and go to the machine that needs to be transferred. These actions can also be performed from the Proxmox console without using the web interface.
       On a physical (VMware image in my case) machine, create a file with the exception of directories and files for tar archiving:
    # nano non_tar

          Next, we archive the root of the operating system, excluding directories and files from the list created earlier:
    # tar --numeric-owner -czvf /tmp/virtualPBX_6309.tar.gz -X /root/non_tar /
          Copy the resulting archive via ssh to the virtualization host machine (Note: it is copied to the host machine, and not to the container):
    # scp virtualPBX_6309.tar.gz root@IP_OpenVZ_Host:/tmp
          Connect to the host machine via ssh and go to the directory, where is our CentOS 5 / var / lib / vz / private / 100 deployed from the template, where 100 is the unique identifier of the OpenVZ virtual machine, so you most likely will have a different one.
    # cd /var/lib/vz/private/100
          And we expand our archive on top of the template (make sure that you are in the directory of the recently deployed template so as not to overwrite the root section of the host machine or other OpenVZ container):
    # tar xvpfz /tmp/virtualPBX_6309.tar.gz
       Basically, at this stage you can launch our container and enjoy the work of OC under OpenVZ with your settings.
    Marginal notes: For interest, I tried to deploy CentOS 6 to the template, but the virtual machine didn’t work correctly, I didn’t understand much, since I usually prefer to use debian-based distributions.

       The above method is very simple, and if you use rsync for copying, you can transfer the OS almost in real time with minimal downtime.
       I would like to say a few words about updating VirtualPBX. Since the image does not contain the latest builds of the project, we will make a small script for updating:
    # touch /usr/bin/virtualpbx
    # chmod +x /usr/bin/virtualpbx
    # nano /usr/bin/virtualpbx
          Add the following code:
    	read -p 'Введите номер-версию для обновления (например: 6446):' REPLY 
    	wget http://virtual-pbx.googlecode.com/files/VirtualPBX-$REPLY.tgz && echo "Загрузка успешно" || echo 
    	"Загрузка не удалась, возможно, введен неправильный номер сборки или поменялся метод  нумерации проекта" 
    	 if [ -f VirtualPBX-$REPLY.tgz ]; then
    		tar -xzf VirtualPBX-$REPLY.tgz 
    		rm -f VirtualPBX-$REPLY.tgz 
    		cd VirtualPBX-$REPLY 
             rpm -Fvh *.rpm
    	if [ $? -eq 0 ]; then 
    		echo "Обновление успешно!!!" 
    		echo "Обновление завершилось неудачно!!!" 
    	exit 1 
    	exit 0
    		echo "Обновление завершилось неудачно!!!"
    	exit 1

        Now for updating it is enough to give a command
    # virtualpbx
        and enter the desired revision number for installation.
       After writing a draft for the article, I found out that the author provided for checking for updates. Inside there is a script /opt/VirtualPBX/contrib/utils/check_updates.pl, once a day it checks for updates and if it finds an update, a red text appears at the top in the admin interface.

       Using the method described above, you can transfer other Linux distributions by changing the list of files and directories specific to the OS (in my example, the non_tar file), examples of settings for the transfer can be found on the Wiki . Good luck with your experiments!

    materials used to prepare the article:

    Also popular now: