How To Convert Physical Systems And Xen VMs Into OpenVZ Containers (Debian Etch)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Wed, 2009-01-14 18:01. :: Debian | OpenVZ | Xen | Virtualization

How To Convert Physical Systems And Xen VMs Into OpenVZ Containers (Debian Etch)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 12/17/2008

This guide explains how you can convert physical systems (running Debian Etch) or Xen domUs (also running Debian Etch) into an OpenVZ container. This procedure should also work for converting VMware VMs, VirtualBox VMs, or KVM VMs into OpenVZ containers, but I haven't tried this. It should work for other Linux distributions as well, with minor modifications (for example, the network configuration is not located in /etc/network/interfaces if you're not on Debian/Ubuntu).

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I want to convert the physical system or Xen domU server1.example.com (with the IP address 192.168.0.100) into an OpenVZ container. I have a second server, server2.example.com, where I have set up OpenVZ according to this guide: Installing And Using OpenVZ On Debian Etch. I will use the VEID 211 for the new OpenVZ container on server2.example.com.

I will use /vz here as the OpenVZ directory, so make sure that /vz is a symlink to /var/lib/vz:

server2:

ln -s /var/lib/vz /vz

 

2 Converting server1.example.com To OpenVZ

First we create two empty directories for the new OpenVZ container 211 on server2 and also a standard OpenVZ configuration file for the new container:

server2:

mkdir /vz/root/211 /vz/private/211
cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/211.conf

Next we install rsync on both systems as we will use rsync to transfer the files from server1 to the OpenVZ container:

server1/server2:

apt-get install rsync

Now let's transfer server1's files to the OpenVZ container:

server2:

rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e "ssh -l root@192.168.0.100" root@192.168.0.100:/ /vz/private/211/

This can take a few minutes, depending on the number and size of the files on server1.

Afterwards, we can configure our new OpenVZ container with the vzctl command, as you would do if you would create a new container from scratch.

OpenVZ needs to know which distribution is used in the container, therefore we must set the OSTEMPLATE value:

server2:

vzctl set 211 --ostemplate debian-4.0-i386-minimal --save

Afterwards, you can set the network parameters and also the disk space of the new container:

server2:

vzctl set 211 --onboot yes --save

vzctl set 211 --hostname server1.example.com --save
vzctl set 211 --ipadd 192.168.0.100 --save
vzctl set 211 --numothersock 120 --save
vzctl set 211 --nameserver 145.253.2.75 --nameserver 213.191.92.86 --save

vzctl set 211 --diskspace 10000000:11000000 --save

(This would set a disk space soft limit of 10GB and a hard limit of 11GB.)

If you like, you can give the container an IP address different from that used on the original system; in that case you might have to adjust a few other files in the container (e.g. Apache configuration, etc., depending on what is installed in the container). If you use the same IP address, don't forget to shut down the original system before you power on the OpenVZ container!

These are the basic settings. You can, of course, also change the other settings with the vzctl command.

Before we start the OpenVZ container, we have to do a few OpenVZ-specific changes to it:

server2:

sed -i -e '/getty/d' /vz/private/211/etc/inittab
rm -f /vz/private/211/etc/mtab
ln -s /proc/mounts /vz/private/211/etc/mtab

cp /vz/private/211/etc/fstab /vz/private/211/etc/fstab.old
grep devpts /vz/private/211/etc/fstab.old > /vz/private/211/etc/fstab
mkdir /vz/private/211/dev
mknod --mode 666 /vz/private/211/dev/ptmx c 5 2
mkdir /vz/private/211/dev/pts
cp -a /dev/ttyp* /dev/ptyp* /vz/private/211/dev/
rm -f /vz/private/211/dev/null
mknod --mode 666 /vz/private/211/dev/null c 1 3
mknod --mode 444 /vz/private/211/dev/urandom c 1 9
mkdir /vz/private/211/proc
cat /dev/null > /vz/private/211/etc/network/interfaces

That's it, you can now start the new OpenVZ container (don't forget to shut down the old system first if both are using the same IP!)...

server2:

vzctl start 211

... and set a password:

vzctl exec 211 passwd

 

3 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sun, 2010-11-14 21:06.

Worked from xen 3.2-1 just needed to add ORIGIN_SAMPLE="pve.auto" to /etc/vz/conf/211.conf Cheers, Torsten

Submitted by Ilya (not registered) on Thu, 2010-08-05 08:10.
Can anyone help with such CentOS howto ?
about migration CentOS Xen domU to OpenVZ container
Submitted by Noam (not registered) on Wed, 2009-12-09 14:28.

Work great for VMWARE!

I've converted VMware Workstation guest of  Suse Enterprise Linux 10 64bit (running WebSphere) into ProxMox OpenVZ!

Thanks!

Submitted by mfmesa (registered user) on Tue, 2010-06-01 19:41.
Hi Noam !!! We have a server with SLES 10 like application server under VMWARE server, and migrate to OpenVZ, but have problem with it.

can you say me what method are you use for this job ?. Some tips about the setup of system ? could you help me ?


Thank in advanced. Manuel.
Submitted by Anonymous (not registered) on Tue, 2009-08-25 16:27.

I prefer to prefix the directories with "/" in the rsync command. It prevents rsync to exclude any files or directory that may contain "dev" or "proc" in the name:

 rsync -arvpz --numeric-ids --exclude /dev --exclude /proc --exclude /tmp ...

 

thanks for the howto!

 

Submitted by Torsten (not registered) on Thu, 2009-08-20 18:43.

Thanks for that beautiful Howto. I had some problems and solved them this way:

  mkdir /vz/private/211/tmp

  chmod 777  /vz/private/211/tmp

  mkdir /vz/private/211/var/tmp

  chmod 777  /vz/private/211/var/tmp

  mknod --mode 666 /vz/private/211/dev/random c 1 8

  mknod --mode 666 /vz/private/211/dev/zero c 1 5

  mknod --mode 666 /vz/private/211/dev/null c 1 3

nice day

Submitted by dipps (registered user) on Wed, 2013-02-13 07:24.

I found /dev/tty was a normal file, and several things didn't work. It looked like this:

HN:# ls -l /vz/private/221/dev/tty
-rw-r--r-- 1 root root 16 Feb 13 14:42 /vz/private/221/dev/tty

To fix this:

   rm /vz/private/221/dev/tty

   mknod --mode 666 /vz/private/221/dev/tty c 5 0

Now it's a character special file and things are better:

HN:# ls -l /vz/private/221/dev/tty
crw-rw-rw- 1 root root 5, 0 Feb 13 15:55 /vz/private/221/dev/tty

Submitted by Anonymous (not registered) on Sat, 2009-01-17 23:30.

nice tutorial. very useful for users want to migrate to OpenVZ to Proxmox VE - http://pve.proxmox.com - the easy way to OpenVZ.