<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bougui</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bougui"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Bougui"/>
	<updated>2026-04-09T16:47:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7497</id>
		<title>Physical to container</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7497"/>
		<updated>2009-08-29T20:00:13Z</updated>

		<summary type="html">&lt;p&gt;Bougui: /* Ubuntu server 8.x */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A rough description of how to migrate existing physical server into a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Preparing to migrate ==&lt;br /&gt;
&lt;br /&gt;
Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not lose your data. Just leave the bare minimum (including ssh daemon).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prepare a new “empty” container ==&lt;br /&gt;
For OpenVZ this would mean the following (assume you chose CT ID of 123):&lt;br /&gt;
&lt;br /&gt;
 mkdir /vz/root/123 /vz/private/123&lt;br /&gt;
 cat /etc/vz/conf/ve-vps.basic.conf-sample &amp;gt; /etc/vz/conf/123.conf&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copying the data ==&lt;br /&gt;
&lt;br /&gt;
Copy all your data from the machine to an OpenVZ box. Say you'll be using container with ID of 123, then all the data should be placed to &amp;lt;code&amp;gt;/vz/private/123/&amp;lt;/code&amp;gt; directory (so there will be directories such as &amp;lt;code&amp;gt;/vz/private/123/bin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;etc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; and so on). This could be done in several ways:&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
rsync example (run from the new HN):&lt;br /&gt;
 rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e &amp;quot;ssh -l root@a.b.c.d&amp;quot; root@a.b.c.d:/ /vz/private/123/&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' Your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
=== Live CD ===&lt;br /&gt;
Another way to do is using a live cd, booting up and use tar to dump the complete disk in a tar you save over the network or on a USB device.&lt;br /&gt;
&lt;br /&gt;
=== Tar ===&lt;br /&gt;
Another approach is using tar and excluding some dirs, you could do it like this:&lt;br /&gt;
&lt;br /&gt;
Create a file /tmp/excludes.excl with these contents:&lt;br /&gt;
 .bash_history&lt;br /&gt;
 /dev/*&lt;br /&gt;
 /mnt/*&lt;br /&gt;
 /tmp/*&lt;br /&gt;
 /proc/*&lt;br /&gt;
 /sys/*&lt;br /&gt;
 /usr/src/*&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
 # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' You don't need to boot from a live cd, so your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
== Setting container parameters ==&lt;br /&gt;
&lt;br /&gt;
=== OSTEMPLATE ===&lt;br /&gt;
You have to add &amp;lt;code&amp;gt;OSTEMPLATE=xxx&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;/etc/vz/conf/123.conf&amp;lt;/code&amp;gt; file, where &amp;lt;code&amp;gt;xxx&amp;lt;/code&amp;gt; would be distribution name (like &amp;lt;code&amp;gt;debian-3.0&amp;lt;/code&amp;gt;) for vzctl to be able to make changes specific for this distribution.&lt;br /&gt;
&lt;br /&gt;
If you copied from the dummy container then this step is already accomplished.&lt;br /&gt;
&lt;br /&gt;
=== IP address(es) ===&lt;br /&gt;
Also, you have to supply an IP for a new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl set 123 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== venet vs. veth ===&lt;br /&gt;
You may use veth interface instead of venet if you need just bring old server up for seamless migration of services.&lt;br /&gt;
It may be nessessary if server you are migrating is badly configured and it is hard to find all hard-coded net interfaces settings and so on.&lt;br /&gt;
&lt;br /&gt;
veth inteface may be included into bridge to allow seamless old installation access.&lt;br /&gt;
&lt;br /&gt;
== Making adjustments ==&lt;br /&gt;
Since container is a bit different to a real physical server, you have to edit some files inside your new container.&lt;br /&gt;
&lt;br /&gt;
=== /etc/inittab ===&lt;br /&gt;
A container does not have real ttys, so you have to disable getty in &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; (i. e. &amp;lt;code&amp;gt;/vz/private/123/etc/inittab&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 sed -i -e '/getty/d' /vz/private/123/etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== /etc/mtab ===&lt;br /&gt;
Link &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, for &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; to work properly:&lt;br /&gt;
&lt;br /&gt;
 rm -f /vz/private/123/etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /vz/private/123/etc/mtab&lt;br /&gt;
&lt;br /&gt;
{{out|The problem here is container's root filesystem (&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;) is mounted not from the container itself, but rather from the host system. That leaves &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; in container without a record for &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; being mounted, thus df doesn't show it. By linking &amp;lt;code&amp;gt;/etc/mtab → /proc/mounts&amp;lt;/code&amp;gt; we make sure /etc/mtab shows what is really mounted in a container.&lt;br /&gt;
&lt;br /&gt;
Sure this is not the only way to fix df; you can just manually add a line to &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; telling &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; is mounted, and make sure this line will be there after a reboot.}}&lt;br /&gt;
&lt;br /&gt;
=== /etc/fstab ===&lt;br /&gt;
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):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 grep devpts /vz/private/123/etc/fstab.old &amp;gt; /vz/private/123/etc/fstab&lt;br /&gt;
&lt;br /&gt;
You can also mount a devpts in a running (but not fully functional) container:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
=== /dev ===&lt;br /&gt;
&lt;br /&gt;
==== Introduction: static /dev ====&lt;br /&gt;
In order for container to work, some nodes should be present in container's &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;. For modern distributions, udev is taking care of it. For a variety of reasons udev doesn't make much sense in a container, so the best thing to do is to disable udev and create needed device nodes manually.&lt;br /&gt;
&lt;br /&gt;
Note that in some distributions &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; — this will not work in case of static &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;. So what you need to do is find out where &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is being mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; and remove this. This is highly distribution-dependent; please add info for your distro here.&lt;br /&gt;
&lt;br /&gt;
For Suse 11.0, It is found in /etc/init.d/boot &lt;br /&gt;
&lt;br /&gt;
After you made sure your &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is static, populate it with needed device nodes.&lt;br /&gt;
&lt;br /&gt;
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by &amp;lt;code&amp;gt;umask&amp;lt;/code&amp;gt; ([[w:umask]]). You can use --mode option for &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to set the desired permissions.&lt;br /&gt;
&lt;br /&gt;
Hint:&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==== tty device nodes ====&lt;br /&gt;
&lt;br /&gt;
In order for vzctl enter to work, a container needs to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.&lt;br /&gt;
&lt;br /&gt;
===== /dev/ptmx =====&lt;br /&gt;
Check that /dev/ptmx exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
===== /dev/pts/ =====&lt;br /&gt;
Check that /dev/pts exists. It's a directory, if it does not exist, create with:&lt;br /&gt;
 mkdir /vz/private/123/dev/pts&lt;br /&gt;
&lt;br /&gt;
===== /dev/ttyp* and /dev/ptyp* =====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To copy:&lt;br /&gt;
 cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/&lt;br /&gt;
&lt;br /&gt;
To recreate with MAKEDEV, either&lt;br /&gt;
 /sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp&lt;br /&gt;
or&lt;br /&gt;
 cd /vz/private/123/dev &amp;amp;&amp;amp; /sbin/MAKEDEV ttyp&lt;br /&gt;
&lt;br /&gt;
====/dev/null====&lt;br /&gt;
Make sure sure /dev/null is not a file or directory; if unsure remove and recreate. If this is not correct sshd will not start correctly.&lt;br /&gt;
 rm -f /vz/private/123/dev/null&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/null c 1 3&lt;br /&gt;
&lt;br /&gt;
==== /dev/urandom ====&lt;br /&gt;
Check that /dev/urandom exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 444 /vz/private/123/dev/urandom c 1 9&lt;br /&gt;
&lt;br /&gt;
===/proc===&lt;br /&gt;
Make sure the /proc directory exists:&lt;br /&gt;
 ls -la /vz/private/123/ | grep proc&lt;br /&gt;
&lt;br /&gt;
If it doesn't, create it:&lt;br /&gt;
 mkdir /vz/private/123/proc&lt;br /&gt;
&lt;br /&gt;
=== /etc/init.d services ===&lt;br /&gt;
&lt;br /&gt;
Some system services can (or in some cases should) be disabled. A few good candidates are:&lt;br /&gt;
&lt;br /&gt;
* acpid, amd (not needed)&lt;br /&gt;
* checkfs, checkroot (no filesystem checking is required in container)&lt;br /&gt;
* clock (no clock setting is required/allowed in container)&lt;br /&gt;
* consolefont (container does not have a console)&lt;br /&gt;
* hdparm (container does not have real hard drives)&lt;br /&gt;
* klogd (unless you use iptables to LOG some packets)&lt;br /&gt;
* keymaps (container does not have a real keyboard)&lt;br /&gt;
* kudzu (container does not have real hardware)&lt;br /&gt;
* lm_sensors (container does not have access to hardware sensors)&lt;br /&gt;
* microcodectl (container can not update CPU microcode)&lt;br /&gt;
* netplugd (container does not have real Ethernet device) &lt;br /&gt;
&lt;br /&gt;
To see which services are enabled:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --list&amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: Use '&amp;lt;code&amp;gt;rcconf&amp;lt;/code&amp;gt;' (ncurses) or &amp;lt;code&amp;gt;update-rc.d&amp;lt;/code&amp;gt;&lt;br /&gt;
( See: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html )&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To disable the service:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --del SERVICENAME  &amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: &amp;lt;code&amp;gt;' update-rc.d -f hdparm remove '&amp;lt;/code&amp;gt;&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update del SERVICENAME&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable old network interface ===&lt;br /&gt;
You should disable your old physical network interface from starting at boot time. This is distribution-dependant.&lt;br /&gt;
&lt;br /&gt;
==== Fedora/CentOS/Red Hat ====&lt;br /&gt;
Edit /vz/private/{CTID}/etc/sysconfig/network-scripts/ifcfg-eth''x''&lt;br /&gt;
&lt;br /&gt;
Make the following look like this:&lt;br /&gt;
 ONBOOT=no&lt;br /&gt;
&lt;br /&gt;
==== Debian/Ubuntu ====&lt;br /&gt;
Edit /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# /etc/network/interfaces -- configuration file for ifup(8),  ifdown(8)&lt;br /&gt;
&lt;br /&gt;
# The loopback interface&lt;br /&gt;
# automatically added when upgrading&lt;br /&gt;
auto lo eth0&lt;br /&gt;
iface lo inet loopback&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet dhcp&lt;br /&gt;
       address 10.0.0.4&lt;br /&gt;
       netmask 255.0.0.0&lt;br /&gt;
       network 10.0.0.0&lt;br /&gt;
       broadcast 10.0.0.255&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can either comment out the eth* interface stanza(s), or take it out of the &amp;quot;auto&amp;quot; line(s).&lt;br /&gt;
&lt;br /&gt;
===== Ubuntu server 8.x =====&lt;br /&gt;
&lt;br /&gt;
Here what I have done for my Ubuntu server JEOS 8.04.2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/123/etc/network/if-up.d/ntpdate&lt;br /&gt;
rm /vz/private/123/etc/event.d/tty{1,2,3,4,5,6} &lt;br /&gt;
vzctl exec 123 update-rc.d -f klogd remove&lt;br /&gt;
vzctl exec 123 update-rc.d -f udev remove&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openSUSE/SLES ====&lt;br /&gt;
&lt;br /&gt;
Use Yast.&lt;br /&gt;
&lt;br /&gt;
=== Disable udev if you create DEVNODES devices ===&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;see&amp;quot; the device from within the container it disables it. Therefore, if you have DEVNODES statements in veid.conf then disable udev.&lt;br /&gt;
&lt;br /&gt;
In Fedora, Redhat, Centos, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other adjustments ===&lt;br /&gt;
There might be other adjustments needed. Please add those here (just above this section) if you have more info.&lt;br /&gt;
&lt;br /&gt;
== Starting a new container ==&lt;br /&gt;
&lt;br /&gt;
Try to start your new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl start 123&lt;br /&gt;
&lt;br /&gt;
Now check that everything works fine. If not, see [[#Troubleshooting]] below.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
===PHP not serving pages / random issues===&lt;br /&gt;
&lt;br /&gt;
Make sure that /tmp and /var/tmp are created if you rsynced over your data and that they have proper permissions&lt;br /&gt;
&lt;br /&gt;
 mkdir tmp&lt;br /&gt;
 chmod 1777 tmp&lt;br /&gt;
&lt;br /&gt;
=== Can't enter container ===&lt;br /&gt;
&lt;br /&gt;
If you can not enter your container (using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt;), you should be able to at least execute commands in it.&lt;br /&gt;
&lt;br /&gt;
First, see the [[#tty device nodes]] section above.&lt;br /&gt;
&lt;br /&gt;
Next, check if devpts is mounted:&lt;br /&gt;
 vzctl exec 123 mount | grep pts&lt;br /&gt;
&lt;br /&gt;
If it is not mounted, mount it:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
Then, add the appropriate mount command to container's startup scripts. On some distros, you need to have the appropriate line in container's /etc/fstab.&lt;br /&gt;
&lt;br /&gt;
In Fedora, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
 vi /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Locate the '''udev''' entry from within vim&lt;br /&gt;
 /udev&lt;br /&gt;
Then comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other problems ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Success stories ==&lt;br /&gt;
{{Note|please add your line to the bottom of this list, and do not forget to sign it using &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;--~~~~&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST)&lt;br /&gt;
* Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST)&lt;br /&gt;
* Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST)&lt;br /&gt;
* AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] 16:16, 23 March 2007 (EST)&lt;br /&gt;
* Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] 23:38, 26 February 2008 (EST) &lt;br /&gt;
* Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] 17:35, 10 March 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] 19:46, 10 March 2008 (EST)&lt;br /&gt;
* Debian 1:3.3.5-13 with apache2, PHP, etc. --[[User:Spawrks|spawrks]] 23:36, 10 April 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2, MySQL, etc. --[[User:Zhafrance|zhafrance]] 16:29, 20 April 2008 (EST)&lt;br /&gt;
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)&lt;br /&gt;
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)&lt;br /&gt;
* Centos 4.6 with cPanel/WHM (Apache2, Mysql, Exim, etc) --[[User:Zccopwrx|Zccopwrx]] 08:16, 30 July 2008 (EDT)&lt;br /&gt;
* SlackWare 10.1 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* SlackWare 10.0 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* Ubuntu 8.04.3 LTS JEOS (Apache2, Mysql) --[[User:bougui|bougui]] Fri Aug 28 10:40:41 EDT 2009&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Bougui</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7494</id>
		<title>Physical to container</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7494"/>
		<updated>2009-08-28T18:33:57Z</updated>

		<summary type="html">&lt;p&gt;Bougui: /* Success stories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A rough description of how to migrate existing physical server into a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Preparing to migrate ==&lt;br /&gt;
&lt;br /&gt;
Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not lose your data. Just leave the bare minimum (including ssh daemon).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prepare a new “empty” container ==&lt;br /&gt;
For OpenVZ this would mean the following (assume you chose CT ID of 123):&lt;br /&gt;
&lt;br /&gt;
 mkdir /vz/root/123 /vz/private/123&lt;br /&gt;
 cat /etc/vz/conf/ve-vps.basic.conf-sample &amp;gt; /etc/vz/conf/123.conf&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copying the data ==&lt;br /&gt;
&lt;br /&gt;
Copy all your data from the machine to an OpenVZ box. Say you'll be using container with ID of 123, then all the data should be placed to &amp;lt;code&amp;gt;/vz/private/123/&amp;lt;/code&amp;gt; directory (so there will be directories such as &amp;lt;code&amp;gt;/vz/private/123/bin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;etc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; and so on). This could be done in several ways:&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
rsync example (run from the new HN):&lt;br /&gt;
 rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e &amp;quot;ssh -l root@a.b.c.d&amp;quot; root@a.b.c.d:/ /vz/private/123/&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' Your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
=== Live CD ===&lt;br /&gt;
Another way to do is using a live cd, booting up and use tar to dump the complete disk in a tar you save over the network or on a USB device.&lt;br /&gt;
&lt;br /&gt;
=== Tar ===&lt;br /&gt;
Another approach is using tar and excluding some dirs, you could do it like this:&lt;br /&gt;
&lt;br /&gt;
Create a file /tmp/excludes.excl with these contents:&lt;br /&gt;
 .bash_history&lt;br /&gt;
 /dev/*&lt;br /&gt;
 /mnt/*&lt;br /&gt;
 /tmp/*&lt;br /&gt;
 /proc/*&lt;br /&gt;
 /sys/*&lt;br /&gt;
 /usr/src/*&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
 # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' You don't need to boot from a live cd, so your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
== Setting container parameters ==&lt;br /&gt;
&lt;br /&gt;
=== OSTEMPLATE ===&lt;br /&gt;
You have to add &amp;lt;code&amp;gt;OSTEMPLATE=xxx&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;/etc/vz/conf/123.conf&amp;lt;/code&amp;gt; file, where &amp;lt;code&amp;gt;xxx&amp;lt;/code&amp;gt; would be distribution name (like &amp;lt;code&amp;gt;debian-3.0&amp;lt;/code&amp;gt;) for vzctl to be able to make changes specific for this distribution.&lt;br /&gt;
&lt;br /&gt;
If you copied from the dummy container then this step is already accomplished.&lt;br /&gt;
&lt;br /&gt;
=== IP address(es) ===&lt;br /&gt;
Also, you have to supply an IP for a new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl set 123 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== venet vs. veth ===&lt;br /&gt;
You may use veth interface instead of venet if you need just bring old server up for seamless migration of services.&lt;br /&gt;
It may be nessessary if server you are migrating is badly configured and it is hard to find all hard-coded net interfaces settings and so on.&lt;br /&gt;
&lt;br /&gt;
veth inteface may be included into bridge to allow seamless old installation access.&lt;br /&gt;
&lt;br /&gt;
== Making adjustments ==&lt;br /&gt;
Since container is a bit different to a real physical server, you have to edit some files inside your new container.&lt;br /&gt;
&lt;br /&gt;
=== /etc/inittab ===&lt;br /&gt;
A container does not have real ttys, so you have to disable getty in &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; (i. e. &amp;lt;code&amp;gt;/vz/private/123/etc/inittab&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 sed -i -e '/getty/d' /vz/private/123/etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== /etc/mtab ===&lt;br /&gt;
Link &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, for &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; to work properly:&lt;br /&gt;
&lt;br /&gt;
 rm -f /vz/private/123/etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /vz/private/123/etc/mtab&lt;br /&gt;
&lt;br /&gt;
{{out|The problem here is container's root filesystem (&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;) is mounted not from the container itself, but rather from the host system. That leaves &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; in container without a record for &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; being mounted, thus df doesn't show it. By linking &amp;lt;code&amp;gt;/etc/mtab → /proc/mounts&amp;lt;/code&amp;gt; we make sure /etc/mtab shows what is really mounted in a container.&lt;br /&gt;
&lt;br /&gt;
Sure this is not the only way to fix df; you can just manually add a line to &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; telling &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; is mounted, and make sure this line will be there after a reboot.}}&lt;br /&gt;
&lt;br /&gt;
=== /etc/fstab ===&lt;br /&gt;
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):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 grep devpts /vz/private/123/etc/fstab.old &amp;gt; /vz/private/123/etc/fstab&lt;br /&gt;
&lt;br /&gt;
You can also mount a devpts in a running (but not fully functional) container:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
=== /dev ===&lt;br /&gt;
&lt;br /&gt;
==== Introduction: static /dev ====&lt;br /&gt;
In order for container to work, some nodes should be present in container's &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;. For modern distributions, udev is taking care of it. For a variety of reasons udev doesn't make much sense in a container, so the best thing to do is to disable udev and create needed device nodes manually.&lt;br /&gt;
&lt;br /&gt;
Note that in some distributions &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; — this will not work in case of static &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;. So what you need to do is find out where &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is being mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; and remove this. This is highly distribution-dependent; please add info for your distro here.&lt;br /&gt;
&lt;br /&gt;
For Suse 11.0, It is found in /etc/init.d/boot &lt;br /&gt;
&lt;br /&gt;
After you made sure your &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is static, populate it with needed device nodes.&lt;br /&gt;
&lt;br /&gt;
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by &amp;lt;code&amp;gt;umask&amp;lt;/code&amp;gt; ([[w:umask]]). You can use --mode option for &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to set the desired permissions.&lt;br /&gt;
&lt;br /&gt;
Hint:&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==== tty device nodes ====&lt;br /&gt;
&lt;br /&gt;
In order for vzctl enter to work, a container needs to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.&lt;br /&gt;
&lt;br /&gt;
===== /dev/ptmx =====&lt;br /&gt;
Check that /dev/ptmx exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
===== /dev/pts/ =====&lt;br /&gt;
Check that /dev/pts exists. It's a directory, if it does not exist, create with:&lt;br /&gt;
 mkdir /vz/private/123/dev/pts&lt;br /&gt;
&lt;br /&gt;
===== /dev/ttyp* and /dev/ptyp* =====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To copy:&lt;br /&gt;
 cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/&lt;br /&gt;
&lt;br /&gt;
To recreate with MAKEDEV, either&lt;br /&gt;
 /sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp&lt;br /&gt;
or&lt;br /&gt;
 cd /vz/private/123/dev &amp;amp;&amp;amp; /sbin/MAKEDEV ttyp&lt;br /&gt;
&lt;br /&gt;
====/dev/null====&lt;br /&gt;
Make sure sure /dev/null is not a file or directory; if unsure remove and recreate. If this is not correct sshd will not start correctly.&lt;br /&gt;
 rm -f /vz/private/123/dev/null&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/null c 1 3&lt;br /&gt;
&lt;br /&gt;
==== /dev/urandom ====&lt;br /&gt;
Check that /dev/urandom exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 444 /vz/private/123/dev/urandom c 1 9&lt;br /&gt;
&lt;br /&gt;
===/proc===&lt;br /&gt;
Make sure the /proc directory exists:&lt;br /&gt;
 ls -la /vz/private/123/ | grep proc&lt;br /&gt;
&lt;br /&gt;
If it doesn't, create it:&lt;br /&gt;
 mkdir /vz/private/123/proc&lt;br /&gt;
&lt;br /&gt;
=== /etc/init.d services ===&lt;br /&gt;
&lt;br /&gt;
Some system services can (or in some cases should) be disabled. A few good candidates are:&lt;br /&gt;
&lt;br /&gt;
* acpid, amd (not needed)&lt;br /&gt;
* checkfs, checkroot (no filesystem checking is required in container)&lt;br /&gt;
* clock (no clock setting is required/allowed in container)&lt;br /&gt;
* consolefont (container does not have a console)&lt;br /&gt;
* hdparm (container does not have real hard drives)&lt;br /&gt;
* klogd (unless you use iptables to LOG some packets)&lt;br /&gt;
* keymaps (container does not have a real keyboard)&lt;br /&gt;
* kudzu (container does not have real hardware)&lt;br /&gt;
* lm_sensors (container does not have access to hardware sensors)&lt;br /&gt;
* microcodectl (container can not update CPU microcode)&lt;br /&gt;
* netplugd (container does not have real Ethernet device) &lt;br /&gt;
&lt;br /&gt;
To see which services are enabled:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --list&amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: Use '&amp;lt;code&amp;gt;rcconf&amp;lt;/code&amp;gt;' (ncurses) or &amp;lt;code&amp;gt;update-rc.d&amp;lt;/code&amp;gt;&lt;br /&gt;
( See: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html )&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To disable the service:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --del SERVICENAME  &amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: &amp;lt;code&amp;gt;' update-rc.d -f hdparm remove '&amp;lt;/code&amp;gt;&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update del SERVICENAME&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable old network interface ===&lt;br /&gt;
You should disable your old physical network interface from starting at boot time. This is distribution-dependant.&lt;br /&gt;
&lt;br /&gt;
==== Fedora/CentOS/Red Hat ====&lt;br /&gt;
Edit /vz/private/{CTID}/etc/sysconfig/network-scripts/ifcfg-eth''x''&lt;br /&gt;
&lt;br /&gt;
Make the following look like this:&lt;br /&gt;
 ONBOOT=no&lt;br /&gt;
&lt;br /&gt;
==== Debian/Ubuntu ====&lt;br /&gt;
Edit /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# /etc/network/interfaces -- configuration file for ifup(8),  ifdown(8)&lt;br /&gt;
&lt;br /&gt;
# The loopback interface&lt;br /&gt;
# automatically added when upgrading&lt;br /&gt;
auto lo eth0&lt;br /&gt;
iface lo inet loopback&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet dhcp&lt;br /&gt;
       address 10.0.0.4&lt;br /&gt;
       netmask 255.0.0.0&lt;br /&gt;
       network 10.0.0.0&lt;br /&gt;
       broadcast 10.0.0.255&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can either comment out the eth* interface stanza(s), or take it out of the &amp;quot;auto&amp;quot; line(s).&lt;br /&gt;
&lt;br /&gt;
===== Ubuntu server 8.x =====&lt;br /&gt;
&lt;br /&gt;
Here what I have done for my Ubuntu server JEOS 8.04.2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/root/123/etc/network/if-up.d/ntpdate&lt;br /&gt;
rm rm /vz/root/123/etc/event.d/tty{1,2,3,4,5,6} &lt;br /&gt;
vzctl exec 123 update-rc.d -f klogd remove&lt;br /&gt;
vzctl exec 123 update-rc.d -f udev remove&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openSUSE/SLES ====&lt;br /&gt;
&lt;br /&gt;
Use Yast.&lt;br /&gt;
&lt;br /&gt;
=== Disable udev if you create DEVNODES devices ===&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;see&amp;quot; the device from within the container it disables it. Therefore, if you have DEVNODES statements in veid.conf then disable udev.&lt;br /&gt;
&lt;br /&gt;
In Fedora, Redhat, Centos, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other adjustments ===&lt;br /&gt;
There might be other adjustments needed. Please add those here (just above this section) if you have more info.&lt;br /&gt;
&lt;br /&gt;
== Starting a new container ==&lt;br /&gt;
&lt;br /&gt;
Try to start your new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl start 123&lt;br /&gt;
&lt;br /&gt;
Now check that everything works fine. If not, see [[#Troubleshooting]] below.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
===PHP not serving pages / random issues===&lt;br /&gt;
&lt;br /&gt;
Make sure that /tmp and /var/tmp are created if you rsynced over your data and that they have proper permissions&lt;br /&gt;
&lt;br /&gt;
 mkdir tmp&lt;br /&gt;
 chmod 1777 tmp&lt;br /&gt;
&lt;br /&gt;
=== Can't enter container ===&lt;br /&gt;
&lt;br /&gt;
If you can not enter your container (using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt;), you should be able to at least execute commands in it.&lt;br /&gt;
&lt;br /&gt;
First, see the [[#tty device nodes]] section above.&lt;br /&gt;
&lt;br /&gt;
Next, check if devpts is mounted:&lt;br /&gt;
 vzctl exec 123 mount | grep pts&lt;br /&gt;
&lt;br /&gt;
If it is not mounted, mount it:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
Then, add the appropriate mount command to container's startup scripts. On some distros, you need to have the appropriate line in container's /etc/fstab.&lt;br /&gt;
&lt;br /&gt;
In Fedora, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
 vi /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Locate the '''udev''' entry from within vim&lt;br /&gt;
 /udev&lt;br /&gt;
Then comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other problems ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Success stories ==&lt;br /&gt;
{{Note|please add your line to the bottom of this list, and do not forget to sign it using &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;--~~~~&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST)&lt;br /&gt;
* Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST)&lt;br /&gt;
* Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST)&lt;br /&gt;
* AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] 16:16, 23 March 2007 (EST)&lt;br /&gt;
* Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] 23:38, 26 February 2008 (EST) &lt;br /&gt;
* Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] 17:35, 10 March 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] 19:46, 10 March 2008 (EST)&lt;br /&gt;
* Debian 1:3.3.5-13 with apache2, PHP, etc. --[[User:Spawrks|spawrks]] 23:36, 10 April 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2, MySQL, etc. --[[User:Zhafrance|zhafrance]] 16:29, 20 April 2008 (EST)&lt;br /&gt;
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)&lt;br /&gt;
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)&lt;br /&gt;
* Centos 4.6 with cPanel/WHM (Apache2, Mysql, Exim, etc) --[[User:Zccopwrx|Zccopwrx]] 08:16, 30 July 2008 (EDT)&lt;br /&gt;
* SlackWare 10.1 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* SlackWare 10.0 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* Ubuntu 8.04.3 LTS JEOS (Apache2, Mysql) --[[User:bougui|bougui]] Fri Aug 28 10:40:41 EDT 2009&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Bougui</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7493</id>
		<title>Physical to container</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7493"/>
		<updated>2009-08-28T18:32:32Z</updated>

		<summary type="html">&lt;p&gt;Bougui: /* Success stories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A rough description of how to migrate existing physical server into a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Preparing to migrate ==&lt;br /&gt;
&lt;br /&gt;
Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not lose your data. Just leave the bare minimum (including ssh daemon).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prepare a new “empty” container ==&lt;br /&gt;
For OpenVZ this would mean the following (assume you chose CT ID of 123):&lt;br /&gt;
&lt;br /&gt;
 mkdir /vz/root/123 /vz/private/123&lt;br /&gt;
 cat /etc/vz/conf/ve-vps.basic.conf-sample &amp;gt; /etc/vz/conf/123.conf&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copying the data ==&lt;br /&gt;
&lt;br /&gt;
Copy all your data from the machine to an OpenVZ box. Say you'll be using container with ID of 123, then all the data should be placed to &amp;lt;code&amp;gt;/vz/private/123/&amp;lt;/code&amp;gt; directory (so there will be directories such as &amp;lt;code&amp;gt;/vz/private/123/bin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;etc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; and so on). This could be done in several ways:&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
rsync example (run from the new HN):&lt;br /&gt;
 rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e &amp;quot;ssh -l root@a.b.c.d&amp;quot; root@a.b.c.d:/ /vz/private/123/&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' Your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
=== Live CD ===&lt;br /&gt;
Another way to do is using a live cd, booting up and use tar to dump the complete disk in a tar you save over the network or on a USB device.&lt;br /&gt;
&lt;br /&gt;
=== Tar ===&lt;br /&gt;
Another approach is using tar and excluding some dirs, you could do it like this:&lt;br /&gt;
&lt;br /&gt;
Create a file /tmp/excludes.excl with these contents:&lt;br /&gt;
 .bash_history&lt;br /&gt;
 /dev/*&lt;br /&gt;
 /mnt/*&lt;br /&gt;
 /tmp/*&lt;br /&gt;
 /proc/*&lt;br /&gt;
 /sys/*&lt;br /&gt;
 /usr/src/*&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
 # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' You don't need to boot from a live cd, so your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
== Setting container parameters ==&lt;br /&gt;
&lt;br /&gt;
=== OSTEMPLATE ===&lt;br /&gt;
You have to add &amp;lt;code&amp;gt;OSTEMPLATE=xxx&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;/etc/vz/conf/123.conf&amp;lt;/code&amp;gt; file, where &amp;lt;code&amp;gt;xxx&amp;lt;/code&amp;gt; would be distribution name (like &amp;lt;code&amp;gt;debian-3.0&amp;lt;/code&amp;gt;) for vzctl to be able to make changes specific for this distribution.&lt;br /&gt;
&lt;br /&gt;
If you copied from the dummy container then this step is already accomplished.&lt;br /&gt;
&lt;br /&gt;
=== IP address(es) ===&lt;br /&gt;
Also, you have to supply an IP for a new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl set 123 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== venet vs. veth ===&lt;br /&gt;
You may use veth interface instead of venet if you need just bring old server up for seamless migration of services.&lt;br /&gt;
It may be nessessary if server you are migrating is badly configured and it is hard to find all hard-coded net interfaces settings and so on.&lt;br /&gt;
&lt;br /&gt;
veth inteface may be included into bridge to allow seamless old installation access.&lt;br /&gt;
&lt;br /&gt;
== Making adjustments ==&lt;br /&gt;
Since container is a bit different to a real physical server, you have to edit some files inside your new container.&lt;br /&gt;
&lt;br /&gt;
=== /etc/inittab ===&lt;br /&gt;
A container does not have real ttys, so you have to disable getty in &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; (i. e. &amp;lt;code&amp;gt;/vz/private/123/etc/inittab&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 sed -i -e '/getty/d' /vz/private/123/etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== /etc/mtab ===&lt;br /&gt;
Link &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, for &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; to work properly:&lt;br /&gt;
&lt;br /&gt;
 rm -f /vz/private/123/etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /vz/private/123/etc/mtab&lt;br /&gt;
&lt;br /&gt;
{{out|The problem here is container's root filesystem (&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;) is mounted not from the container itself, but rather from the host system. That leaves &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; in container without a record for &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; being mounted, thus df doesn't show it. By linking &amp;lt;code&amp;gt;/etc/mtab → /proc/mounts&amp;lt;/code&amp;gt; we make sure /etc/mtab shows what is really mounted in a container.&lt;br /&gt;
&lt;br /&gt;
Sure this is not the only way to fix df; you can just manually add a line to &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; telling &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; is mounted, and make sure this line will be there after a reboot.}}&lt;br /&gt;
&lt;br /&gt;
=== /etc/fstab ===&lt;br /&gt;
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):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 grep devpts /vz/private/123/etc/fstab.old &amp;gt; /vz/private/123/etc/fstab&lt;br /&gt;
&lt;br /&gt;
You can also mount a devpts in a running (but not fully functional) container:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
=== /dev ===&lt;br /&gt;
&lt;br /&gt;
==== Introduction: static /dev ====&lt;br /&gt;
In order for container to work, some nodes should be present in container's &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;. For modern distributions, udev is taking care of it. For a variety of reasons udev doesn't make much sense in a container, so the best thing to do is to disable udev and create needed device nodes manually.&lt;br /&gt;
&lt;br /&gt;
Note that in some distributions &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; — this will not work in case of static &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;. So what you need to do is find out where &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is being mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; and remove this. This is highly distribution-dependent; please add info for your distro here.&lt;br /&gt;
&lt;br /&gt;
For Suse 11.0, It is found in /etc/init.d/boot &lt;br /&gt;
&lt;br /&gt;
After you made sure your &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is static, populate it with needed device nodes.&lt;br /&gt;
&lt;br /&gt;
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by &amp;lt;code&amp;gt;umask&amp;lt;/code&amp;gt; ([[w:umask]]). You can use --mode option for &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to set the desired permissions.&lt;br /&gt;
&lt;br /&gt;
Hint:&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==== tty device nodes ====&lt;br /&gt;
&lt;br /&gt;
In order for vzctl enter to work, a container needs to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.&lt;br /&gt;
&lt;br /&gt;
===== /dev/ptmx =====&lt;br /&gt;
Check that /dev/ptmx exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
===== /dev/pts/ =====&lt;br /&gt;
Check that /dev/pts exists. It's a directory, if it does not exist, create with:&lt;br /&gt;
 mkdir /vz/private/123/dev/pts&lt;br /&gt;
&lt;br /&gt;
===== /dev/ttyp* and /dev/ptyp* =====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To copy:&lt;br /&gt;
 cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/&lt;br /&gt;
&lt;br /&gt;
To recreate with MAKEDEV, either&lt;br /&gt;
 /sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp&lt;br /&gt;
or&lt;br /&gt;
 cd /vz/private/123/dev &amp;amp;&amp;amp; /sbin/MAKEDEV ttyp&lt;br /&gt;
&lt;br /&gt;
====/dev/null====&lt;br /&gt;
Make sure sure /dev/null is not a file or directory; if unsure remove and recreate. If this is not correct sshd will not start correctly.&lt;br /&gt;
 rm -f /vz/private/123/dev/null&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/null c 1 3&lt;br /&gt;
&lt;br /&gt;
==== /dev/urandom ====&lt;br /&gt;
Check that /dev/urandom exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 444 /vz/private/123/dev/urandom c 1 9&lt;br /&gt;
&lt;br /&gt;
===/proc===&lt;br /&gt;
Make sure the /proc directory exists:&lt;br /&gt;
 ls -la /vz/private/123/ | grep proc&lt;br /&gt;
&lt;br /&gt;
If it doesn't, create it:&lt;br /&gt;
 mkdir /vz/private/123/proc&lt;br /&gt;
&lt;br /&gt;
=== /etc/init.d services ===&lt;br /&gt;
&lt;br /&gt;
Some system services can (or in some cases should) be disabled. A few good candidates are:&lt;br /&gt;
&lt;br /&gt;
* acpid, amd (not needed)&lt;br /&gt;
* checkfs, checkroot (no filesystem checking is required in container)&lt;br /&gt;
* clock (no clock setting is required/allowed in container)&lt;br /&gt;
* consolefont (container does not have a console)&lt;br /&gt;
* hdparm (container does not have real hard drives)&lt;br /&gt;
* klogd (unless you use iptables to LOG some packets)&lt;br /&gt;
* keymaps (container does not have a real keyboard)&lt;br /&gt;
* kudzu (container does not have real hardware)&lt;br /&gt;
* lm_sensors (container does not have access to hardware sensors)&lt;br /&gt;
* microcodectl (container can not update CPU microcode)&lt;br /&gt;
* netplugd (container does not have real Ethernet device) &lt;br /&gt;
&lt;br /&gt;
To see which services are enabled:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --list&amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: Use '&amp;lt;code&amp;gt;rcconf&amp;lt;/code&amp;gt;' (ncurses) or &amp;lt;code&amp;gt;update-rc.d&amp;lt;/code&amp;gt;&lt;br /&gt;
( See: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html )&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To disable the service:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --del SERVICENAME  &amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: &amp;lt;code&amp;gt;' update-rc.d -f hdparm remove '&amp;lt;/code&amp;gt;&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update del SERVICENAME&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable old network interface ===&lt;br /&gt;
You should disable your old physical network interface from starting at boot time. This is distribution-dependant.&lt;br /&gt;
&lt;br /&gt;
==== Fedora/CentOS/Red Hat ====&lt;br /&gt;
Edit /vz/private/{CTID}/etc/sysconfig/network-scripts/ifcfg-eth''x''&lt;br /&gt;
&lt;br /&gt;
Make the following look like this:&lt;br /&gt;
 ONBOOT=no&lt;br /&gt;
&lt;br /&gt;
==== Debian/Ubuntu ====&lt;br /&gt;
Edit /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# /etc/network/interfaces -- configuration file for ifup(8),  ifdown(8)&lt;br /&gt;
&lt;br /&gt;
# The loopback interface&lt;br /&gt;
# automatically added when upgrading&lt;br /&gt;
auto lo eth0&lt;br /&gt;
iface lo inet loopback&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet dhcp&lt;br /&gt;
       address 10.0.0.4&lt;br /&gt;
       netmask 255.0.0.0&lt;br /&gt;
       network 10.0.0.0&lt;br /&gt;
       broadcast 10.0.0.255&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can either comment out the eth* interface stanza(s), or take it out of the &amp;quot;auto&amp;quot; line(s).&lt;br /&gt;
&lt;br /&gt;
===== Ubuntu server 8.x =====&lt;br /&gt;
&lt;br /&gt;
Here what I have done for my Ubuntu server JEOS 8.04.2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/root/123/etc/network/if-up.d/ntpdate&lt;br /&gt;
rm rm /vz/root/123/etc/event.d/tty{1,2,3,4,5,6} &lt;br /&gt;
vzctl exec 123 update-rc.d -f klogd remove&lt;br /&gt;
vzctl exec 123 update-rc.d -f udev remove&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openSUSE/SLES ====&lt;br /&gt;
&lt;br /&gt;
Use Yast.&lt;br /&gt;
&lt;br /&gt;
=== Disable udev if you create DEVNODES devices ===&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;see&amp;quot; the device from within the container it disables it. Therefore, if you have DEVNODES statements in veid.conf then disable udev.&lt;br /&gt;
&lt;br /&gt;
In Fedora, Redhat, Centos, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other adjustments ===&lt;br /&gt;
There might be other adjustments needed. Please add those here (just above this section) if you have more info.&lt;br /&gt;
&lt;br /&gt;
== Starting a new container ==&lt;br /&gt;
&lt;br /&gt;
Try to start your new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl start 123&lt;br /&gt;
&lt;br /&gt;
Now check that everything works fine. If not, see [[#Troubleshooting]] below.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
===PHP not serving pages / random issues===&lt;br /&gt;
&lt;br /&gt;
Make sure that /tmp and /var/tmp are created if you rsynced over your data and that they have proper permissions&lt;br /&gt;
&lt;br /&gt;
 mkdir tmp&lt;br /&gt;
 chmod 1777 tmp&lt;br /&gt;
&lt;br /&gt;
=== Can't enter container ===&lt;br /&gt;
&lt;br /&gt;
If you can not enter your container (using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt;), you should be able to at least execute commands in it.&lt;br /&gt;
&lt;br /&gt;
First, see the [[#tty device nodes]] section above.&lt;br /&gt;
&lt;br /&gt;
Next, check if devpts is mounted:&lt;br /&gt;
 vzctl exec 123 mount | grep pts&lt;br /&gt;
&lt;br /&gt;
If it is not mounted, mount it:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
Then, add the appropriate mount command to container's startup scripts. On some distros, you need to have the appropriate line in container's /etc/fstab.&lt;br /&gt;
&lt;br /&gt;
In Fedora, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
 vi /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Locate the '''udev''' entry from within vim&lt;br /&gt;
 /udev&lt;br /&gt;
Then comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other problems ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Success stories ==&lt;br /&gt;
{{Note|please add your line to the bottom of this list, and do not forget to sign it using &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;--~~~~&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST)&lt;br /&gt;
* Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST)&lt;br /&gt;
* Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST)&lt;br /&gt;
* AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] 16:16, 23 March 2007 (EST)&lt;br /&gt;
* Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] 23:38, 26 February 2008 (EST) &lt;br /&gt;
* Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] 17:35, 10 March 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] 19:46, 10 March 2008 (EST)&lt;br /&gt;
* Debian 1:3.3.5-13 with apache2, PHP, etc. --[[User:Spawrks|spawrks]] 23:36, 10 April 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2, MySQL, etc. --[[User:Zhafrance|zhafrance]] 16:29, 20 April 2008 (EST)&lt;br /&gt;
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)&lt;br /&gt;
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)&lt;br /&gt;
* Centos 4.6 with cPanel/WHM (Apache2, Mysql, Exim, etc) --[[User:Zccopwrx|Zccopwrx]] 08:16, 30 July 2008 (EDT)&lt;br /&gt;
* SlackWare 10.1 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* SlackWare 10.0 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* Ubuntu JEOS (Apache2, Mysql) --[[User:bougui|bouguil]] Fri Aug 28 10:40:41 EDT 2009&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Bougui</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7492</id>
		<title>Physical to container</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=7492"/>
		<updated>2009-08-28T15:26:38Z</updated>

		<summary type="html">&lt;p&gt;Bougui: /* Debian/Ubuntu */  add specifi ubuntu server info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A rough description of how to migrate existing physical server into a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Preparing to migrate ==&lt;br /&gt;
&lt;br /&gt;
Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not lose your data. Just leave the bare minimum (including ssh daemon).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prepare a new “empty” container ==&lt;br /&gt;
For OpenVZ this would mean the following (assume you chose CT ID of 123):&lt;br /&gt;
&lt;br /&gt;
 mkdir /vz/root/123 /vz/private/123&lt;br /&gt;
 cat /etc/vz/conf/ve-vps.basic.conf-sample &amp;gt; /etc/vz/conf/123.conf&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copying the data ==&lt;br /&gt;
&lt;br /&gt;
Copy all your data from the machine to an OpenVZ box. Say you'll be using container with ID of 123, then all the data should be placed to &amp;lt;code&amp;gt;/vz/private/123/&amp;lt;/code&amp;gt; directory (so there will be directories such as &amp;lt;code&amp;gt;/vz/private/123/bin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;etc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; and so on). This could be done in several ways:&lt;br /&gt;
&lt;br /&gt;
=== rsync ===&lt;br /&gt;
rsync example (run from the new HN):&lt;br /&gt;
 rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e &amp;quot;ssh -l root@a.b.c.d&amp;quot; root@a.b.c.d:/ /vz/private/123/&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' Your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
=== Live CD ===&lt;br /&gt;
Another way to do is using a live cd, booting up and use tar to dump the complete disk in a tar you save over the network or on a USB device.&lt;br /&gt;
&lt;br /&gt;
=== Tar ===&lt;br /&gt;
Another approach is using tar and excluding some dirs, you could do it like this:&lt;br /&gt;
&lt;br /&gt;
Create a file /tmp/excludes.excl with these contents:&lt;br /&gt;
 .bash_history&lt;br /&gt;
 /dev/*&lt;br /&gt;
 /mnt/*&lt;br /&gt;
 /tmp/*&lt;br /&gt;
 /proc/*&lt;br /&gt;
 /sys/*&lt;br /&gt;
 /usr/src/*&lt;br /&gt;
&lt;br /&gt;
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)&lt;br /&gt;
&lt;br /&gt;
 # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
'''Advantage:''' You don't need to boot from a live cd, so your system doesn't really go down.&lt;br /&gt;
&lt;br /&gt;
== Setting container parameters ==&lt;br /&gt;
&lt;br /&gt;
=== OSTEMPLATE ===&lt;br /&gt;
You have to add &amp;lt;code&amp;gt;OSTEMPLATE=xxx&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;/etc/vz/conf/123.conf&amp;lt;/code&amp;gt; file, where &amp;lt;code&amp;gt;xxx&amp;lt;/code&amp;gt; would be distribution name (like &amp;lt;code&amp;gt;debian-3.0&amp;lt;/code&amp;gt;) for vzctl to be able to make changes specific for this distribution.&lt;br /&gt;
&lt;br /&gt;
If you copied from the dummy container then this step is already accomplished.&lt;br /&gt;
&lt;br /&gt;
=== IP address(es) ===&lt;br /&gt;
Also, you have to supply an IP for a new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl set 123 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== venet vs. veth ===&lt;br /&gt;
You may use veth interface instead of venet if you need just bring old server up for seamless migration of services.&lt;br /&gt;
It may be nessessary if server you are migrating is badly configured and it is hard to find all hard-coded net interfaces settings and so on.&lt;br /&gt;
&lt;br /&gt;
veth inteface may be included into bridge to allow seamless old installation access.&lt;br /&gt;
&lt;br /&gt;
== Making adjustments ==&lt;br /&gt;
Since container is a bit different to a real physical server, you have to edit some files inside your new container.&lt;br /&gt;
&lt;br /&gt;
=== /etc/inittab ===&lt;br /&gt;
A container does not have real ttys, so you have to disable getty in &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; (i. e. &amp;lt;code&amp;gt;/vz/private/123/etc/inittab&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 sed -i -e '/getty/d' /vz/private/123/etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== /etc/mtab ===&lt;br /&gt;
Link &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, for &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; to work properly:&lt;br /&gt;
&lt;br /&gt;
 rm -f /vz/private/123/etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /vz/private/123/etc/mtab&lt;br /&gt;
&lt;br /&gt;
{{out|The problem here is container's root filesystem (&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;) is mounted not from the container itself, but rather from the host system. That leaves &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; in container without a record for &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; being mounted, thus df doesn't show it. By linking &amp;lt;code&amp;gt;/etc/mtab → /proc/mounts&amp;lt;/code&amp;gt; we make sure /etc/mtab shows what is really mounted in a container.&lt;br /&gt;
&lt;br /&gt;
Sure this is not the only way to fix df; you can just manually add a line to &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; telling &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; is mounted, and make sure this line will be there after a reboot.}}&lt;br /&gt;
&lt;br /&gt;
=== /etc/fstab ===&lt;br /&gt;
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):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 grep devpts /vz/private/123/etc/fstab.old &amp;gt; /vz/private/123/etc/fstab&lt;br /&gt;
&lt;br /&gt;
You can also mount a devpts in a running (but not fully functional) container:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
=== /dev ===&lt;br /&gt;
&lt;br /&gt;
==== Introduction: static /dev ====&lt;br /&gt;
In order for container to work, some nodes should be present in container's &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;. For modern distributions, udev is taking care of it. For a variety of reasons udev doesn't make much sense in a container, so the best thing to do is to disable udev and create needed device nodes manually.&lt;br /&gt;
&lt;br /&gt;
Note that in some distributions &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; — this will not work in case of static &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt;. So what you need to do is find out where &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is being mounted on &amp;lt;code&amp;gt;tmpfs&amp;lt;/code&amp;gt; and remove this. This is highly distribution-dependent; please add info for your distro here.&lt;br /&gt;
&lt;br /&gt;
For Suse 11.0, It is found in /etc/init.d/boot &lt;br /&gt;
&lt;br /&gt;
After you made sure your &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; is static, populate it with needed device nodes.&lt;br /&gt;
&lt;br /&gt;
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by &amp;lt;code&amp;gt;umask&amp;lt;/code&amp;gt; ([[w:umask]]). You can use --mode option for &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to set the desired permissions.&lt;br /&gt;
&lt;br /&gt;
Hint:&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==== tty device nodes ====&lt;br /&gt;
&lt;br /&gt;
In order for vzctl enter to work, a container needs to have some entries in /dev. This can either be /dev/ttyp* and /dev/ptyp*, or /dev/ptmx and mounted /dev/pts.&lt;br /&gt;
&lt;br /&gt;
===== /dev/ptmx =====&lt;br /&gt;
Check that /dev/ptmx exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
===== /dev/pts/ =====&lt;br /&gt;
Check that /dev/pts exists. It's a directory, if it does not exist, create with:&lt;br /&gt;
 mkdir /vz/private/123/dev/pts&lt;br /&gt;
&lt;br /&gt;
===== /dev/ttyp* and /dev/ptyp* =====&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To copy:&lt;br /&gt;
 cp -a /dev/ttyp* /dev/ptyp* /vz/private/123/dev/&lt;br /&gt;
&lt;br /&gt;
To recreate with MAKEDEV, either&lt;br /&gt;
 /sbin/MAKEDEV -d /vz/private/123/dev ttyp ptyp&lt;br /&gt;
or&lt;br /&gt;
 cd /vz/private/123/dev &amp;amp;&amp;amp; /sbin/MAKEDEV ttyp&lt;br /&gt;
&lt;br /&gt;
====/dev/null====&lt;br /&gt;
Make sure sure /dev/null is not a file or directory; if unsure remove and recreate. If this is not correct sshd will not start correctly.&lt;br /&gt;
 rm -f /vz/private/123/dev/null&lt;br /&gt;
 mknod --mode 666 /vz/private/123/dev/null c 1 3&lt;br /&gt;
&lt;br /&gt;
==== /dev/urandom ====&lt;br /&gt;
Check that /dev/urandom exists. If it does not, create with:&lt;br /&gt;
 mknod --mode 444 /vz/private/123/dev/urandom c 1 9&lt;br /&gt;
&lt;br /&gt;
===/proc===&lt;br /&gt;
Make sure the /proc directory exists:&lt;br /&gt;
 ls -la /vz/private/123/ | grep proc&lt;br /&gt;
&lt;br /&gt;
If it doesn't, create it:&lt;br /&gt;
 mkdir /vz/private/123/proc&lt;br /&gt;
&lt;br /&gt;
=== /etc/init.d services ===&lt;br /&gt;
&lt;br /&gt;
Some system services can (or in some cases should) be disabled. A few good candidates are:&lt;br /&gt;
&lt;br /&gt;
* acpid, amd (not needed)&lt;br /&gt;
* checkfs, checkroot (no filesystem checking is required in container)&lt;br /&gt;
* clock (no clock setting is required/allowed in container)&lt;br /&gt;
* consolefont (container does not have a console)&lt;br /&gt;
* hdparm (container does not have real hard drives)&lt;br /&gt;
* klogd (unless you use iptables to LOG some packets)&lt;br /&gt;
* keymaps (container does not have a real keyboard)&lt;br /&gt;
* kudzu (container does not have real hardware)&lt;br /&gt;
* lm_sensors (container does not have access to hardware sensors)&lt;br /&gt;
* microcodectl (container can not update CPU microcode)&lt;br /&gt;
* netplugd (container does not have real Ethernet device) &lt;br /&gt;
&lt;br /&gt;
To see which services are enabled:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --list&amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: Use '&amp;lt;code&amp;gt;rcconf&amp;lt;/code&amp;gt;' (ncurses) or &amp;lt;code&amp;gt;update-rc.d&amp;lt;/code&amp;gt;&lt;br /&gt;
( See: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html )&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To disable the service:&lt;br /&gt;
* RedHat/Fedora/SUSE: &amp;lt;code&amp;gt;/sbin/chkconfig --del SERVICENAME  &amp;lt;/code&amp;gt;&lt;br /&gt;
* Debian: &amp;lt;code&amp;gt;' update-rc.d -f hdparm remove '&amp;lt;/code&amp;gt;&lt;br /&gt;
* Gentoo: &amp;lt;code&amp;gt;/sbin/rc-update del SERVICENAME&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disable old network interface ===&lt;br /&gt;
You should disable your old physical network interface from starting at boot time. This is distribution-dependant.&lt;br /&gt;
&lt;br /&gt;
==== Fedora/CentOS/Red Hat ====&lt;br /&gt;
Edit /vz/private/{CTID}/etc/sysconfig/network-scripts/ifcfg-eth''x''&lt;br /&gt;
&lt;br /&gt;
Make the following look like this:&lt;br /&gt;
 ONBOOT=no&lt;br /&gt;
&lt;br /&gt;
==== Debian/Ubuntu ====&lt;br /&gt;
Edit /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# /etc/network/interfaces -- configuration file for ifup(8),  ifdown(8)&lt;br /&gt;
&lt;br /&gt;
# The loopback interface&lt;br /&gt;
# automatically added when upgrading&lt;br /&gt;
auto lo eth0&lt;br /&gt;
iface lo inet loopback&lt;br /&gt;
&lt;br /&gt;
iface eth0 inet dhcp&lt;br /&gt;
       address 10.0.0.4&lt;br /&gt;
       netmask 255.0.0.0&lt;br /&gt;
       network 10.0.0.0&lt;br /&gt;
       broadcast 10.0.0.255&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can either comment out the eth* interface stanza(s), or take it out of the &amp;quot;auto&amp;quot; line(s).&lt;br /&gt;
&lt;br /&gt;
===== Ubuntu server 8.x =====&lt;br /&gt;
&lt;br /&gt;
Here what I have done for my Ubuntu server JEOS 8.04.2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/root/123/etc/network/if-up.d/ntpdate&lt;br /&gt;
rm rm /vz/root/123/etc/event.d/tty{1,2,3,4,5,6} &lt;br /&gt;
vzctl exec 123 update-rc.d -f klogd remove&lt;br /&gt;
vzctl exec 123 update-rc.d -f udev remove&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openSUSE/SLES ====&lt;br /&gt;
&lt;br /&gt;
Use Yast.&lt;br /&gt;
&lt;br /&gt;
=== Disable udev if you create DEVNODES devices ===&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;see&amp;quot; the device from within the container it disables it. Therefore, if you have DEVNODES statements in veid.conf then disable udev.&lt;br /&gt;
&lt;br /&gt;
In Fedora, Redhat, Centos, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other adjustments ===&lt;br /&gt;
There might be other adjustments needed. Please add those here (just above this section) if you have more info.&lt;br /&gt;
&lt;br /&gt;
== Starting a new container ==&lt;br /&gt;
&lt;br /&gt;
Try to start your new container:&lt;br /&gt;
 &lt;br /&gt;
 vzctl start 123&lt;br /&gt;
&lt;br /&gt;
Now check that everything works fine. If not, see [[#Troubleshooting]] below.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
===PHP not serving pages / random issues===&lt;br /&gt;
&lt;br /&gt;
Make sure that /tmp and /var/tmp are created if you rsynced over your data and that they have proper permissions&lt;br /&gt;
&lt;br /&gt;
 mkdir tmp&lt;br /&gt;
 chmod 1777 tmp&lt;br /&gt;
&lt;br /&gt;
=== Can't enter container ===&lt;br /&gt;
&lt;br /&gt;
If you can not enter your container (using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt;), you should be able to at least execute commands in it.&lt;br /&gt;
&lt;br /&gt;
First, see the [[#tty device nodes]] section above.&lt;br /&gt;
&lt;br /&gt;
Next, check if devpts is mounted:&lt;br /&gt;
 vzctl exec 123 mount | grep pts&lt;br /&gt;
&lt;br /&gt;
If it is not mounted, mount it:&lt;br /&gt;
 vzctl exec 123 mount -t devpts none /dev/pts&lt;br /&gt;
&lt;br /&gt;
Then, add the appropriate mount command to container's startup scripts. On some distros, you need to have the appropriate line in container's /etc/fstab.&lt;br /&gt;
&lt;br /&gt;
In Fedora, try commenting out any '''udev''' entries in /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
 vi /vz/private/{CTID}/etc/rc.sysinit&lt;br /&gt;
Locate the '''udev''' entry from within vim&lt;br /&gt;
 /udev&lt;br /&gt;
Then comment the line similar to this:&lt;br /&gt;
 #[ -x /sbin/start_udev ] &amp;amp;&amp;amp; /sbin/start_udev&lt;br /&gt;
&lt;br /&gt;
=== Other problems ===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Success stories ==&lt;br /&gt;
{{Note|please add your line to the bottom of this list, and do not forget to sign it using &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;--~~~~&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST)&lt;br /&gt;
* Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST)&lt;br /&gt;
* Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST)&lt;br /&gt;
* AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] 16:16, 23 March 2007 (EST)&lt;br /&gt;
* Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] 23:38, 26 February 2008 (EST) &lt;br /&gt;
* Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] 17:35, 10 March 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] 19:46, 10 March 2008 (EST)&lt;br /&gt;
* Debian 1:3.3.5-13 with apache2, PHP, etc. --[[User:Spawrks|spawrks]] 23:36, 10 April 2008 (EST)&lt;br /&gt;
* Debian Etch with apache2, MySQL, etc. --[[User:Zhafrance|zhafrance]] 16:29, 20 April 2008 (EST)&lt;br /&gt;
* Debian Etch i386 with apache2, MySQL, etc. --[[User:geejay|geejay]] 17:29, 26 May 2008 (GMT)&lt;br /&gt;
* Centos 4.6 with apache2, MySQL, Qmail etc. --[[User:Bharathchari|Bharathchari]] 08:06, 13 June 2008 (EDT)&lt;br /&gt;
* Centos 4.6 with cPanel/WHM (Apache2, Mysql, Exim, etc) --[[User:Zccopwrx|Zccopwrx]] 08:16, 30 July 2008 (EDT)&lt;br /&gt;
* SlackWare 10.1 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
* SlackWare 10.0 (Qmail) --[[User:defiancenl|defiancenl]]&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>Bougui</name></author>
		
	</entry>
</feed>