Editing Physical to container

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 7: Line 7:
 
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.
 
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 ==
 
== Prepare a new “empty” container ==
 
For OpenVZ this would mean the following (assume you chose CT ID of 123):
 
For OpenVZ this would mean the following (assume you chose CT ID of 123):
<source lang="bash">
+
 
 
  mkdir /vz/root/123 /vz/private/123
 
  mkdir /vz/root/123 /vz/private/123
  cat /etc/vz/conf/ve-basic.conf-sample > /etc/vz/conf/123.conf
+
  cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/123.conf
</source>
 
  
{{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.}}
+
Hint: 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 ==
 
== Copying the data ==
Line 25: Line 22:
  
 
=== rsync ===
 
=== rsync ===
On the new HN create a file <code>/tmp/exclude.txt</code> with:
+
rsync example (run from the new HN):
<pre>
+
  rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e "ssh -l root@a.b.c.d" root@a.b.c.d:/ /vz/private/123/
/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 -avz -H -X --one-file-system --numeric-ids --exclude-from=/tmp/exclude.txt -e ssh root@a.b.c.d:/ /vz/private/123/
 
</source>
 
 
 
{{Note|You should add the <code>-H</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="bash">
 
rsync -avz -H -X --one-file-system --numeric-ids -e ssh root@a.b.c.d:/var/ /vz/private/123/var/
 
</source>
 
  
 
'''Advantage:''' Your system doesn't really go down.
 
'''Advantage:''' Your system doesn't really go down.
 
{{Note|To decrease the downtime, you can use double rsync approach. Run rsync for the first time before stopping most of the services, and then for the second time after stopping services. That way most of the data will be transferred while your server is fully working, and the second rsync will just "catch the latest changes" which is faster.}}
 
  
 
=== Live CD ===
 
=== Live CD ===
Line 70: Line 44:
 
Then create the tar. But remember, when the system is 'not' using udev, you have to look into /proc/ after creating your container because some devices might not exist. (/dev/ptmx or others)
 
Then create the tar. But remember, when the system is 'not' using udev, you have to look into /proc/ after creating your container because some devices might not exist. (/dev/ptmx or others)
  
  # tar --numeric-owner -cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl
+
  # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl
  
 
Naturally, you can only do this when the critical services (MySQL, apache, ..) are stopped and your /tmp filesystem is big enough to contain your tar.
 
Naturally, you can only do this when the critical services (MySQL, apache, ..) are stopped and your /tmp filesystem is big enough to contain your tar.
Line 81: Line 55:
 
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.
 
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.}}
+
If you copied from the dummy container then this step is already accomplished.
  
 
=== IP address(es) ===
 
=== IP address(es) ===
Line 100: Line 74:
 
A container 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>).
 
A container 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 's/^[0-9].*getty.*tty/#&/g' /vz/private/123/etc/inittab
 
  
 
=== /etc/mtab ===
 
=== /etc/mtab ===
 
Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, for <code>df</code> to work properly:
 
Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, for <code>df</code> to work properly:
  
  ln -sf /proc/mounts /vz/private/123/etc/mtab
+
rm -f /vz/private/123/etc/mtab
 +
  ln -s /proc/mounts /vz/private/123/etc/mtab
  
 
{{out|The problem here is container's root filesystem (<code>/</code>) is mounted not from the container itself, but rather from the host system. That leaves <code>/etc/mtab</code> in container without a record for <code>/</code> being mounted, thus df doesn't show it. By linking <code>/etc/mtab → /proc/mounts</code> we make sure /etc/mtab shows what is really mounted in a container.
 
{{out|The problem here is container's root filesystem (<code>/</code>) is mounted not from the container itself, but rather from the host system. That leaves <code>/etc/mtab</code> in container without a record for <code>/</code> being mounted, thus df doesn't show it. By linking <code>/etc/mtab → /proc/mounts</code> we make sure /etc/mtab shows what is really mounted in a container.
Line 113: Line 87:
  
 
=== /etc/fstab ===
 
=== /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):
+
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 line for /dev/pts):
<source lang="bash">
+
 
  mv /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old
+
  cp /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
+
  grep devpts /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:
 
You can also mount a devpts in a running (but not fully functional) container:
 
  vzctl exec 123 mount -t devpts none /dev/pts
 
  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 ===
 
=== /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 ====
 
==== Introduction: static /dev ====
Line 145: Line 108:
 
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.
 
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.
  
{{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.}}
+
Hint:
 +
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 ====
 
==== tty device nodes ====
Line 178: Line 142:
 
Check that /dev/urandom exists. If it does not, create with:
 
Check that /dev/urandom exists. If it does not, create with:
 
  mknod --mode 444 /vz/private/123/dev/urandom c 1 9
 
  mknod --mode 444 /vz/private/123/dev/urandom c 1 9
 
==== Using udev anyway ====
 
CentOS 5 can run in a container with udev enabled.  You need to create /etc/udev/devices, containing the above device nodes.  Also, the following will create the extra device nodes you need
 
mkdir /vz/private/123/etc/udev/devices
 
/sbin/MAKEDEV -d /vz/private/123/dev {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0
 
/sbin/MAKEDEV -d /vz/private/123/etc/udev/devices {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0
 
  
 
===/proc===
 
===/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:
 
Make sure the /proc directory exists:
 
  ls -la /vz/private/123/ | grep proc
 
  ls -la /vz/private/123/ | grep proc
Line 196: Line 152:
 
=== /etc/init.d services ===
 
=== /etc/init.d services ===
  
Some system services can (or in some cases should) be disabled and/or uninstaled. A few good candidates are:
+
Some system services can (or in some cases should) be disabled. A few good candidates are:
  
 
* acpid, amd (not needed)
 
* acpid, amd (not needed)
Line 208: Line 164:
 
* lm_sensors (container does not have access to hardware sensors)
 
* lm_sensors (container does not have access to hardware sensors)
 
* microcodectl (container can not update CPU microcode)
 
* microcodectl (container can not update CPU microcode)
* netplugd (container does not have real Ethernet device)
+
* 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:
 
To see which services are enabled:
Line 221: Line 173:
  
 
To disable the service:
 
To disable the service:
* RedHat/Fedora/SUSE: <code>/sbin/chkconfig SERVICENAME off </code>
+
* RedHat/Fedora/SUSE: <code>/sbin/chkconfig --del SERVICENAME </code>
 
* Debian: <code>' update-rc.d -f hdparm remove '</code>
 
* Debian: <code>' update-rc.d -f hdparm remove '</code>
 
* Gentoo: <code>/sbin/rc-update del SERVICENAME</code>
 
* Gentoo: <code>/sbin/rc-update del SERVICENAME</code>
Line 233: Line 185:
 
Make the following look like this:
 
Make the following look like this:
 
  ONBOOT=no
 
  ONBOOT=no
 
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or
 
/vz/private/{CTID}/etc/sysconfig/network-scripts/ifup-venet exist, make sure they won't be used. These two files might exist if the physical server had OpenVZ installed. One way to do this is to rename them, like so:
 
mv ifdown-venet SKIP.ifdown-venet
 
 
Failing to do this will prevent networking from starting up correctly in the container.
 
  
 
==== Debian/Ubuntu ====
 
==== Debian/Ubuntu ====
Line 251: Line 197:
 
iface lo inet loopback
 
iface lo inet loopback
  
iface eth0 inet static
+
iface eth0 inet dhcp
 
       address 10.0.0.4
 
       address 10.0.0.4
 
       netmask 255.0.0.0
 
       netmask 255.0.0.0
Line 259: Line 205:
  
 
You can either comment out the eth* interface stanza(s), or take it out of the "auto" line(s).
 
You can either comment out the eth* interface stanza(s), or take it out of the "auto" line(s).
 
===== Ubuntu server 8.x =====
 
 
Here what I have done for my Ubuntu server JEOS 8.04.2
 
 
<pre>
 
rm /vz/private/123/etc/network/if-up.d/ntpdate
 
rm /vz/private/123/etc/event.d/tty{1,2,3,4,5,6}
 
vzctl exec 123 update-rc.d -f klogd remove
 
vzctl exec 123 update-rc.d -f udev remove
 
 
</pre>
 
  
 
==== openSUSE/SLES ====
 
==== openSUSE/SLES ====
  
 
Use Yast.
 
Use Yast.
 
=== Disable udev if you create DEVNODES devices ===
 
 
If you are creating devices for the container with a DEVNODES statement in a veid.conf file then these devices may be overwritten/deleted by udev when the container starts. As udev cannot "see" the device from within the container it disables it. Therefore, if you have DEVNODES statements in veid.conf then disable udev.
 
 
In Fedora, Redhat, Centos, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit
 
Comment the line similar to this:
 
#[ -x /sbin/start_udev ] && /sbin/start_udev
 
  
 
=== Other adjustments ===
 
=== Other adjustments ===
Line 294: Line 220:
  
 
Now check that everything works fine. If not, see [[#Troubleshooting]] below.
 
Now check that everything works fine. If not, see [[#Troubleshooting]] below.
 
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 303: Line 228:
  
 
  mkdir tmp
 
  mkdir tmp
  chmod 1777 tmp
+
  chmod 777 tmp
 +
 
  
 
=== Can't enter container ===
 
=== Can't enter container ===
Line 328: Line 254:
 
=== Other problems ===
 
=== 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.
 
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 ==
 
== Success stories ==
Line 348: Line 269:
 
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)
 
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)
 
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)
 
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)
* Centos 4.6 with cPanel/WHM (Apache2, Mysql, Exim, etc) --[[User:Zccopwrx|Zccopwrx]] 08:16, 30 July 2008 (EDT)
+
* Centos 5 with AOLServer, PostgreSQL, Java, Tomcat, Apache etc. <code><nowiki>--~~~~</nowiki></code>
* SlackWare 10.1 (Qmail) --[[User:defiancenl|defiancenl]]
 
* SlackWare 10.0 (Qmail) --[[User:defiancenl|defiancenl]]
 
* Ubuntu 8.04.3 LTS JEOS (Apache2, Mysql) --[[User:bougui|bougui]] Fri Aug 28 10:40:41 EDT 2009
 
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009
 
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}
 
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)
 
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)
 
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC)
 
* Redhat 4 -- 20:32, 18 August 2010 (UTC)
 
* Fedora 4 -- 15:06, 20 August 2010 (UTC)
 
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010
 
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)
 
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
* Debian 6 (Squeeze) with Lighttpd, MySQL, nfs, smb, etc. --[[Special:Contributions/95.21.175.189|95.21.175.189]] 22:39, 30 July 2011 (UTC)
 
* RedHat 9 (Shrike) with apache,nginx,mysql,qmail 09 August 2011 (UTC)
 
* Centos 5.6 with Postresql and JitterBit 24 August 2011
 
* 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
 

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: