Changes

Jump to: navigation, search

Physical to container

3,051 bytes added, 06:03, 26 October 2017
Prepare a new “empty” container
To make things easier you may like to first follow the basic instructions elsewhere and create a dummy container based on the same Linux distribution you want to migrate. That way you can take that dummy as a template and then copy to your new migrated container and modify. You can later discard this dummy.
{{Note|Still better is to use this container from the same Linux distribution you want to migrate as the starting point for the new installation. In this case, if we are carefull to copy only the needed files from the original system, we will be able to skip many of the following steps.}}
== Prepare a new “empty” container ==
For OpenVZ this would mean the following (assume you chose CT ID of 123):
<source lang="bash">
mkdir /vz/root/123 /vz/private/123
cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/123.conf</source>
Hint: {{Note|Now comes the dummy container handy mentioned above: Simply copy the xxx.conf file of the dummy to your new yyy.conf and modify it.}}
{{Note|If you have created a container from the same distro as the basis for the migration, simply take note of the CT ID and skip this step.}}
== Copying the data ==
=== rsync ===
rsync example (run from On the new HN)create a file <code>/tmp/exclude.txt</code> with:<pre>/tmp/boot/lib/modules/etc/blkid/etc/mtab/etc/lvm/etc/fstab/etc/udev</pre> and run <b>rsync</b> as follows:<source lang="bash"> rsync -arvpz avz -H -X --one-file-system --numeric-ids --exclude-from=/dev tmp/exclude.txt -e ssh root@a.b.c.d:/ /vz/private/123/</source> {{Note|You should add the <code>-excludeH</code> option, so hardlinks will be preserved during sync and also include the <code>-X</code> option to preserve file extended attributes}} If your source system have multiple partitions (for example <code>/var</code> or <code>/home</code>) repeat the command above for each partition in your system; for example:<source lang=/proc "bash">rsync -avz -H -X --one-file-system --numeric-exclude=/tmp ids -e ssh root@a.b.c.d:/var/ /vz/private/123/var/</source>
'''Advantage:''' Your system doesn't really go down.
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.
{{Note|If you copied from the dummy container or are using it as basis for your migrated system then this step is already accomplished.}}
=== IP address(es) ===
=== /etc/fstab ===
Since you do not have any real disk partitions in a container, /etc/fstab (or most part of it) is no longer needed. Empty it (excluding the lines for <code>/dev/pts</code>, <code>/proc</code>, <code>/sys</code> and such):
<source lang="bash">
mv /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old
egrep '/dev/pts|/dev/shm|/proc|/sys' /vz/private/123/etc/fstab.old > /vz/private/123/etc/fstab
</source>
You can also mount a devpts in a running (but not fully functional) container:
vzctl exec 123 mount -t devpts none /dev/pts
 
A still better approach would be simply to copy the <code>/etc/fstab</code> from a previously created container from a template of the same or similar distribution. In the case of RedHat/CentOS 5 this is:
<source lang="bash">
none /dev/pts devpts rw 0 0
</source>
and for RedHat/CentOS 6:
<source lang="bash">
none /dev/pts devpts rw,gid=5,mode=620 0 0
</source>
=== /dev ===
{{Note| Once again if you are using the container from the same distro as basis, and you were carefull to not overwrite <code>/dev</code> with <b>rsync</b> by using the <code>--one-file-system</code> option, you can skip this section}}
==== Introduction: static /dev ====
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by <code>umask</code> ([[w:umask]]). You can use --mode option for <code>mknod</code> to set the desired permissions.
Hint:{{Note|Now comes the dummy container handy mentioned above: Simply copy the entire /dev directory of the dummy to your new migrated container - worked in my case at least with Debian Etch.}}
==== tty device nodes ====
===/proc===
{{Note| One more time you may skip this if you are using a container created from a template of the same distro as your basis system.}}
 
Make sure the /proc directory exists:
ls -la /vz/private/123/ | grep proc
=== /etc/init.d services ===
Some system services can (or in some cases should) be disabledand/or uninstaled. A few good candidates are:
* acpid, amd (not needed)
* lm_sensors (container does not have access to hardware sensors)
* microcodectl (container can not update CPU microcode)
* netplugd (container does not have real Ethernet device)* irqbalance (this is handled in host node)* auditd ( not needed in container)* lvm2-monitor (no LVM in containers)* ntp/ntpd (clock taken from host node)
To see which services are enabled:
iface lo inet loopback
iface eth0 inet dhcpstatic
address 10.0.0.4
netmask 255.0.0.0
Now check that everything works fine. If not, see [[#Troubleshooting]] below.
 
== Troubleshooting ==
=== 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.
 
== Scripting ==
For CentOS below are two scripts to help with the migration:
* [http://pastebin.com/ehf8G3H6 pre-copy.sh]: Does the necessary configuration required for the migration of a server/VM to a CT.
* [http://pastebin.com/thn0sezV post-copy.sh]: Performs steps 5 and 6.
== Success stories ==
* Centos 4.9 with MySQL, Apache, ColdFusion, etc. 26 August 2011
* Centos 5.6 with MySQL, Apache, BIND, Postfix, Mono, etc. 26 August 2011
* Centos 5.7 with MySQL, Apache, Nginx, Memcached, Postfix, Openx, etc. --[[User:juranas|Juranas]] 18 November 2011
* RedHat Enterprise Linux 5 (rhel 5.6 - x86_64) 14:50, 18 November 2011
* Debian 6.0.4 with DTC Hosting Contro Panel . 15:00, 14 May 2012
* Debian 6, LAMP with ISPManager CP (no adjustments were made, just transferred the file structure and created ctid.conf) 03:19, 15 Jun 2012
* Debian 5.0.3, with Mysql, Apache, ISCP omega, Postfix, etc --[[Special:Contributions/91.143.222.253|91.143.222.253]] 19:47, 28 June 2012 (EDT)
* Debian 6.0.5 with artica-zarafa, 20 Nov 2012
Anonymous user

Navigation menu