Difference between revisions of "Physical to container"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
m (added info on dev-ptmx and not able to enter VE)
(reformatted using sections/subsections/subsub....)
Line 1: Line 1:
 
A rough description of how to migrate existing physical server into a [[VE]].
 
A rough description of how to migrate existing physical server into a [[VE]].
  
What you need to do in order to migrate is:
+
== Prepare a new “empty” VE ==
 
+
For OpenVZ this would mean the following (assume you chose VE ID of 123):
* Prepare an “empty” VE. For OpenVZ this would mean the following (assume you choose VE ID of 123):
 
  
 
  mkdir /vz/root/123 /vz/private/123
 
  mkdir /vz/root/123 /vz/private/123
 
  cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/123.conf
 
  cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/123.conf
  
* Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not loose your data. Just leave the bare minimum (including ssh).
 
  
* Copy all your data from the machine to an OpenVZ box. Say you'll be using VE with ID of 123, then all the data should be placed to <code>/vz/private/123/</code> directory (so there will be directories such as <code>/vz/private/123/bin</code>, <code>etc</code>, <code>var</code> and so on). This could be done by scp or rsync.
+
== Preparing to migrate ==
 +
 
 +
Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not loose your data. Just leave the bare minimum (including ssh daemon).
 +
 
 +
 
 +
== Copying the data ==
 +
 
 +
Copy all your data from the machine to an OpenVZ box. Say you'll be using VE with ID of 123, then all the data should be placed to <code>/vz/private/123/</code> directory (so there will be directories such as <code>/vz/private/123/bin</code>, <code>etc</code>, <code>var</code> and so on). This could be done by scp or rsync.
 +
 
 +
== Set VE parameters ==
  
* Set some VE parameters. You have to add <code>OSTEMPLATE=xxx</code> line to <code>/etc/vz/conf/123.conf</code> file, where <code>xxx</code> would be distribution name (like <code>debian-3.0</code>) for vzctl to be able to make changes specific for this distribution.
+
=== OSTEMPLATE ===
 +
You have to add <code>OSTEMPLATE=xxx</code> line to <code>/etc/vz/conf/123.conf</code> file, where <code>xxx</code> would be distribution name (like <code>debian-3.0</code>) for vzctl to be able to make changes specific for this distribution.
  
: Also, you have to supply an IP for a new VE:
+
=== IP address(es) ===
 +
Also, you have to supply an IP for a new VE:
 
   
 
   
 
  vzctl set 123 --ipadd x.x.x.x --save
 
  vzctl set 123 --ipadd x.x.x.x --save
  
* You have to edit some files inside a VE. For example, virtual server does not have real ttys, so you have to disable getty in <code>/etc/inittab</code> (i. e. <code>/vz/private/123/etc/inittab</code>). Also, link <code>/etc/mtab</code> to <code>/proc/mounts</code>.
+
== Making adjustments ==
 +
Since VE is a bit different than a real physical server, you have to edit some files inside your new VE.
 +
 
 +
=== /etc/inittab ===
 +
A VE does not have real ttys, so you have to disable getty in <code>/etc/inittab</code> (i. e. <code>/vz/private/123/etc/inittab</code>).
  
 
  sed -i -e '/getty/d' /vz/private/123/etc/inittab
 
  sed -i -e '/getty/d' /vz/private/123/etc/inittab
 +
 +
=== /etc/mtab ===
 +
Link <code>/etc/mtab</code> to <code>/proc/mounts</code>:
 +
 
  rm -f /vz/private/123/etc/mtab
 
  rm -f /vz/private/123/etc/mtab
 
  ln -s /proc/mounts /vz/private/123/etc/mtab  
 
  ln -s /proc/mounts /vz/private/123/etc/mtab  
  
'''Also check that:'''
+
=== /etc/fstab ===
- fstab is empty ; fstab has to be empty.
+
Since you do not have any real disk partitions in a VE, /etc/fstab (or most part of it) is no longer needed. Empty it (excluding the line for /dev/pts):
  - /dev/ptymx exists
+
 
  if it does not exist, create with: <code>vzctl exec 123 mknod /dev/ptmx c 5 2</code>
+
  cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old
  - check if /dev/pts exists
+
  grep devpts /vz/private/123/etc/fstab.old > /vz/private/123/etc/fstab
    it's a dir, if it does not exist, create with <code>vzctl exec 123 mkdir /dev/pts</code>
 
  
: There might be other adjustments needed. Please add if you have more info.
+
=== /dev TTY devices ===
 +
In order for vzctl enter to work, a VE need to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.
  
* Try to start your new VE:
+
==== /dev/ptmx ====
 +
Check that /dev/ptmx exists. If it does not, create with:
 +
mknod /vz/private/123/dev/ptmx c 5 2
 +
 
 +
==== /dev/pts/ ====
 +
Check that /dev/pts exists. It's a directory, if it does not exist, create with:
 +
mkdir /vz/private/123/dev/pts
 +
 
 +
==== /dev/ttyp* and /dev/ptyp* ====
 +
Check that /dev/ttyp* and /dev/ptyp* files are there. If not, you have to create those, either by using /sbin/MAKEDEV, or by copying them from the host system.
 +
 
 +
To copy:
 +
cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/
 +
 
 +
To recreate with MAKEDEV, either
 +
/sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp
 +
or
 +
cd /vz/private/123/dev && /sbin/MAKEDEV ttyp
 +
 
 +
=== Other ===
 +
There might be other adjustments needed. Please add those here if you have more info.
 +
 
 +
== Starting a new VE ==
 +
 
 +
Try to start your new VE:
 
   
 
   
 
  vzctl start 123
 
  vzctl start 123
  
* If your node starts but you can not enter it, you should be able to execute commands in it.
+
Now check that everything works fine. If not, see [[#Troubleshooting]] below.
check if devpts is mounted.
+
 
  <code>vzctl exec 123 mount</code>
+
== Troubleshooting ==
 +
 
 +
=== Can't enter VE ===
 +
 
 +
If you can not enter your VE (using <code>vzctl enter</code>), you should be able to at least execute commands in it.
 +
 
 +
First, see the [[#/dev TTY devices]] section above.
 +
 
 +
Next, check if devpts is mounted:
 +
  vzctl exec 123 mount | grep pts
 +
 
 +
If it is not mounted, mount it:
 +
vzctl exec 123 mount -t devpts none /dev/pts
  
If it is not mounted, mount it <code>vzctl exec 123 mount -t devpts none /dev/pts</code>
+
Then, add the appropriate mount command to VE's startup scripts. On some distros, you need to have the appropriate line in VE's /etc/fstab.
If it does not exist, please check above to create it correctly.
 
  
: If anything goes wrong, try to find out why and fix. If you have enough Linux experience, it can be handled.
+
=== Other problems ===
: Also check out IRC and please report back on this page.
+
If anything goes wrong, try to find out why and fix. If you have enough Linux experience, it can be handled. Also check out IRC and please report back on this page.
  
 
== Success Stories ==
 
== Success Stories ==

Revision as of 14:50, 8 February 2007

A rough description of how to migrate existing physical server into a VE.

Prepare a new “empty” VE

For OpenVZ this would mean the following (assume you chose VE ID of 123):

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


Preparing to migrate

Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not loose your data. Just leave the bare minimum (including ssh daemon).


Copying the data

Copy all your data from the machine to an OpenVZ box. Say you'll be using VE with ID of 123, then all the data should be placed to /vz/private/123/ directory (so there will be directories such as /vz/private/123/bin, etc, var and so on). This could be done by scp or rsync.

Set VE parameters

OSTEMPLATE

You have to add OSTEMPLATE=xxx line to /etc/vz/conf/123.conf file, where xxx would be distribution name (like debian-3.0) for vzctl to be able to make changes specific for this distribution.

IP address(es)

Also, you have to supply an IP for a new VE:

vzctl set 123 --ipadd x.x.x.x --save

Making adjustments

Since VE is a bit different than a real physical server, you have to edit some files inside your new VE.

/etc/inittab

A VE does not have real ttys, so you have to disable getty in /etc/inittab (i. e. /vz/private/123/etc/inittab).

sed -i -e '/getty/d' /vz/private/123/etc/inittab

/etc/mtab

Link /etc/mtab to /proc/mounts:

rm -f /vz/private/123/etc/mtab
ln -s /proc/mounts /vz/private/123/etc/mtab 

/etc/fstab

Since you do not have any real disk partitions in a VE, /etc/fstab (or most part of it) is no longer needed. Empty it (excluding the line for /dev/pts):

cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old
grep devpts /vz/private/123/etc/fstab.old > /vz/private/123/etc/fstab

/dev TTY devices

In order for vzctl enter to work, a VE need to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.

/dev/ptmx

Check that /dev/ptmx exists. If it does not, create with:

mknod /vz/private/123/dev/ptmx c 5 2

/dev/pts/

Check that /dev/pts exists. It's a directory, if it does not exist, create with:

mkdir /vz/private/123/dev/pts

/dev/ttyp* and /dev/ptyp*

Check that /dev/ttyp* and /dev/ptyp* files are there. If not, you have to create those, either by using /sbin/MAKEDEV, or by copying them from the host system.

To copy:

cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/

To recreate with MAKEDEV, either

/sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp

or

cd /vz/private/123/dev && /sbin/MAKEDEV ttyp

Other

There might be other adjustments needed. Please add those here if you have more info.

Starting a new VE

Try to start your new VE:

vzctl start 123

Now check that everything works fine. If not, see #Troubleshooting below.

Troubleshooting

Can't enter VE

If you can not enter your VE (using vzctl enter), you should be able to at least execute commands in it.

First, see the #/dev TTY devices section above.

Next, check if devpts is mounted:

vzctl exec 123 mount | grep pts

If it is not mounted, mount it: vzctl exec 123 mount -t devpts none /dev/pts

Then, add the appropriate mount command to VE's startup scripts. On some distros, you need to have the appropriate line in VE's /etc/fstab.

Other problems

If anything goes wrong, try to find out why and fix. If you have enough Linux experience, it can be handled. Also check out IRC and please report back on this page.

Success Stories

- Debian 3.1 Sarge with MySQL, apache2, PowerDNS --stoffell 08:41, 8 February 2007 (EST)