<?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=TimSmall</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=TimSmall"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/TimSmall"/>
	<updated>2026-06-10T02:01:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13905</id>
		<title>Debian template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13905"/>
		<updated>2013-06-23T20:24:43Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* Preparing for and packing template cache */ Use system default editor (whatever that's been set to) instead of insisting on nano (!)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are rough instructions of how to manually create basic Debian template cache, which can be used to create OpenVZ [[VE]]s based on Debian. &lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
* You shouldn't be running as root, but as a user that is permitted to use sudo instead.  It's a dangerous idea, run as root at your peril.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;/vz&amp;lt;/tt&amp;gt;, you might really need to use &amp;lt;tt&amp;gt;/var/lib/vz&amp;lt;/tt&amp;gt; instead, especially on a Debian Etch host.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;http://http.us.debian.org/debian/&amp;lt;/tt&amp;gt;, you can substitute your favorite Debian mirror.  ([http://www.debian.org/mirror/list List of official Debian Mirrors])&lt;br /&gt;
* See also: &amp;lt;tt&amp;gt;/usr/share/doc/vzctl/README.Debian&amp;lt;/tt&amp;gt; in the ''vzctl'' Debian package&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|if you want to use &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; file system for &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, use &amp;lt;code&amp;gt;nodelalloc&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;, otherwise it will crash. See {{Bug|1509}} and its duplicates for details.}}&lt;br /&gt;
&lt;br /&gt;
You need to have a working copy of &amp;lt;tt&amp;gt;debootstrap&amp;lt;/tt&amp;gt; running on your hardware node.&lt;br /&gt;
&lt;br /&gt;
For Debian:&lt;br /&gt;
 sudo apt-get install debootstrap&lt;br /&gt;
&lt;br /&gt;
For Gentoo:&lt;br /&gt;
 sudo emerge debootstrap&lt;br /&gt;
&lt;br /&gt;
For Fedora (at least Fedora 8 have it, not sure about earlier versions):&lt;br /&gt;
 sudo yum install debootstrap&lt;br /&gt;
&lt;br /&gt;
For other distros you might need to install it from sources, or search for an appropriate package for your distribution.  An RPM is available on the [http://forum.openvz.org/index.php?t=tree&amp;amp;th=142&amp;amp;mid=584 OpenVZ Forum].&lt;br /&gt;
&lt;br /&gt;
== Bootstrapping Debian ==&lt;br /&gt;
&lt;br /&gt;
You can install different releases of Debian into a VE's private directory using the debootstrap command.&lt;br /&gt;
&lt;br /&gt;
The command parameters are:&lt;br /&gt;
&lt;br /&gt;
  debootstrap --arch ARCH NAME DIRECTORY URL&lt;br /&gt;
&lt;br /&gt;
Specify your architecture instead of &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; if you're using something other than i386/x86.  For example, for AMD64/x86_64, use &amp;lt;tt&amp;gt;amd64&amp;lt;/tt&amp;gt; or for ia64, use &amp;lt;tt&amp;gt;ia64&amp;lt;/tt&amp;gt;. You can use http or ftp in the URL.&lt;br /&gt;
&lt;br /&gt;
We use VE ID of 777 for this example, but it can be any unused ID.&lt;br /&gt;
&lt;br /&gt;
=== Wheezy (current stable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 wheezy /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 wheezy /vz/private/777 http://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Squeeze (current oldstable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 squeeze /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 squeeze /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Lenny (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 lenny /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 lenny /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Etch (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 etch /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Sarge (very old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap sarge /vz/private/777 http://archive.debian.org/debian&lt;br /&gt;
&lt;br /&gt;
== Preparing the HN network ==&lt;br /&gt;
Append the following lines to /etc/sysctl.conf, adjust to taste and then execute &amp;quot;sysctl -p&amp;quot; for them to take effect.&lt;br /&gt;
 ### OpenVZ settings&lt;br /&gt;
 &lt;br /&gt;
 # On Hardware Node enable packet forwarding to forward&lt;br /&gt;
 # packets between the HN network interfaces and venet.&lt;br /&gt;
 # Proxy arp is needed when CT is in a different subnet&lt;br /&gt;
 # or when using veth AND veth is not bridged to a HN&lt;br /&gt;
 # interface. When veth is bridged to a HN interface,&lt;br /&gt;
 # the CT handles its own arps.&lt;br /&gt;
 &lt;br /&gt;
 net.ipv4.conf.default.forwarding=1&lt;br /&gt;
 net.ipv4.conf.default.proxy_arp = 0&lt;br /&gt;
 net.ipv4.ip_forward=1&lt;br /&gt;
 &lt;br /&gt;
 # Enables source route verification&lt;br /&gt;
 net.ipv4.conf.all.rp_filter = 1&lt;br /&gt;
 &lt;br /&gt;
 # Enables the magic-sysrq key&lt;br /&gt;
 kernel.sysrq = 1&lt;br /&gt;
 &lt;br /&gt;
 # TCP Explict Congestion Notification&lt;br /&gt;
 net.ipv4.tcp_ecn = 0&lt;br /&gt;
 &lt;br /&gt;
 # we do not want all our interfaces to send redirects&lt;br /&gt;
 net.ipv4.conf.default.send_redirects = 1&lt;br /&gt;
 net.ipv4.conf.all.send_redirects = 0&lt;br /&gt;
&lt;br /&gt;
== Preparing and starting the VE ==&lt;br /&gt;
&lt;br /&gt;
=== Setting VE config ===&lt;br /&gt;
First, we need a config for the [[VE]]:&lt;br /&gt;
 sudo vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&lt;br /&gt;
On debian squeeze only the following worked for me (''confirmed''), because the standard template names in /etc/vz/conf have changed.&lt;br /&gt;
 sudo vzctl set 777 --applyconfig basic --save&lt;br /&gt;
&lt;br /&gt;
=== Setting VE OSTEMPLATE ===&lt;br /&gt;
Also, we need &amp;lt;tt&amp;gt;OSTEMPLATE&amp;lt;/tt&amp;gt; to be set in VE configuration file, for [[vzctl]] to work properly.&lt;br /&gt;
&lt;br /&gt;
 sudo sh -c 'echo OSTEMPLATE=\&amp;quot;debian-6.0\&amp;quot;' &amp;gt;&amp;gt; /etc/vz/conf/777.conf&lt;br /&gt;
&lt;br /&gt;
=== Setting VE IP address ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it:&lt;br /&gt;
 sudo vzctl set 777 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
{{Note|if you use private IP for the VE, you might have to set up NAT as described in [[Using NAT for VE with private IPs]].}}&lt;br /&gt;
&lt;br /&gt;
=== Setting DNS server for VE ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it:&lt;br /&gt;
 sudo vzctl set 777 --nameserver x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== Creating /dev/ptmx  ===&lt;br /&gt;
The ptmx character device should normally exist, but if it doesn't, create one.&lt;br /&gt;
 sudo mknod --mode 666 /var/lib/vz/private/777/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
=== Starting VE ===&lt;br /&gt;
Now start the VE:&lt;br /&gt;
 sudo vzctl start 777&lt;br /&gt;
&lt;br /&gt;
== Customizing the installation ==&lt;br /&gt;
A few things need to be done inside a newly created VE for it to become suitable for OpenVZ. Enter the VE to begin the configuration (note: if running a wheezy container on a squeeze hardware node, you'll need to manually install a newer version of vzctl (the one from wheezy will be fine - http://packages.debian.org/wheezy/vzctl) due to this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683454 - without making this change, the enter command will hang). Exporting the path is optional.&lt;br /&gt;
 sudo vzctl enter 777&lt;br /&gt;
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}}&lt;br /&gt;
&lt;br /&gt;
=== Set Debian repositories ===&lt;br /&gt;
The list shown is for wheezy, and downloading from US located servers - adjust your release name and mirror location as necessary&lt;br /&gt;
 cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apt/sources.list&lt;br /&gt;
 deb http://http.us.debian.org/debian wheezy main contrib&lt;br /&gt;
 deb http://security.debian.org wheezy/updates main contrib&lt;br /&gt;
 deb http://http.us.debian.org/debian wheezy-updates main&lt;br /&gt;
 ## backports - ONLY IF YOU KNOW WHAT YOU DO&lt;br /&gt;
 # deb http://http.us.debian.org/debian-backports/ wheezy-backports main&lt;br /&gt;
 EOF&lt;br /&gt;
&lt;br /&gt;
=== Get new security updates ===&lt;br /&gt;
 apt-get update&lt;br /&gt;
 apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
=== Install some more packages ===&lt;br /&gt;
Installing packages could be an interactive process so the system might ask some questions.  You can install more packages if you'd like.  For example:&lt;br /&gt;
 apt-get install ssh quota less&lt;br /&gt;
&lt;br /&gt;
=== Set sane permissions for &amp;lt;tt&amp;gt;/root&amp;lt;/tt&amp;gt; directory ===&lt;br /&gt;
 chmod 700 /root&lt;br /&gt;
&lt;br /&gt;
=== Disable root login ===&lt;br /&gt;
This will disable root login by default.&lt;br /&gt;
 usermod -L root&lt;br /&gt;
&lt;br /&gt;
=== Disable getty ===&lt;br /&gt;
Disable running &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt;s on terminals as a VE does not have any:&lt;br /&gt;
 sed -i -e '/getty/d' /etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== Disable &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; for syslog ===&lt;br /&gt;
Turn off doing &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; on every write for &amp;lt;tt&amp;gt;syslog&amp;lt;/tt&amp;gt;'s log files, to improve I/O performance:&lt;br /&gt;
 &amp;lt;pre&amp;gt;sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/*syslog.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Link &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;/proc/mounts&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt; and friends will work:&lt;br /&gt;
 rm -f /etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
=== Remove some unneeded packages ===&lt;br /&gt;
If you have any packages you'd like to remove, now's the time for it.  Here's an example — note that not all of those packages are installed by default in Debian Squeeze (although they were in earlier versions):&lt;br /&gt;
 dpkg --purge modutils ppp pppoeconf pppoe pppconfig module-init-tools&lt;br /&gt;
&lt;br /&gt;
=== Disable services ===&lt;br /&gt;
Do not start some services, stick to bare minimum:&lt;br /&gt;
 update-rc.d -f klogd remove&lt;br /&gt;
 update-rc.d -f quotarpc remove&lt;br /&gt;
 update-rc.d -f exim4 remove&lt;br /&gt;
 update-rc.d -f inetd remove&lt;br /&gt;
&lt;br /&gt;
For dependency-based boot sequence introduced with Squeeze type:&lt;br /&gt;
&lt;br /&gt;
 update-rc.d-insserv -f klogd remove&lt;br /&gt;
 update-rc.d-insserv -f quotarpc remove&lt;br /&gt;
 update-rc.d-insserv -f exim4 remove&lt;br /&gt;
 update-rc.d-insserv -f inetd remove&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys ===&lt;br /&gt;
This is only useful if you installed SSH.  Each individual [[VE]] should have its own pair of SSH host keys.  The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|This will not work using the dependency-based boot sequence introduced with Squeeze. See the section below. }}&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys in Squeeze when using dependency-based booting ===&lt;br /&gt;
&lt;br /&gt;
 rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          Generates new ssh host keys on first boot&lt;br /&gt;
# Required-Start:    $remote_fs $syslog&lt;br /&gt;
# Required-Stop:     $remote_fs $syslog&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:&lt;br /&gt;
# Short-Description: Generates new ssh host keys on first boot&lt;br /&gt;
# Description:       Generates new ssh host keys on first boot&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N &amp;quot;&amp;quot;&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N &amp;quot;&amp;quot;&lt;br /&gt;
insserv -r /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 chmod a+x /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
 insserv /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
&lt;br /&gt;
=== Change timezone ===&lt;br /&gt;
&lt;br /&gt;
You might want to change timezone if you do not live in $UTC. The following example is for Germany&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or even better&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dpkg-reconfigure tzdata&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clean packages ===&lt;br /&gt;
After installing packages, you'll have some junk packages laying around in your cache.  Since you don't want your template to have those, this command will wipe them out.&lt;br /&gt;
 apt-get --purge clean&lt;br /&gt;
&lt;br /&gt;
Now everything is done.  Exit from the template and go back to the hardware node.&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
== Preparing for and packing template cache ==&lt;br /&gt;
&lt;br /&gt;
We don't need an IP for the VE anymore, and we definitely do not need it in template cache, so remove it:&lt;br /&gt;
 sudo vzctl set 777 --ipdel all --save&lt;br /&gt;
&lt;br /&gt;
Also, remove DNS server and search domain information from ''/etc/resolv.conf'' file '''in VE''':&lt;br /&gt;
 sudo editor /vz/private/777/etc/resolv.conf&lt;br /&gt;
&lt;br /&gt;
Also, remove ''/etc/hostname'' file '''in VE''':&lt;br /&gt;
 sudo rm -f /vz/private/777/etc/hostname&lt;br /&gt;
&lt;br /&gt;
Stop the VE:&lt;br /&gt;
 sudo vzctl stop 777&lt;br /&gt;
&lt;br /&gt;
Go to the VE directory:&lt;br /&gt;
 cd /vz/private/777&lt;br /&gt;
&lt;br /&gt;
Now create a cached OS tarball.  In the command below, you'll want to replace &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; with your architecture (i386, amd64, ia64, etc).&lt;br /&gt;
 sudo tar --numeric-owner -zcf /vz/template/cache/debian-5.0-i386-minimal.tar.gz .&lt;br /&gt;
&lt;br /&gt;
Look at the resulting tarball to see its size is sane:&lt;br /&gt;
 # ls -lh /vz/template/cache&lt;br /&gt;
 -rw-r--r--  1 root root  51M Apr 10 03:16 debian-5.0-i386-minimal.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Checking if template cache works ==&lt;br /&gt;
We can now create a VE based on the just-created template cache.  Be sure to change &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; to your architecture just like you did when you named the tarball above.&lt;br /&gt;
 sudo vzctl create 123456 --ostemplate debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
Now make sure that it works:&lt;br /&gt;
 sudo vzctl start 123456&lt;br /&gt;
 sudo vzctl exec 123456 ps ax&lt;br /&gt;
&lt;br /&gt;
You should see that a few processes are running.&lt;br /&gt;
&lt;br /&gt;
== Final cleanup ==&lt;br /&gt;
Stop and remove the test VE you just created:&lt;br /&gt;
 sudo vzctl stop 123456&lt;br /&gt;
 sudo vzctl destroy 123456&lt;br /&gt;
 sudo rm /etc/vz/conf/123456.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
Finally, let's remove the VE we used for OS template cache creation:&lt;br /&gt;
 sudo vzctl destroy 777&lt;br /&gt;
 sudo rm /etc/vz/conf/777.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
You might want to edit /etc/vz/vz.conf and change DEF_OSTEMPLATE to the name of the template you use most often so that you don't have to specify the template when creating a VE.&lt;br /&gt;
 DEF_OSTEMPLATE=&amp;quot;debian-6.0-i386-minimal&amp;quot;&lt;br /&gt;
If you use iptables, you might want to include additional modules in the list for IPTABLES in /etc/vz/vz.conf. See ''man vzctl'' for a list of available modules.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Debian]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13904</id>
		<title>Debian template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13904"/>
		<updated>2013-06-23T20:12:29Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* Set up Debian repositories */ Add note re release name and mirror customisation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are rough instructions of how to manually create basic Debian template cache, which can be used to create OpenVZ [[VE]]s based on Debian. &lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
* You shouldn't be running as root, but as a user that is permitted to use sudo instead.  It's a dangerous idea, run as root at your peril.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;/vz&amp;lt;/tt&amp;gt;, you might really need to use &amp;lt;tt&amp;gt;/var/lib/vz&amp;lt;/tt&amp;gt; instead, especially on a Debian Etch host.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;http://http.us.debian.org/debian/&amp;lt;/tt&amp;gt;, you can substitute your favorite Debian mirror.  ([http://www.debian.org/mirror/list List of official Debian Mirrors])&lt;br /&gt;
* See also: &amp;lt;tt&amp;gt;/usr/share/doc/vzctl/README.Debian&amp;lt;/tt&amp;gt; in the ''vzctl'' Debian package&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|if you want to use &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; file system for &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, use &amp;lt;code&amp;gt;nodelalloc&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;, otherwise it will crash. See {{Bug|1509}} and its duplicates for details.}}&lt;br /&gt;
&lt;br /&gt;
You need to have a working copy of &amp;lt;tt&amp;gt;debootstrap&amp;lt;/tt&amp;gt; running on your hardware node.&lt;br /&gt;
&lt;br /&gt;
For Debian:&lt;br /&gt;
 sudo apt-get install debootstrap&lt;br /&gt;
&lt;br /&gt;
For Gentoo:&lt;br /&gt;
 sudo emerge debootstrap&lt;br /&gt;
&lt;br /&gt;
For Fedora (at least Fedora 8 have it, not sure about earlier versions):&lt;br /&gt;
 sudo yum install debootstrap&lt;br /&gt;
&lt;br /&gt;
For other distros you might need to install it from sources, or search for an appropriate package for your distribution.  An RPM is available on the [http://forum.openvz.org/index.php?t=tree&amp;amp;th=142&amp;amp;mid=584 OpenVZ Forum].&lt;br /&gt;
&lt;br /&gt;
== Bootstrapping Debian ==&lt;br /&gt;
&lt;br /&gt;
You can install different releases of Debian into a VE's private directory using the debootstrap command.&lt;br /&gt;
&lt;br /&gt;
The command parameters are:&lt;br /&gt;
&lt;br /&gt;
  debootstrap --arch ARCH NAME DIRECTORY URL&lt;br /&gt;
&lt;br /&gt;
Specify your architecture instead of &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; if you're using something other than i386/x86.  For example, for AMD64/x86_64, use &amp;lt;tt&amp;gt;amd64&amp;lt;/tt&amp;gt; or for ia64, use &amp;lt;tt&amp;gt;ia64&amp;lt;/tt&amp;gt;. You can use http or ftp in the URL.&lt;br /&gt;
&lt;br /&gt;
We use VE ID of 777 for this example, but it can be any unused ID.&lt;br /&gt;
&lt;br /&gt;
=== Wheezy (current stable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 wheezy /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 wheezy /vz/private/777 http://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Squeeze (current oldstable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 squeeze /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 squeeze /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Lenny (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 lenny /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 lenny /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Etch (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 etch /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Sarge (very old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap sarge /vz/private/777 http://archive.debian.org/debian&lt;br /&gt;
&lt;br /&gt;
== Preparing the HN network ==&lt;br /&gt;
Append the following lines to /etc/sysctl.conf, adjust to taste and then execute &amp;quot;sysctl -p&amp;quot; for them to take effect.&lt;br /&gt;
 ### OpenVZ settings&lt;br /&gt;
 &lt;br /&gt;
 # On Hardware Node enable packet forwarding to forward&lt;br /&gt;
 # packets between the HN network interfaces and venet.&lt;br /&gt;
 # Proxy arp is needed when CT is in a different subnet&lt;br /&gt;
 # or when using veth AND veth is not bridged to a HN&lt;br /&gt;
 # interface. When veth is bridged to a HN interface,&lt;br /&gt;
 # the CT handles its own arps.&lt;br /&gt;
 &lt;br /&gt;
 net.ipv4.conf.default.forwarding=1&lt;br /&gt;
 net.ipv4.conf.default.proxy_arp = 0&lt;br /&gt;
 net.ipv4.ip_forward=1&lt;br /&gt;
 &lt;br /&gt;
 # Enables source route verification&lt;br /&gt;
 net.ipv4.conf.all.rp_filter = 1&lt;br /&gt;
 &lt;br /&gt;
 # Enables the magic-sysrq key&lt;br /&gt;
 kernel.sysrq = 1&lt;br /&gt;
 &lt;br /&gt;
 # TCP Explict Congestion Notification&lt;br /&gt;
 net.ipv4.tcp_ecn = 0&lt;br /&gt;
 &lt;br /&gt;
 # we do not want all our interfaces to send redirects&lt;br /&gt;
 net.ipv4.conf.default.send_redirects = 1&lt;br /&gt;
 net.ipv4.conf.all.send_redirects = 0&lt;br /&gt;
&lt;br /&gt;
== Preparing and starting the VE ==&lt;br /&gt;
&lt;br /&gt;
=== Setting VE config ===&lt;br /&gt;
First, we need a config for the [[VE]]:&lt;br /&gt;
 sudo vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&lt;br /&gt;
On debian squeeze only the following worked for me (''confirmed''), because the standard template names in /etc/vz/conf have changed.&lt;br /&gt;
 sudo vzctl set 777 --applyconfig basic --save&lt;br /&gt;
&lt;br /&gt;
=== Setting VE OSTEMPLATE ===&lt;br /&gt;
Also, we need &amp;lt;tt&amp;gt;OSTEMPLATE&amp;lt;/tt&amp;gt; to be set in VE configuration file, for [[vzctl]] to work properly.&lt;br /&gt;
&lt;br /&gt;
 sudo sh -c 'echo OSTEMPLATE=\&amp;quot;debian-6.0\&amp;quot;' &amp;gt;&amp;gt; /etc/vz/conf/777.conf&lt;br /&gt;
&lt;br /&gt;
=== Setting VE IP address ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it:&lt;br /&gt;
 sudo vzctl set 777 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
{{Note|if you use private IP for the VE, you might have to set up NAT as described in [[Using NAT for VE with private IPs]].}}&lt;br /&gt;
&lt;br /&gt;
=== Setting DNS server for VE ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it:&lt;br /&gt;
 sudo vzctl set 777 --nameserver x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== Creating /dev/ptmx  ===&lt;br /&gt;
The ptmx character device should normally exist, but if it doesn't, create one.&lt;br /&gt;
 sudo mknod --mode 666 /var/lib/vz/private/777/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
=== Starting VE ===&lt;br /&gt;
Now start the VE:&lt;br /&gt;
 sudo vzctl start 777&lt;br /&gt;
&lt;br /&gt;
== Customizing the installation ==&lt;br /&gt;
A few things need to be done inside a newly created VE for it to become suitable for OpenVZ. Enter the VE to begin the configuration (note: if running a wheezy container on a squeeze hardware node, you'll need to manually install a newer version of vzctl (the one from wheezy will be fine - http://packages.debian.org/wheezy/vzctl) due to this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683454 - without making this change, the enter command will hang). Exporting the path is optional.&lt;br /&gt;
 sudo vzctl enter 777&lt;br /&gt;
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}}&lt;br /&gt;
&lt;br /&gt;
=== Set Debian repositories ===&lt;br /&gt;
The list shown is for wheezy, and downloading from US located servers - adjust your release name and mirror location as necessary&lt;br /&gt;
 cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apt/sources.list&lt;br /&gt;
 deb http://http.us.debian.org/debian wheezy main contrib&lt;br /&gt;
 deb http://security.debian.org wheezy/updates main contrib&lt;br /&gt;
 deb http://http.us.debian.org/debian wheezy-updates main&lt;br /&gt;
 ## backports - ONLY IF YOU KNOW WHAT YOU DO&lt;br /&gt;
 # deb http://http.us.debian.org/debian-backports/ wheezy-backports main&lt;br /&gt;
 EOF&lt;br /&gt;
&lt;br /&gt;
=== Get new security updates ===&lt;br /&gt;
 apt-get update&lt;br /&gt;
 apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
=== Install some more packages ===&lt;br /&gt;
Installing packages could be an interactive process so the system might ask some questions.  You can install more packages if you'd like.  For example:&lt;br /&gt;
 apt-get install ssh quota less&lt;br /&gt;
&lt;br /&gt;
=== Set sane permissions for &amp;lt;tt&amp;gt;/root&amp;lt;/tt&amp;gt; directory ===&lt;br /&gt;
 chmod 700 /root&lt;br /&gt;
&lt;br /&gt;
=== Disable root login ===&lt;br /&gt;
This will disable root login by default.&lt;br /&gt;
 usermod -L root&lt;br /&gt;
&lt;br /&gt;
=== Disable getty ===&lt;br /&gt;
Disable running &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt;s on terminals as a VE does not have any:&lt;br /&gt;
 sed -i -e '/getty/d' /etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== Disable &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; for syslog ===&lt;br /&gt;
Turn off doing &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; on every write for &amp;lt;tt&amp;gt;syslog&amp;lt;/tt&amp;gt;'s log files, to improve I/O performance:&lt;br /&gt;
 &amp;lt;pre&amp;gt;sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/*syslog.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Link &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;/proc/mounts&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt; and friends will work:&lt;br /&gt;
 rm -f /etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
=== Remove some unneeded packages ===&lt;br /&gt;
If you have any packages you'd like to remove, now's the time for it.  Here's an example — note that not all of those packages are installed by default in Debian Squeeze (although they were in earlier versions):&lt;br /&gt;
 dpkg --purge modutils ppp pppoeconf pppoe pppconfig module-init-tools&lt;br /&gt;
&lt;br /&gt;
=== Disable services ===&lt;br /&gt;
Do not start some services, stick to bare minimum:&lt;br /&gt;
 update-rc.d -f klogd remove&lt;br /&gt;
 update-rc.d -f quotarpc remove&lt;br /&gt;
 update-rc.d -f exim4 remove&lt;br /&gt;
 update-rc.d -f inetd remove&lt;br /&gt;
&lt;br /&gt;
For dependency-based boot sequence introduced with Squeeze type:&lt;br /&gt;
&lt;br /&gt;
 update-rc.d-insserv -f klogd remove&lt;br /&gt;
 update-rc.d-insserv -f quotarpc remove&lt;br /&gt;
 update-rc.d-insserv -f exim4 remove&lt;br /&gt;
 update-rc.d-insserv -f inetd remove&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys ===&lt;br /&gt;
This is only useful if you installed SSH.  Each individual [[VE]] should have its own pair of SSH host keys.  The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|This will not work using the dependency-based boot sequence introduced with Squeeze. See the section below. }}&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys in Squeeze when using dependency-based booting ===&lt;br /&gt;
&lt;br /&gt;
 rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          Generates new ssh host keys on first boot&lt;br /&gt;
# Required-Start:    $remote_fs $syslog&lt;br /&gt;
# Required-Stop:     $remote_fs $syslog&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:&lt;br /&gt;
# Short-Description: Generates new ssh host keys on first boot&lt;br /&gt;
# Description:       Generates new ssh host keys on first boot&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N &amp;quot;&amp;quot;&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N &amp;quot;&amp;quot;&lt;br /&gt;
insserv -r /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 chmod a+x /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
 insserv /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
&lt;br /&gt;
=== Change timezone ===&lt;br /&gt;
&lt;br /&gt;
You might want to change timezone if you do not live in $UTC. The following example is for Germany&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or even better&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dpkg-reconfigure tzdata&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clean packages ===&lt;br /&gt;
After installing packages, you'll have some junk packages laying around in your cache.  Since you don't want your template to have those, this command will wipe them out.&lt;br /&gt;
 apt-get --purge clean&lt;br /&gt;
&lt;br /&gt;
Now everything is done.  Exit from the template and go back to the hardware node.&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
== Preparing for and packing template cache ==&lt;br /&gt;
&lt;br /&gt;
We don't need an IP for the VE anymore, and we definitely do not need it in template cache, so remove it:&lt;br /&gt;
 sudo vzctl set 777 --ipdel all --save&lt;br /&gt;
&lt;br /&gt;
Also, remove DNS server and search domain information from ''/etc/resolv.conf'' file '''in VE''':&lt;br /&gt;
 sudo nano /vz/private/777/etc/resolv.conf&lt;br /&gt;
&lt;br /&gt;
Also, remove ''/etc/hostname'' file '''in VE''':&lt;br /&gt;
 sudo rm -f /vz/private/777/etc/hostname&lt;br /&gt;
&lt;br /&gt;
Stop the VE:&lt;br /&gt;
 sudo vzctl stop 777&lt;br /&gt;
&lt;br /&gt;
Go to the VE directory:&lt;br /&gt;
 cd /vz/private/777&lt;br /&gt;
&lt;br /&gt;
Now create a cached OS tarball.  In the command below, you'll want to replace &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; with your architecture (i386, amd64, ia64, etc).&lt;br /&gt;
 sudo tar --numeric-owner -zcf /vz/template/cache/debian-5.0-i386-minimal.tar.gz .&lt;br /&gt;
&lt;br /&gt;
Look at the resulting tarball to see its size is sane:&lt;br /&gt;
 # ls -lh /vz/template/cache&lt;br /&gt;
 -rw-r--r--  1 root root  51M Apr 10 03:16 debian-5.0-i386-minimal.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Checking if template cache works ==&lt;br /&gt;
We can now create a VE based on the just-created template cache.  Be sure to change &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; to your architecture just like you did when you named the tarball above.&lt;br /&gt;
 sudo vzctl create 123456 --ostemplate debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
Now make sure that it works:&lt;br /&gt;
 sudo vzctl start 123456&lt;br /&gt;
 sudo vzctl exec 123456 ps ax&lt;br /&gt;
&lt;br /&gt;
You should see that a few processes are running.&lt;br /&gt;
&lt;br /&gt;
== Final cleanup ==&lt;br /&gt;
Stop and remove the test VE you just created:&lt;br /&gt;
 sudo vzctl stop 123456&lt;br /&gt;
 sudo vzctl destroy 123456&lt;br /&gt;
 sudo rm /etc/vz/conf/123456.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
Finally, let's remove the VE we used for OS template cache creation:&lt;br /&gt;
 sudo vzctl destroy 777&lt;br /&gt;
 sudo rm /etc/vz/conf/777.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
You might want to edit /etc/vz/vz.conf and change DEF_OSTEMPLATE to the name of the template you use most often so that you don't have to specify the template when creating a VE.&lt;br /&gt;
 DEF_OSTEMPLATE=&amp;quot;debian-6.0-i386-minimal&amp;quot;&lt;br /&gt;
If you use iptables, you might want to include additional modules in the list for IPTABLES in /etc/vz/vz.conf. See ''man vzctl'' for a list of available modules.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Debian]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13903</id>
		<title>Debian template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13903"/>
		<updated>2013-06-23T20:08:59Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* Customizing the installation */ Add note re fix for using wheezy containers on squeeze HNs.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are rough instructions of how to manually create basic Debian template cache, which can be used to create OpenVZ [[VE]]s based on Debian. &lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
* You shouldn't be running as root, but as a user that is permitted to use sudo instead.  It's a dangerous idea, run as root at your peril.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;/vz&amp;lt;/tt&amp;gt;, you might really need to use &amp;lt;tt&amp;gt;/var/lib/vz&amp;lt;/tt&amp;gt; instead, especially on a Debian Etch host.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;http://http.us.debian.org/debian/&amp;lt;/tt&amp;gt;, you can substitute your favorite Debian mirror.  ([http://www.debian.org/mirror/list List of official Debian Mirrors])&lt;br /&gt;
* See also: &amp;lt;tt&amp;gt;/usr/share/doc/vzctl/README.Debian&amp;lt;/tt&amp;gt; in the ''vzctl'' Debian package&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|if you want to use &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; file system for &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, use &amp;lt;code&amp;gt;nodelalloc&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;, otherwise it will crash. See {{Bug|1509}} and its duplicates for details.}}&lt;br /&gt;
&lt;br /&gt;
You need to have a working copy of &amp;lt;tt&amp;gt;debootstrap&amp;lt;/tt&amp;gt; running on your hardware node.&lt;br /&gt;
&lt;br /&gt;
For Debian:&lt;br /&gt;
 sudo apt-get install debootstrap&lt;br /&gt;
&lt;br /&gt;
For Gentoo:&lt;br /&gt;
 sudo emerge debootstrap&lt;br /&gt;
&lt;br /&gt;
For Fedora (at least Fedora 8 have it, not sure about earlier versions):&lt;br /&gt;
 sudo yum install debootstrap&lt;br /&gt;
&lt;br /&gt;
For other distros you might need to install it from sources, or search for an appropriate package for your distribution.  An RPM is available on the [http://forum.openvz.org/index.php?t=tree&amp;amp;th=142&amp;amp;mid=584 OpenVZ Forum].&lt;br /&gt;
&lt;br /&gt;
== Bootstrapping Debian ==&lt;br /&gt;
&lt;br /&gt;
You can install different releases of Debian into a VE's private directory using the debootstrap command.&lt;br /&gt;
&lt;br /&gt;
The command parameters are:&lt;br /&gt;
&lt;br /&gt;
  debootstrap --arch ARCH NAME DIRECTORY URL&lt;br /&gt;
&lt;br /&gt;
Specify your architecture instead of &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; if you're using something other than i386/x86.  For example, for AMD64/x86_64, use &amp;lt;tt&amp;gt;amd64&amp;lt;/tt&amp;gt; or for ia64, use &amp;lt;tt&amp;gt;ia64&amp;lt;/tt&amp;gt;. You can use http or ftp in the URL.&lt;br /&gt;
&lt;br /&gt;
We use VE ID of 777 for this example, but it can be any unused ID.&lt;br /&gt;
&lt;br /&gt;
=== Wheezy (current stable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 wheezy /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 wheezy /vz/private/777 http://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Squeeze (current oldstable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 squeeze /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 squeeze /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Lenny (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 lenny /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 lenny /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Etch (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 etch /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Sarge (very old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap sarge /vz/private/777 http://archive.debian.org/debian&lt;br /&gt;
&lt;br /&gt;
== Preparing the HN network ==&lt;br /&gt;
Append the following lines to /etc/sysctl.conf, adjust to taste and then execute &amp;quot;sysctl -p&amp;quot; for them to take effect.&lt;br /&gt;
 ### OpenVZ settings&lt;br /&gt;
 &lt;br /&gt;
 # On Hardware Node enable packet forwarding to forward&lt;br /&gt;
 # packets between the HN network interfaces and venet.&lt;br /&gt;
 # Proxy arp is needed when CT is in a different subnet&lt;br /&gt;
 # or when using veth AND veth is not bridged to a HN&lt;br /&gt;
 # interface. When veth is bridged to a HN interface,&lt;br /&gt;
 # the CT handles its own arps.&lt;br /&gt;
 &lt;br /&gt;
 net.ipv4.conf.default.forwarding=1&lt;br /&gt;
 net.ipv4.conf.default.proxy_arp = 0&lt;br /&gt;
 net.ipv4.ip_forward=1&lt;br /&gt;
 &lt;br /&gt;
 # Enables source route verification&lt;br /&gt;
 net.ipv4.conf.all.rp_filter = 1&lt;br /&gt;
 &lt;br /&gt;
 # Enables the magic-sysrq key&lt;br /&gt;
 kernel.sysrq = 1&lt;br /&gt;
 &lt;br /&gt;
 # TCP Explict Congestion Notification&lt;br /&gt;
 net.ipv4.tcp_ecn = 0&lt;br /&gt;
 &lt;br /&gt;
 # we do not want all our interfaces to send redirects&lt;br /&gt;
 net.ipv4.conf.default.send_redirects = 1&lt;br /&gt;
 net.ipv4.conf.all.send_redirects = 0&lt;br /&gt;
&lt;br /&gt;
== Preparing and starting the VE ==&lt;br /&gt;
&lt;br /&gt;
=== Setting VE config ===&lt;br /&gt;
First, we need a config for the [[VE]]:&lt;br /&gt;
 sudo vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&lt;br /&gt;
On debian squeeze only the following worked for me (''confirmed''), because the standard template names in /etc/vz/conf have changed.&lt;br /&gt;
 sudo vzctl set 777 --applyconfig basic --save&lt;br /&gt;
&lt;br /&gt;
=== Setting VE OSTEMPLATE ===&lt;br /&gt;
Also, we need &amp;lt;tt&amp;gt;OSTEMPLATE&amp;lt;/tt&amp;gt; to be set in VE configuration file, for [[vzctl]] to work properly.&lt;br /&gt;
&lt;br /&gt;
 sudo sh -c 'echo OSTEMPLATE=\&amp;quot;debian-6.0\&amp;quot;' &amp;gt;&amp;gt; /etc/vz/conf/777.conf&lt;br /&gt;
&lt;br /&gt;
=== Setting VE IP address ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it:&lt;br /&gt;
 sudo vzctl set 777 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
{{Note|if you use private IP for the VE, you might have to set up NAT as described in [[Using NAT for VE with private IPs]].}}&lt;br /&gt;
&lt;br /&gt;
=== Setting DNS server for VE ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it:&lt;br /&gt;
 sudo vzctl set 777 --nameserver x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== Creating /dev/ptmx  ===&lt;br /&gt;
The ptmx character device should normally exist, but if it doesn't, create one.&lt;br /&gt;
 sudo mknod --mode 666 /var/lib/vz/private/777/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
=== Starting VE ===&lt;br /&gt;
Now start the VE:&lt;br /&gt;
 sudo vzctl start 777&lt;br /&gt;
&lt;br /&gt;
== Customizing the installation ==&lt;br /&gt;
A few things need to be done inside a newly created VE for it to become suitable for OpenVZ. Enter the VE to begin the configuration (note: if running a wheezy container on a squeeze hardware node, you'll need to manually install a newer version of vzctl (the one from wheezy will be fine - http://packages.debian.org/wheezy/vzctl) due to this bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683454 - without making this change, the enter command will hang). Exporting the path is optional.&lt;br /&gt;
 sudo vzctl enter 777&lt;br /&gt;
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}}&lt;br /&gt;
&lt;br /&gt;
=== Set Debian repositories ===&lt;br /&gt;
 cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apt/sources.list&lt;br /&gt;
 deb http://http.us.debian.org/debian squeeze main contrib&lt;br /&gt;
 deb http://security.debian.org squeeze/updates main contrib&lt;br /&gt;
 deb http://http.us.debian.org/debian squeeze-updates main&lt;br /&gt;
 ## backports - ONLY IF YOU KNOW WHAT YOU DO&lt;br /&gt;
 # deb http://http.us.debian.org/debian-backports/ squeeze-backports main&lt;br /&gt;
 EOF&lt;br /&gt;
&lt;br /&gt;
=== Get new security updates ===&lt;br /&gt;
 apt-get update&lt;br /&gt;
 apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
=== Install some more packages ===&lt;br /&gt;
Installing packages could be an interactive process so the system might ask some questions.  You can install more packages if you'd like.  For example:&lt;br /&gt;
 apt-get install ssh quota less&lt;br /&gt;
&lt;br /&gt;
=== Set sane permissions for &amp;lt;tt&amp;gt;/root&amp;lt;/tt&amp;gt; directory ===&lt;br /&gt;
 chmod 700 /root&lt;br /&gt;
&lt;br /&gt;
=== Disable root login ===&lt;br /&gt;
This will disable root login by default.&lt;br /&gt;
 usermod -L root&lt;br /&gt;
&lt;br /&gt;
=== Disable getty ===&lt;br /&gt;
Disable running &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt;s on terminals as a VE does not have any:&lt;br /&gt;
 sed -i -e '/getty/d' /etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== Disable &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; for syslog ===&lt;br /&gt;
Turn off doing &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; on every write for &amp;lt;tt&amp;gt;syslog&amp;lt;/tt&amp;gt;'s log files, to improve I/O performance:&lt;br /&gt;
 &amp;lt;pre&amp;gt;sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/*syslog.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Link &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;/proc/mounts&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt; and friends will work:&lt;br /&gt;
 rm -f /etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
=== Remove some unneeded packages ===&lt;br /&gt;
If you have any packages you'd like to remove, now's the time for it.  Here's an example — note that not all of those packages are installed by default in Debian Squeeze (although they were in earlier versions):&lt;br /&gt;
 dpkg --purge modutils ppp pppoeconf pppoe pppconfig module-init-tools&lt;br /&gt;
&lt;br /&gt;
=== Disable services ===&lt;br /&gt;
Do not start some services, stick to bare minimum:&lt;br /&gt;
 update-rc.d -f klogd remove&lt;br /&gt;
 update-rc.d -f quotarpc remove&lt;br /&gt;
 update-rc.d -f exim4 remove&lt;br /&gt;
 update-rc.d -f inetd remove&lt;br /&gt;
&lt;br /&gt;
For dependency-based boot sequence introduced with Squeeze type:&lt;br /&gt;
&lt;br /&gt;
 update-rc.d-insserv -f klogd remove&lt;br /&gt;
 update-rc.d-insserv -f quotarpc remove&lt;br /&gt;
 update-rc.d-insserv -f exim4 remove&lt;br /&gt;
 update-rc.d-insserv -f inetd remove&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys ===&lt;br /&gt;
This is only useful if you installed SSH.  Each individual [[VE]] should have its own pair of SSH host keys.  The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|This will not work using the dependency-based boot sequence introduced with Squeeze. See the section below. }}&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys in Squeeze when using dependency-based booting ===&lt;br /&gt;
&lt;br /&gt;
 rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          Generates new ssh host keys on first boot&lt;br /&gt;
# Required-Start:    $remote_fs $syslog&lt;br /&gt;
# Required-Stop:     $remote_fs $syslog&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:&lt;br /&gt;
# Short-Description: Generates new ssh host keys on first boot&lt;br /&gt;
# Description:       Generates new ssh host keys on first boot&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N &amp;quot;&amp;quot;&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N &amp;quot;&amp;quot;&lt;br /&gt;
insserv -r /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 chmod a+x /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
 insserv /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
&lt;br /&gt;
=== Change timezone ===&lt;br /&gt;
&lt;br /&gt;
You might want to change timezone if you do not live in $UTC. The following example is for Germany&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or even better&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dpkg-reconfigure tzdata&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clean packages ===&lt;br /&gt;
After installing packages, you'll have some junk packages laying around in your cache.  Since you don't want your template to have those, this command will wipe them out.&lt;br /&gt;
 apt-get --purge clean&lt;br /&gt;
&lt;br /&gt;
Now everything is done.  Exit from the template and go back to the hardware node.&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
== Preparing for and packing template cache ==&lt;br /&gt;
&lt;br /&gt;
We don't need an IP for the VE anymore, and we definitely do not need it in template cache, so remove it:&lt;br /&gt;
 sudo vzctl set 777 --ipdel all --save&lt;br /&gt;
&lt;br /&gt;
Also, remove DNS server and search domain information from ''/etc/resolv.conf'' file '''in VE''':&lt;br /&gt;
 sudo nano /vz/private/777/etc/resolv.conf&lt;br /&gt;
&lt;br /&gt;
Also, remove ''/etc/hostname'' file '''in VE''':&lt;br /&gt;
 sudo rm -f /vz/private/777/etc/hostname&lt;br /&gt;
&lt;br /&gt;
Stop the VE:&lt;br /&gt;
 sudo vzctl stop 777&lt;br /&gt;
&lt;br /&gt;
Go to the VE directory:&lt;br /&gt;
 cd /vz/private/777&lt;br /&gt;
&lt;br /&gt;
Now create a cached OS tarball.  In the command below, you'll want to replace &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; with your architecture (i386, amd64, ia64, etc).&lt;br /&gt;
 sudo tar --numeric-owner -zcf /vz/template/cache/debian-5.0-i386-minimal.tar.gz .&lt;br /&gt;
&lt;br /&gt;
Look at the resulting tarball to see its size is sane:&lt;br /&gt;
 # ls -lh /vz/template/cache&lt;br /&gt;
 -rw-r--r--  1 root root  51M Apr 10 03:16 debian-5.0-i386-minimal.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Checking if template cache works ==&lt;br /&gt;
We can now create a VE based on the just-created template cache.  Be sure to change &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; to your architecture just like you did when you named the tarball above.&lt;br /&gt;
 sudo vzctl create 123456 --ostemplate debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
Now make sure that it works:&lt;br /&gt;
 sudo vzctl start 123456&lt;br /&gt;
 sudo vzctl exec 123456 ps ax&lt;br /&gt;
&lt;br /&gt;
You should see that a few processes are running.&lt;br /&gt;
&lt;br /&gt;
== Final cleanup ==&lt;br /&gt;
Stop and remove the test VE you just created:&lt;br /&gt;
 sudo vzctl stop 123456&lt;br /&gt;
 sudo vzctl destroy 123456&lt;br /&gt;
 sudo rm /etc/vz/conf/123456.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
Finally, let's remove the VE we used for OS template cache creation:&lt;br /&gt;
 sudo vzctl destroy 777&lt;br /&gt;
 sudo rm /etc/vz/conf/777.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
You might want to edit /etc/vz/vz.conf and change DEF_OSTEMPLATE to the name of the template you use most often so that you don't have to specify the template when creating a VE.&lt;br /&gt;
 DEF_OSTEMPLATE=&amp;quot;debian-6.0-i386-minimal&amp;quot;&lt;br /&gt;
If you use iptables, you might want to include additional modules in the list for IPTABLES in /etc/vz/vz.conf. See ''man vzctl'' for a list of available modules.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Debian]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13902</id>
		<title>Debian template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=13902"/>
		<updated>2013-06-23T20:03:50Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* Bootstrapping Debian */ Add wheezy (Debian 7.0)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are rough instructions of how to manually create basic Debian template cache, which can be used to create OpenVZ [[VE]]s based on Debian. &lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
* You shouldn't be running as root, but as a user that is permitted to use sudo instead.  It's a dangerous idea, run as root at your peril.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;/vz&amp;lt;/tt&amp;gt;, you might really need to use &amp;lt;tt&amp;gt;/var/lib/vz&amp;lt;/tt&amp;gt; instead, especially on a Debian Etch host.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;http://http.us.debian.org/debian/&amp;lt;/tt&amp;gt;, you can substitute your favorite Debian mirror.  ([http://www.debian.org/mirror/list List of official Debian Mirrors])&lt;br /&gt;
* See also: &amp;lt;tt&amp;gt;/usr/share/doc/vzctl/README.Debian&amp;lt;/tt&amp;gt; in the ''vzctl'' Debian package&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|if you want to use &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; file system for &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt;, use &amp;lt;code&amp;gt;nodelalloc&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;, otherwise it will crash. See {{Bug|1509}} and its duplicates for details.}}&lt;br /&gt;
&lt;br /&gt;
You need to have a working copy of &amp;lt;tt&amp;gt;debootstrap&amp;lt;/tt&amp;gt; running on your hardware node.&lt;br /&gt;
&lt;br /&gt;
For Debian:&lt;br /&gt;
 sudo apt-get install debootstrap&lt;br /&gt;
&lt;br /&gt;
For Gentoo:&lt;br /&gt;
 sudo emerge debootstrap&lt;br /&gt;
&lt;br /&gt;
For Fedora (at least Fedora 8 have it, not sure about earlier versions):&lt;br /&gt;
 sudo yum install debootstrap&lt;br /&gt;
&lt;br /&gt;
For other distros you might need to install it from sources, or search for an appropriate package for your distribution.  An RPM is available on the [http://forum.openvz.org/index.php?t=tree&amp;amp;th=142&amp;amp;mid=584 OpenVZ Forum].&lt;br /&gt;
&lt;br /&gt;
== Bootstrapping Debian ==&lt;br /&gt;
&lt;br /&gt;
You can install different releases of Debian into a VE's private directory using the debootstrap command.&lt;br /&gt;
&lt;br /&gt;
The command parameters are:&lt;br /&gt;
&lt;br /&gt;
  debootstrap --arch ARCH NAME DIRECTORY URL&lt;br /&gt;
&lt;br /&gt;
Specify your architecture instead of &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; if you're using something other than i386/x86.  For example, for AMD64/x86_64, use &amp;lt;tt&amp;gt;amd64&amp;lt;/tt&amp;gt; or for ia64, use &amp;lt;tt&amp;gt;ia64&amp;lt;/tt&amp;gt;. You can use http or ftp in the URL.&lt;br /&gt;
&lt;br /&gt;
We use VE ID of 777 for this example, but it can be any unused ID.&lt;br /&gt;
&lt;br /&gt;
=== Wheezy (current stable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 wheezy /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 wheezy /vz/private/777 http://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Squeeze (current oldstable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 squeeze /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 squeeze /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Lenny (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 lenny /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
 or&lt;br /&gt;
 debootstrap --arch amd64 lenny /vz/private/777 ftp://ftp.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Etch (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 etch /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Sarge (very old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap sarge /vz/private/777 http://archive.debian.org/debian&lt;br /&gt;
&lt;br /&gt;
== Preparing the HN network ==&lt;br /&gt;
Append the following lines to /etc/sysctl.conf, adjust to taste and then execute &amp;quot;sysctl -p&amp;quot; for them to take effect.&lt;br /&gt;
 ### OpenVZ settings&lt;br /&gt;
 &lt;br /&gt;
 # On Hardware Node enable packet forwarding to forward&lt;br /&gt;
 # packets between the HN network interfaces and venet.&lt;br /&gt;
 # Proxy arp is needed when CT is in a different subnet&lt;br /&gt;
 # or when using veth AND veth is not bridged to a HN&lt;br /&gt;
 # interface. When veth is bridged to a HN interface,&lt;br /&gt;
 # the CT handles its own arps.&lt;br /&gt;
 &lt;br /&gt;
 net.ipv4.conf.default.forwarding=1&lt;br /&gt;
 net.ipv4.conf.default.proxy_arp = 0&lt;br /&gt;
 net.ipv4.ip_forward=1&lt;br /&gt;
 &lt;br /&gt;
 # Enables source route verification&lt;br /&gt;
 net.ipv4.conf.all.rp_filter = 1&lt;br /&gt;
 &lt;br /&gt;
 # Enables the magic-sysrq key&lt;br /&gt;
 kernel.sysrq = 1&lt;br /&gt;
 &lt;br /&gt;
 # TCP Explict Congestion Notification&lt;br /&gt;
 net.ipv4.tcp_ecn = 0&lt;br /&gt;
 &lt;br /&gt;
 # we do not want all our interfaces to send redirects&lt;br /&gt;
 net.ipv4.conf.default.send_redirects = 1&lt;br /&gt;
 net.ipv4.conf.all.send_redirects = 0&lt;br /&gt;
&lt;br /&gt;
== Preparing and starting the VE ==&lt;br /&gt;
&lt;br /&gt;
=== Setting VE config ===&lt;br /&gt;
First, we need a config for the [[VE]]:&lt;br /&gt;
 sudo vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&lt;br /&gt;
On debian squeeze only the following worked for me (''confirmed''), because the standard template names in /etc/vz/conf have changed.&lt;br /&gt;
 sudo vzctl set 777 --applyconfig basic --save&lt;br /&gt;
&lt;br /&gt;
=== Setting VE OSTEMPLATE ===&lt;br /&gt;
Also, we need &amp;lt;tt&amp;gt;OSTEMPLATE&amp;lt;/tt&amp;gt; to be set in VE configuration file, for [[vzctl]] to work properly.&lt;br /&gt;
&lt;br /&gt;
 sudo sh -c 'echo OSTEMPLATE=\&amp;quot;debian-6.0\&amp;quot;' &amp;gt;&amp;gt; /etc/vz/conf/777.conf&lt;br /&gt;
&lt;br /&gt;
=== Setting VE IP address ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it:&lt;br /&gt;
 sudo vzctl set 777 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
{{Note|if you use private IP for the VE, you might have to set up NAT as described in [[Using NAT for VE with private IPs]].}}&lt;br /&gt;
&lt;br /&gt;
=== Setting DNS server for VE ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it:&lt;br /&gt;
 sudo vzctl set 777 --nameserver x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== Creating /dev/ptmx  ===&lt;br /&gt;
The ptmx character device should normally exist, but if it doesn't, create one.&lt;br /&gt;
 sudo mknod --mode 666 /var/lib/vz/private/777/dev/ptmx c 5 2&lt;br /&gt;
&lt;br /&gt;
=== Starting VE ===&lt;br /&gt;
Now start the VE:&lt;br /&gt;
 sudo vzctl start 777&lt;br /&gt;
&lt;br /&gt;
== Customizing the installation ==&lt;br /&gt;
A few things need to be done inside a newly created VE for it to become suitable for OpenVZ. Enter the VE to begin the configuration. Exporting the path is optional.&lt;br /&gt;
 sudo vzctl enter 777&lt;br /&gt;
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}}&lt;br /&gt;
&lt;br /&gt;
=== Set Debian repositories ===&lt;br /&gt;
 cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apt/sources.list&lt;br /&gt;
 deb http://http.us.debian.org/debian squeeze main contrib&lt;br /&gt;
 deb http://security.debian.org squeeze/updates main contrib&lt;br /&gt;
 deb http://http.us.debian.org/debian squeeze-updates main&lt;br /&gt;
 ## backports - ONLY IF YOU KNOW WHAT YOU DO&lt;br /&gt;
 # deb http://http.us.debian.org/debian-backports/ squeeze-backports main&lt;br /&gt;
 EOF&lt;br /&gt;
&lt;br /&gt;
=== Get new security updates ===&lt;br /&gt;
 apt-get update&lt;br /&gt;
 apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
=== Install some more packages ===&lt;br /&gt;
Installing packages could be an interactive process so the system might ask some questions.  You can install more packages if you'd like.  For example:&lt;br /&gt;
 apt-get install ssh quota less&lt;br /&gt;
&lt;br /&gt;
=== Set sane permissions for &amp;lt;tt&amp;gt;/root&amp;lt;/tt&amp;gt; directory ===&lt;br /&gt;
 chmod 700 /root&lt;br /&gt;
&lt;br /&gt;
=== Disable root login ===&lt;br /&gt;
This will disable root login by default.&lt;br /&gt;
 usermod -L root&lt;br /&gt;
&lt;br /&gt;
=== Disable getty ===&lt;br /&gt;
Disable running &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt;s on terminals as a VE does not have any:&lt;br /&gt;
 sed -i -e '/getty/d' /etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== Disable &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; for syslog ===&lt;br /&gt;
Turn off doing &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; on every write for &amp;lt;tt&amp;gt;syslog&amp;lt;/tt&amp;gt;'s log files, to improve I/O performance:&lt;br /&gt;
 &amp;lt;pre&amp;gt;sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/*syslog.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Link &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;/proc/mounts&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt; and friends will work:&lt;br /&gt;
 rm -f /etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
=== Remove some unneeded packages ===&lt;br /&gt;
If you have any packages you'd like to remove, now's the time for it.  Here's an example — note that not all of those packages are installed by default in Debian Squeeze (although they were in earlier versions):&lt;br /&gt;
 dpkg --purge modutils ppp pppoeconf pppoe pppconfig module-init-tools&lt;br /&gt;
&lt;br /&gt;
=== Disable services ===&lt;br /&gt;
Do not start some services, stick to bare minimum:&lt;br /&gt;
 update-rc.d -f klogd remove&lt;br /&gt;
 update-rc.d -f quotarpc remove&lt;br /&gt;
 update-rc.d -f exim4 remove&lt;br /&gt;
 update-rc.d -f inetd remove&lt;br /&gt;
&lt;br /&gt;
For dependency-based boot sequence introduced with Squeeze type:&lt;br /&gt;
&lt;br /&gt;
 update-rc.d-insserv -f klogd remove&lt;br /&gt;
 update-rc.d-insserv -f quotarpc remove&lt;br /&gt;
 update-rc.d-insserv -f exim4 remove&lt;br /&gt;
 update-rc.d-insserv -f inetd remove&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys ===&lt;br /&gt;
This is only useful if you installed SSH.  Each individual [[VE]] should have its own pair of SSH host keys.  The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|This will not work using the dependency-based boot sequence introduced with Squeeze. See the section below. }}&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys in Squeeze when using dependency-based booting ===&lt;br /&gt;
&lt;br /&gt;
 rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
### BEGIN INIT INFO&lt;br /&gt;
# Provides:          Generates new ssh host keys on first boot&lt;br /&gt;
# Required-Start:    $remote_fs $syslog&lt;br /&gt;
# Required-Stop:     $remote_fs $syslog&lt;br /&gt;
# Default-Start:     2 3 4 5&lt;br /&gt;
# Default-Stop:&lt;br /&gt;
# Short-Description: Generates new ssh host keys on first boot&lt;br /&gt;
# Description:       Generates new ssh host keys on first boot&lt;br /&gt;
### END INIT INFO&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N &amp;quot;&amp;quot;&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N &amp;quot;&amp;quot;&lt;br /&gt;
insserv -r /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
 chmod a+x /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
 insserv /etc/init.d/ssh_gen_host_keys&lt;br /&gt;
&lt;br /&gt;
=== Change timezone ===&lt;br /&gt;
&lt;br /&gt;
You might want to change timezone if you do not live in $UTC. The following example is for Germany&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or even better&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dpkg-reconfigure tzdata&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clean packages ===&lt;br /&gt;
After installing packages, you'll have some junk packages laying around in your cache.  Since you don't want your template to have those, this command will wipe them out.&lt;br /&gt;
 apt-get --purge clean&lt;br /&gt;
&lt;br /&gt;
Now everything is done.  Exit from the template and go back to the hardware node.&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
== Preparing for and packing template cache ==&lt;br /&gt;
&lt;br /&gt;
We don't need an IP for the VE anymore, and we definitely do not need it in template cache, so remove it:&lt;br /&gt;
 sudo vzctl set 777 --ipdel all --save&lt;br /&gt;
&lt;br /&gt;
Also, remove DNS server and search domain information from ''/etc/resolv.conf'' file '''in VE''':&lt;br /&gt;
 sudo nano /vz/private/777/etc/resolv.conf&lt;br /&gt;
&lt;br /&gt;
Also, remove ''/etc/hostname'' file '''in VE''':&lt;br /&gt;
 sudo rm -f /vz/private/777/etc/hostname&lt;br /&gt;
&lt;br /&gt;
Stop the VE:&lt;br /&gt;
 sudo vzctl stop 777&lt;br /&gt;
&lt;br /&gt;
Go to the VE directory:&lt;br /&gt;
 cd /vz/private/777&lt;br /&gt;
&lt;br /&gt;
Now create a cached OS tarball.  In the command below, you'll want to replace &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; with your architecture (i386, amd64, ia64, etc).&lt;br /&gt;
 sudo tar --numeric-owner -zcf /vz/template/cache/debian-5.0-i386-minimal.tar.gz .&lt;br /&gt;
&lt;br /&gt;
Look at the resulting tarball to see its size is sane:&lt;br /&gt;
 # ls -lh /vz/template/cache&lt;br /&gt;
 -rw-r--r--  1 root root  51M Apr 10 03:16 debian-5.0-i386-minimal.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Checking if template cache works ==&lt;br /&gt;
We can now create a VE based on the just-created template cache.  Be sure to change &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; to your architecture just like you did when you named the tarball above.&lt;br /&gt;
 sudo vzctl create 123456 --ostemplate debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
Now make sure that it works:&lt;br /&gt;
 sudo vzctl start 123456&lt;br /&gt;
 sudo vzctl exec 123456 ps ax&lt;br /&gt;
&lt;br /&gt;
You should see that a few processes are running.&lt;br /&gt;
&lt;br /&gt;
== Final cleanup ==&lt;br /&gt;
Stop and remove the test VE you just created:&lt;br /&gt;
 sudo vzctl stop 123456&lt;br /&gt;
 sudo vzctl destroy 123456&lt;br /&gt;
 sudo rm /etc/vz/conf/123456.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
Finally, let's remove the VE we used for OS template cache creation:&lt;br /&gt;
 sudo vzctl destroy 777&lt;br /&gt;
 sudo rm /etc/vz/conf/777.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
You might want to edit /etc/vz/vz.conf and change DEF_OSTEMPLATE to the name of the template you use most often so that you don't have to specify the template when creating a VE.&lt;br /&gt;
 DEF_OSTEMPLATE=&amp;quot;debian-6.0-i386-minimal&amp;quot;&lt;br /&gt;
If you use iptables, you might want to include additional modules in the list for IPTABLES in /etc/vz/vz.conf. See ''man vzctl'' for a list of available modules.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Debian]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Installation_on_Debian/old&amp;diff=13536</id>
		<title>Installation on Debian/old</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Installation_on_Debian/old&amp;diff=13536"/>
		<updated>2013-03-22T12:53:04Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;OpenVZ consists of a kernel, user-level tools, and container templates.&lt;br /&gt;
&lt;br /&gt;
This guide tells how to install the kernel and the tools on [http://www.debian.org Debian] Etch or Lenny/Squeeze. &lt;br /&gt;
&lt;br /&gt;
For Squeeze, use the Lenny directions.&lt;br /&gt;
&lt;br /&gt;
For Wheezy (7.0), use the vzctl package included in wheezy, together with the Wheezy OpenVZ kernels from [http://download.openvz.org/debian/ http://download.openvz.org/debian/].  Alternatively reduced functionality may be possible using the stock Debian Wheezy kernel (based on kernel.org version 3.2) and [[Vzctl_for_upstream_kernel]].&lt;br /&gt;
&lt;br /&gt;
{{Note|The majority of the content on this page only applies to older, unsupported Debian versions and should be archived.}}&lt;br /&gt;
&lt;br /&gt;
You may also wish to check the information on [http://wiki.debian.org/OpenVz the Debian wiki].&lt;br /&gt;
&lt;br /&gt;
For Etch users, this document explains how to partially upgrade to Debian Lenny and install from lenny repositories ('''use this options at your risk''').&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Filesystems ===&lt;br /&gt;
It's recommended that you use a separate partition for container private&lt;br /&gt;
directories (by default &amp;lt;code&amp;gt;/var/lib/vz/private/&amp;lt;CTID&amp;gt;&amp;lt;/code&amp;gt;). The reason for this is that if you wish to use the OpenVZ per-container disk quota, you won't be able to use usual Linux disk quotas on the same partition. Bear in mind that &amp;quot;per-container quota&amp;quot; in this context includes not only pure per-container quota but also the usual Linux disk quota used in container, not on the [[HN]].&lt;br /&gt;
&lt;br /&gt;
At the very least try to avoid using the root partition for containers, because the root user of a container will be able to overcome the 5% disk space barrier in some situations. If the HN root partition is completely filled, it will break the system.&lt;br /&gt;
&lt;br /&gt;
OpenVZ per-container disk quota is supported only for ext2/ext3 filesystems; therefore it makes sense to use one of these filesystems (ext3 is recommended) if you need per-container disk quota.&lt;br /&gt;
&lt;br /&gt;
=== Repository setup (Etch only) ===&lt;br /&gt;
&lt;br /&gt;
'''If you are using Debian Lenny, this step in no longer required. Openvz kernel packages and tools are available on main repository.'''&lt;br /&gt;
&lt;br /&gt;
==== 1. Using openvz.org repositories ====&lt;br /&gt;
&lt;br /&gt;
At the moment two different repositories are online at http://download.openvz.org:&lt;br /&gt;
&lt;br /&gt;
; by Ola Lundqvist &amp;lt;opal@debian.org&amp;gt;&lt;br /&gt;
: (OpenVZ kernels only)&lt;br /&gt;
: apt-uri http://download.openvz.org/debian&lt;br /&gt;
&lt;br /&gt;
; by Thorsten Schifferdecker &amp;lt;tsd@debian.systs.org&amp;gt;&lt;br /&gt;
: apt-uri http://download.openvz.org/debian-systs&lt;br /&gt;
: (Mirror of OpenVZ Repository from http://debian.systs.org/)&lt;br /&gt;
&lt;br /&gt;
{{Note|The next steps use the repository at http://download.openvz.org/debian-systs; the actual OpenVZ Tools for Debian exist only as unstable builds, see http://packages.debian.org/vzctl}}&lt;br /&gt;
&lt;br /&gt;
{{Note|By default, on Ubuntu systems root tasks are executed with [https://help.ubuntu.com/community/RootSudo sudo]}}&lt;br /&gt;
&lt;br /&gt;
This can be done via the following commands, as root or as privileged &amp;quot;sudo&amp;quot; user&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# echo -e &amp;quot;\ndeb http://download.openvz.org/debian-systs etch openvz&amp;quot; &amp;gt;&amp;gt; /etc/apt/sources.list&lt;br /&gt;
# wget -q http://download.openvz.org/debian-systs/dso_archiv_signing_key.asc -O- | apt-key add - &amp;amp;&amp;amp; apt-get update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Using Debian repositories (upgrade to lenny) ====&lt;br /&gt;
&lt;br /&gt;
There is even a '''lenny''' repository with kernel 2.6.28. '''Use it at your own risk!'''&lt;br /&gt;
&lt;br /&gt;
Add lenny repositories to your '''/etc/apt/sources.list'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
deb http://DEBIAN-MIRROR/debian/ testing main&lt;br /&gt;
deb http://DEBIAN-MIRROR/debian-security/ testing/updates main&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enlarge apt-cache adding to '''/etc/apt/apt.conf''' this line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
APT::Cache-Limit &amp;quot;100000000&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Give etch package priority over lenny packages. Edit '''/etc/apt/preferences''' and set like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Package: *&lt;br /&gt;
Pin: release a=etch&lt;br /&gt;
Pin-Priority: 700&lt;br /&gt;
&lt;br /&gt;
Package: *&lt;br /&gt;
Pin: release a=lenny&lt;br /&gt;
Pin-Priority: 650&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then '''apt-get update &amp;amp;&amp;amp; apt-get dist-upgrade''' to upgrade to lenny.&lt;br /&gt;
&lt;br /&gt;
== Kernel installation ==&lt;br /&gt;
&lt;br /&gt;
=== Wheezy and Lenny ===&lt;br /&gt;
&lt;br /&gt;
{{Note|The best kernel to use is [[Download/kernel/rhel6|RHEL6-based]]. Please see [[Install_kernel_from_RPM_on_Debian_6.0]]}}&lt;br /&gt;
&lt;br /&gt;
=== Etch ===&lt;br /&gt;
&lt;br /&gt;
==== 1. Using openvz kernel repositories ====&lt;br /&gt;
&lt;br /&gt;
{{Note|In case you want to recompile the OpenVZ kernel yourself on Debian, see [[Compiling the OpenVZ kernel (the Debian way)]].}}&lt;br /&gt;
&lt;br /&gt;
First, you need to choose what kernel you want to install.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+'''OpenVZ Kernel list built with kernel config from http://download.openvz.org'''&lt;br /&gt;
! Kernel !! Description !! Hardware !! Debian Architecture&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18&lt;br /&gt;
| uniprocessor&lt;br /&gt;
| up to 4GB of RAM&lt;br /&gt;
| i386 and amd64&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18-smp&lt;br /&gt;
| symmetric multiprocessor&lt;br /&gt;
| up to 4 GB of RAM&lt;br /&gt;
| i386 and amd64&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18-enterprise&lt;br /&gt;
| SMP + PAE support + 4/4GB split&lt;br /&gt;
| up to 64 GB of RAM&lt;br /&gt;
| i386 only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+'''OpenVZ Kernel list built with official Debian kernel config and OpenVZ Settings'''&lt;br /&gt;
! Kernel !! Description !! Hardware !! Debian Architecture&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-686&lt;br /&gt;
| uni- and multiprocessor&lt;br /&gt;
| up to 4GB of RAM&lt;br /&gt;
| i386&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-686-bigmem&lt;br /&gt;
| symmetric multiprocessor&lt;br /&gt;
| up to 64 GB of RAM&lt;br /&gt;
| i386&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-amd64&lt;br /&gt;
| uni- and multiprocessor&lt;br /&gt;
| &lt;br /&gt;
| amd64&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # apt-get install &amp;lt;kernel&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Configuring the bootloader =====&lt;br /&gt;
&lt;br /&gt;
In case GRUB is used as the boot loader, it will be configured automatically, or execute update-grub; lines similar to these will be added to the &amp;lt;tt&amp;gt;/boot/grub/menu.lst&amp;lt;/tt&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[...]&lt;br /&gt;
  title           Debian GNU/Linux, kernel 2.6.18-ovz-028stab051.1-686&lt;br /&gt;
  root            (hd0,1)&lt;br /&gt;
  kernel          /vmlinuz-2.6.18-ovz-028stab051.1-686 root=/dev/sda5 ro vga=791&lt;br /&gt;
  initrd          /initrd.img-2.6.18-ovz-028stab051.1-686&lt;br /&gt;
  savedefault&lt;br /&gt;
[...]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|per default on debian/ubuntu, a 2.6.22 kernel will boot before a 2.6.18, please check manually the grub boot order. See man update-grub for more details}}&lt;br /&gt;
&lt;br /&gt;
===== Installing the user-level tools =====&lt;br /&gt;
&lt;br /&gt;
OpenVZ needs some user-level tools installed. Those are:&lt;br /&gt;
&lt;br /&gt;
; vzctl&lt;br /&gt;
: A utility to control OpenVZ containers (create, destroy, start, stop, set parameters etc.)&lt;br /&gt;
; vzquota&lt;br /&gt;
: A utility to manage quotas for containers. Mostly used indirectly (by vzctl).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # [sudo] apt-get install vzctl vzquota&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2 Using Debian lenny repositories ====&lt;br /&gt;
&lt;br /&gt;
If you upgrade to lenny, you can search openvz kernel and can install with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install linux-image-openvz-686&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this command will install latest kernel and all required packages like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install iproute libatm1 linux-image-2.6.26-1-openvz-686 linux-image-openvz-686 rsync vzctl vzquota libcgroup-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and will arrange grub bootloader properly.&lt;br /&gt;
&lt;br /&gt;
=== Rebooting into OpenVZ kernel ===&lt;br /&gt;
&lt;br /&gt;
{{Warning|Before you restart your Server, verify that your system has all needed modules enabled in order to boot your harddisk (e.g. hardware modules, raid system(s), lvm2 etc). You may need an INITRD (initramdisk) or to compile needed kernel modules statically.}}&lt;br /&gt;
&lt;br /&gt;
Now reboot the machine and choose the OpenVZ Linux Kernel on the boot loader menu. If the OpenVZ kernel has been booted successfully, proceed to installing the user-level tools for OpenVZ.&lt;br /&gt;
&lt;br /&gt;
=== Confirm proper installation ===&lt;br /&gt;
&lt;br /&gt;
1. Kernel:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # uname -r&lt;br /&gt;
 2.6.26-1-openvz-686&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Openvz kernel facility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # ps ax | grep vz&lt;br /&gt;
 2349 ?        S      0:00 [vzmond]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. A network interface for containers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # ifconfig&lt;br /&gt;
 venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  &lt;br /&gt;
           UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1&lt;br /&gt;
           RX packets:0 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;
           collisions:0 txqueuelen:0 &lt;br /&gt;
           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuring ==&lt;br /&gt;
&lt;br /&gt;
=== sysctl ===&lt;br /&gt;
&lt;br /&gt;
There are a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt; file. Here is the relevant part of the file; please edit it accordingly.&lt;br /&gt;
&lt;br /&gt;
{{Note|vzctl version from debian-systs, automatically inserts these options at the last of &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;, except for net.ipv4.ip_forward}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[...]&lt;br /&gt;
&lt;br /&gt;
# On Hardware Node we generally need&lt;br /&gt;
# packet forwarding enabled and proxy arp disabled&lt;br /&gt;
&lt;br /&gt;
net.ipv4.conf.default.forwarding=1&lt;br /&gt;
net.ipv4.conf.default.proxy_arp=0&lt;br /&gt;
net.ipv4.ip_forward=1&lt;br /&gt;
&lt;br /&gt;
# Enables source route verification&lt;br /&gt;
net.ipv4.conf.all.rp_filter=1&lt;br /&gt;
&lt;br /&gt;
# Enables the magic-sysrq key&lt;br /&gt;
kernel.sysrq=1&lt;br /&gt;
&lt;br /&gt;
# TCP Explict Congestion Notification&lt;br /&gt;
#net.ipv4.tcp_ecn=0&lt;br /&gt;
&lt;br /&gt;
# we do not want all our interfaces to send redirects&lt;br /&gt;
net.ipv4.conf.default.send_redirects=1&lt;br /&gt;
net.ipv4.conf.all.send_redirects=0&lt;br /&gt;
&lt;br /&gt;
[...]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # [sudo] sysctl -p&lt;br /&gt;
&lt;br /&gt;
{{Note|You can make a symlink from /var/lib/vz to /vz as backward&lt;br /&gt;
compatibility to OpenVZ as installed in other distributions&lt;br /&gt;
(Debian vz root directory is /var/lib/vz to be FHS-compliant.}}&lt;br /&gt;
&lt;br /&gt;
  # [sudo] ln -s /var/lib/vz /vz&lt;br /&gt;
&lt;br /&gt;
=== OS templates ===&lt;br /&gt;
&lt;br /&gt;
{{Note|Support of OS templates on 64 bit hosts is somewhat limited for the time being, so that not all tools or features are available - please see [[Making template tools to work on x86_64]] and [[Install OpenVZ on a x86 64 system Centos-Fedora]] for additional details and information on possible workarounds}}&lt;br /&gt;
&lt;br /&gt;
To install a container, you need OS template(s).&lt;br /&gt;
&lt;br /&gt;
Precreated templates can be found [http://wiki.openvz.org/Download/template/precreated here] and [http://download.openvz.org/contrib/template/precreated/ here].&lt;br /&gt;
&lt;br /&gt;
You can create your own templates, see &lt;br /&gt;
[[Debian template creation]], [[Ubuntu Gutsy template creation]] and [[:Category: Templates]].&lt;br /&gt;
&lt;br /&gt;
{{Note|Setup your prefered standard OS Template : edit the /etc/vz/vz.conf}}&lt;br /&gt;
&lt;br /&gt;
  # [sudo] apt-get install vzctl-ostmpl-debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
== Additional User Tools ==&lt;br /&gt;
&lt;br /&gt;
; vzprocps&lt;br /&gt;
:    A set of utilities to provide system information (vzps and vztop)&lt;br /&gt;
&lt;br /&gt;
; [[vzdump]]&lt;br /&gt;
:    A utility to backup and restore container. &lt;br /&gt;
&lt;br /&gt;
  # [sudo] apt-get install vzprocps vzdump&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On Debian squeeze, vzdump seems packaged in standard aptline. For lenny, See [[Backup_of_a_running_container_with_vzdump]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Secure it ==&lt;br /&gt;
&lt;br /&gt;
If you want to secure your container with individual firewall rules (instead or additionally to securing the host node) then you must run iptables inside the container. This works slightly different than on a physical server. So make sure that you check that iptables rules are indeed applied as expected inside the container.&lt;br /&gt;
&lt;br /&gt;
Iptables modules required by the container must be specified in the general vz.conf file or the vzXXX.conf file of the container.&lt;br /&gt;
&lt;br /&gt;
Add the following line into vz.conf to activate the respective iptables modules for all containers.&lt;br /&gt;
&lt;br /&gt;
 IPTABLES=&amp;quot;ip_tables ipt_REJECT ipt_tos ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl&lt;br /&gt;
 ipt_length ip_conntrack ip_conntrack_ftp ip_conntrack_irc ipt_LOG ipt_conntrack ipt_helper ipt_state iptable_nat ip_nat_ftp ip_nat_irc ipt_TOS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[http://wiki.debian.org/DebianFirewall][Configure]] your iptable rules inside the container.&lt;br /&gt;
&lt;br /&gt;
{{Warning|Note that iptables rules inside the container are not applied automatically as on a physical server by starting the iptables module! Follow the instructions below}}&lt;br /&gt;
&lt;br /&gt;
To make sure the iptables rules are applied on a startup/reboot we'll create a new file:&lt;br /&gt;
&lt;br /&gt;
 nano /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
Add these lines to it:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 /sbin/iptables-restore &amp;lt; /etc/iptables.up.rules&lt;br /&gt;
&lt;br /&gt;
The file needs to be executable so change the permissions:&lt;br /&gt;
&lt;br /&gt;
 chmod +x /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
Start iptables&lt;br /&gt;
&lt;br /&gt;
 /etc/init.d/iptables start&lt;br /&gt;
&lt;br /&gt;
If the startup shows errors then you have probably not activated the needed iptables modules. See above.&lt;br /&gt;
&lt;br /&gt;
Check inside the container that your iptables rules are indeed applied:&lt;br /&gt;
&lt;br /&gt;
 iptables -L&lt;br /&gt;
&lt;br /&gt;
If the rules do not show up as you would expect on a physical server then you might not have activated the needed iptables modules.&lt;br /&gt;
&lt;br /&gt;
== Start it! ==&lt;br /&gt;
&lt;br /&gt;
 # [sudo] /etc/init.d/vz start&lt;br /&gt;
&lt;br /&gt;
This does not make the vz system automatically start at boot time.  For automatic start:&lt;br /&gt;
&lt;br /&gt;
 # [sudo] update-rc.d vz defaults 98&lt;br /&gt;
&lt;br /&gt;
== Use it! ==&lt;br /&gt;
&lt;br /&gt;
After installing the OpenVZ kernel, user tools and a minimal OS template&lt;br /&gt;
to create a first container and do some [[basic operations in OpenVZ environment]]. Read the [[download:doc/OpenVZ-Users-Guide.pdf]], browse this wiki.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Debian]]&lt;br /&gt;
[[Category: Installation]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Installation_on_Debian/old&amp;diff=13529</id>
		<title>Installation on Debian/old</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Installation_on_Debian/old&amp;diff=13529"/>
		<updated>2013-03-18T11:23:29Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: Note for relevance, add link to debian.org wiki page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;OpenVZ consists of a kernel, user-level tools, and container templates.&lt;br /&gt;
&lt;br /&gt;
This guide tells how to install the kernel and the tools on [http://www.debian.org Debian] Etch or Lenny/Squeeze. &lt;br /&gt;
&lt;br /&gt;
For Squeeze, use the Lenny directions.&lt;br /&gt;
&lt;br /&gt;
{{Note|The majority of the content on this page only applies to older, unsupported Debian versions and should be archived.}}&lt;br /&gt;
&lt;br /&gt;
You may also wish to check the information on [http://wiki.debian.org/OpenVz the Debian wiki].&lt;br /&gt;
&lt;br /&gt;
For Etch users, this document explains how to partially upgrade to Debian Lenny and install from lenny repositories ('''use this options at your risk''').&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Filesystems ===&lt;br /&gt;
It's recommended that you use a separate partition for container private&lt;br /&gt;
directories (by default &amp;lt;code&amp;gt;/var/lib/vz/private/&amp;lt;CTID&amp;gt;&amp;lt;/code&amp;gt;). The reason for this is that if you wish to use the OpenVZ per-container disk quota, you won't be able to use usual Linux disk quotas on the same partition. Bear in mind that &amp;quot;per-container quota&amp;quot; in this context includes not only pure per-container quota but also the usual Linux disk quota used in container, not on the [[HN]].&lt;br /&gt;
&lt;br /&gt;
At the very least try to avoid using the root partition for containers, because the root user of a container will be able to overcome the 5% disk space barrier in some situations. If the HN root partition is completely filled, it will break the system.&lt;br /&gt;
&lt;br /&gt;
OpenVZ per-container disk quota is supported only for ext2/ext3 filesystems; therefore it makes sense to use one of these filesystems (ext3 is recommended) if you need per-container disk quota.&lt;br /&gt;
&lt;br /&gt;
=== Repository setup (Etch only) ===&lt;br /&gt;
&lt;br /&gt;
'''If you are using Debian Lenny, this step in no longer required. Openvz kernel packages and tools are available on main repository.'''&lt;br /&gt;
&lt;br /&gt;
==== 1. Using openvz.org repositories ====&lt;br /&gt;
&lt;br /&gt;
At the moment two different repositories are online at http://download.openvz.org:&lt;br /&gt;
&lt;br /&gt;
; by Ola Lundqvist &amp;lt;opal@debian.org&amp;gt;&lt;br /&gt;
: (OpenVZ kernels only)&lt;br /&gt;
: apt-uri http://download.openvz.org/debian&lt;br /&gt;
&lt;br /&gt;
; by Thorsten Schifferdecker &amp;lt;tsd@debian.systs.org&amp;gt;&lt;br /&gt;
: apt-uri http://download.openvz.org/debian-systs&lt;br /&gt;
: (Mirror of OpenVZ Repository from http://debian.systs.org/)&lt;br /&gt;
&lt;br /&gt;
{{Note|The next steps use the repository at http://download.openvz.org/debian-systs; the actual OpenVZ Tools for Debian exist only as unstable builds, see http://packages.debian.org/vzctl}}&lt;br /&gt;
&lt;br /&gt;
{{Note|By default, on Ubuntu systems root tasks are executed with [https://help.ubuntu.com/community/RootSudo sudo]}}&lt;br /&gt;
&lt;br /&gt;
This can be done via the following commands, as root or as privileged &amp;quot;sudo&amp;quot; user&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# echo -e &amp;quot;\ndeb http://download.openvz.org/debian-systs etch openvz&amp;quot; &amp;gt;&amp;gt; /etc/apt/sources.list&lt;br /&gt;
# wget -q http://download.openvz.org/debian-systs/dso_archiv_signing_key.asc -O- | apt-key add - &amp;amp;&amp;amp; apt-get update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Using Debian repositories (upgrade to lenny) ====&lt;br /&gt;
&lt;br /&gt;
There is even a '''lenny''' repository with kernel 2.6.28. '''Use it at your own risk!'''&lt;br /&gt;
&lt;br /&gt;
Add lenny repositories to your '''/etc/apt/sources.list'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
deb http://DEBIAN-MIRROR/debian/ testing main&lt;br /&gt;
deb http://DEBIAN-MIRROR/debian-security/ testing/updates main&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enlarge apt-cache adding to '''/etc/apt/apt.conf''' this line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
APT::Cache-Limit &amp;quot;100000000&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Give etch package priority over lenny packages. Edit '''/etc/apt/preferences''' and set like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Package: *&lt;br /&gt;
Pin: release a=etch&lt;br /&gt;
Pin-Priority: 700&lt;br /&gt;
&lt;br /&gt;
Package: *&lt;br /&gt;
Pin: release a=lenny&lt;br /&gt;
Pin-Priority: 650&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then '''apt-get update &amp;amp;&amp;amp; apt-get dist-upgrade''' to upgrade to lenny.&lt;br /&gt;
&lt;br /&gt;
== Kernel installation ==&lt;br /&gt;
&lt;br /&gt;
=== Wheezy and Lenny ===&lt;br /&gt;
&lt;br /&gt;
{{Note|The best kernel to use is [[Download/kernel/rhel6|RHEL6-based]]. Please see [[Install_kernel_from_RPM_on_Debian_6.0]]}}&lt;br /&gt;
&lt;br /&gt;
=== Etch ===&lt;br /&gt;
&lt;br /&gt;
==== 1. Using openvz kernel repositories ====&lt;br /&gt;
&lt;br /&gt;
{{Note|In case you want to recompile the OpenVZ kernel yourself on Debian, see [[Compiling the OpenVZ kernel (the Debian way)]].}}&lt;br /&gt;
&lt;br /&gt;
First, you need to choose what kernel you want to install.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+'''OpenVZ Kernel list built with kernel config from http://download.openvz.org'''&lt;br /&gt;
! Kernel !! Description !! Hardware !! Debian Architecture&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18&lt;br /&gt;
| uniprocessor&lt;br /&gt;
| up to 4GB of RAM&lt;br /&gt;
| i386 and amd64&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18-smp&lt;br /&gt;
| symmetric multiprocessor&lt;br /&gt;
| up to 4 GB of RAM&lt;br /&gt;
| i386 and amd64&lt;br /&gt;
|-&lt;br /&gt;
! ovzkernel-2.6.18-enterprise&lt;br /&gt;
| SMP + PAE support + 4/4GB split&lt;br /&gt;
| up to 64 GB of RAM&lt;br /&gt;
| i386 only&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+'''OpenVZ Kernel list built with official Debian kernel config and OpenVZ Settings'''&lt;br /&gt;
! Kernel !! Description !! Hardware !! Debian Architecture&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-686&lt;br /&gt;
| uni- and multiprocessor&lt;br /&gt;
| up to 4GB of RAM&lt;br /&gt;
| i386&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-686-bigmem&lt;br /&gt;
| symmetric multiprocessor&lt;br /&gt;
| up to 64 GB of RAM&lt;br /&gt;
| i386&lt;br /&gt;
|-&lt;br /&gt;
! fzakernel-2.6.18-amd64&lt;br /&gt;
| uni- and multiprocessor&lt;br /&gt;
| &lt;br /&gt;
| amd64&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # apt-get install &amp;lt;kernel&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Configuring the bootloader =====&lt;br /&gt;
&lt;br /&gt;
In case GRUB is used as the boot loader, it will be configured automatically, or execute update-grub; lines similar to these will be added to the &amp;lt;tt&amp;gt;/boot/grub/menu.lst&amp;lt;/tt&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[...]&lt;br /&gt;
  title           Debian GNU/Linux, kernel 2.6.18-ovz-028stab051.1-686&lt;br /&gt;
  root            (hd0,1)&lt;br /&gt;
  kernel          /vmlinuz-2.6.18-ovz-028stab051.1-686 root=/dev/sda5 ro vga=791&lt;br /&gt;
  initrd          /initrd.img-2.6.18-ovz-028stab051.1-686&lt;br /&gt;
  savedefault&lt;br /&gt;
[...]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|per default on debian/ubuntu, a 2.6.22 kernel will boot before a 2.6.18, please check manually the grub boot order. See man update-grub for more details}}&lt;br /&gt;
&lt;br /&gt;
===== Installing the user-level tools =====&lt;br /&gt;
&lt;br /&gt;
OpenVZ needs some user-level tools installed. Those are:&lt;br /&gt;
&lt;br /&gt;
; vzctl&lt;br /&gt;
: A utility to control OpenVZ containers (create, destroy, start, stop, set parameters etc.)&lt;br /&gt;
; vzquota&lt;br /&gt;
: A utility to manage quotas for containers. Mostly used indirectly (by vzctl).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # [sudo] apt-get install vzctl vzquota&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2 Using Debian lenny repositories ====&lt;br /&gt;
&lt;br /&gt;
If you upgrade to lenny, you can search openvz kernel and can install with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install linux-image-openvz-686&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
this command will install latest kernel and all required packages like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install iproute libatm1 linux-image-2.6.26-1-openvz-686 linux-image-openvz-686 rsync vzctl vzquota libcgroup-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and will arrange grub bootloader properly.&lt;br /&gt;
&lt;br /&gt;
=== Rebooting into OpenVZ kernel ===&lt;br /&gt;
&lt;br /&gt;
{{Warning|Before you restart your Server, verify that your system has all needed modules enabled in order to boot your harddisk (e.g. hardware modules, raid system(s), lvm2 etc). You may need an INITRD (initramdisk) or to compile needed kernel modules statically.}}&lt;br /&gt;
&lt;br /&gt;
Now reboot the machine and choose the OpenVZ Linux Kernel on the boot loader menu. If the OpenVZ kernel has been booted successfully, proceed to installing the user-level tools for OpenVZ.&lt;br /&gt;
&lt;br /&gt;
=== Confirm proper installation ===&lt;br /&gt;
&lt;br /&gt;
1. Kernel:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # uname -r&lt;br /&gt;
 2.6.26-1-openvz-686&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Openvz kernel facility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # ps ax | grep vz&lt;br /&gt;
 2349 ?        S      0:00 [vzmond]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. A network interface for containers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # ifconfig&lt;br /&gt;
 venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  &lt;br /&gt;
           UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1&lt;br /&gt;
           RX packets:0 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;
           collisions:0 txqueuelen:0 &lt;br /&gt;
           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuring ==&lt;br /&gt;
&lt;br /&gt;
=== sysctl ===&lt;br /&gt;
&lt;br /&gt;
There are a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt; file. Here is the relevant part of the file; please edit it accordingly.&lt;br /&gt;
&lt;br /&gt;
{{Note|vzctl version from debian-systs, automatically inserts these options at the last of &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;, except for net.ipv4.ip_forward}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[...]&lt;br /&gt;
&lt;br /&gt;
# On Hardware Node we generally need&lt;br /&gt;
# packet forwarding enabled and proxy arp disabled&lt;br /&gt;
&lt;br /&gt;
net.ipv4.conf.default.forwarding=1&lt;br /&gt;
net.ipv4.conf.default.proxy_arp=0&lt;br /&gt;
net.ipv4.ip_forward=1&lt;br /&gt;
&lt;br /&gt;
# Enables source route verification&lt;br /&gt;
net.ipv4.conf.all.rp_filter=1&lt;br /&gt;
&lt;br /&gt;
# Enables the magic-sysrq key&lt;br /&gt;
kernel.sysrq=1&lt;br /&gt;
&lt;br /&gt;
# TCP Explict Congestion Notification&lt;br /&gt;
#net.ipv4.tcp_ecn=0&lt;br /&gt;
&lt;br /&gt;
# we do not want all our interfaces to send redirects&lt;br /&gt;
net.ipv4.conf.default.send_redirects=1&lt;br /&gt;
net.ipv4.conf.all.send_redirects=0&lt;br /&gt;
&lt;br /&gt;
[...]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  # [sudo] sysctl -p&lt;br /&gt;
&lt;br /&gt;
{{Note|You can make a symlink from /var/lib/vz to /vz as backward&lt;br /&gt;
compatibility to OpenVZ as installed in other distributions&lt;br /&gt;
(Debian vz root directory is /var/lib/vz to be FHS-compliant.}}&lt;br /&gt;
&lt;br /&gt;
  # [sudo] ln -s /var/lib/vz /vz&lt;br /&gt;
&lt;br /&gt;
=== OS templates ===&lt;br /&gt;
&lt;br /&gt;
{{Note|Support of OS templates on 64 bit hosts is somewhat limited for the time being, so that not all tools or features are available - please see [[Making template tools to work on x86_64]] and [[Install OpenVZ on a x86 64 system Centos-Fedora]] for additional details and information on possible workarounds}}&lt;br /&gt;
&lt;br /&gt;
To install a container, you need OS template(s).&lt;br /&gt;
&lt;br /&gt;
Precreated templates can be found [http://wiki.openvz.org/Download/template/precreated here] and [http://download.openvz.org/contrib/template/precreated/ here].&lt;br /&gt;
&lt;br /&gt;
You can create your own templates, see &lt;br /&gt;
[[Debian template creation]], [[Ubuntu Gutsy template creation]] and [[:Category: Templates]].&lt;br /&gt;
&lt;br /&gt;
{{Note|Setup your prefered standard OS Template : edit the /etc/vz/vz.conf}}&lt;br /&gt;
&lt;br /&gt;
  # [sudo] apt-get install vzctl-ostmpl-debian-5.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
== Additional User Tools ==&lt;br /&gt;
&lt;br /&gt;
; vzprocps&lt;br /&gt;
:    A set of utilities to provide system information (vzps and vztop)&lt;br /&gt;
&lt;br /&gt;
; [[vzdump]]&lt;br /&gt;
:    A utility to backup and restore container. &lt;br /&gt;
&lt;br /&gt;
  # [sudo] apt-get install vzprocps vzdump&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On Debian squeeze, vzdump seems packaged in standard aptline. For lenny, See [[Backup_of_a_running_container_with_vzdump]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Secure it ==&lt;br /&gt;
&lt;br /&gt;
If you want to secure your container with individual firewall rules (instead or additionally to securing the host node) then you must run iptables inside the container. This works slightly different than on a physical server. So make sure that you check that iptables rules are indeed applied as expected inside the container.&lt;br /&gt;
&lt;br /&gt;
Iptables modules required by the container must be specified in the general vz.conf file or the vzXXX.conf file of the container.&lt;br /&gt;
&lt;br /&gt;
Add the following line into vz.conf to activate the respective iptables modules for all containers.&lt;br /&gt;
&lt;br /&gt;
 IPTABLES=&amp;quot;ip_tables ipt_REJECT ipt_tos ipt_limit ipt_multiport iptable_filter iptable_mangle ipt_TCPMSS ipt_tcpmss ipt_ttl&lt;br /&gt;
 ipt_length ip_conntrack ip_conntrack_ftp ip_conntrack_irc ipt_LOG ipt_conntrack ipt_helper ipt_state iptable_nat ip_nat_ftp ip_nat_irc ipt_TOS&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[http://wiki.debian.org/DebianFirewall][Configure]] your iptable rules inside the container.&lt;br /&gt;
&lt;br /&gt;
{{Warning|Note that iptables rules inside the container are not applied automatically as on a physical server by starting the iptables module! Follow the instructions below}}&lt;br /&gt;
&lt;br /&gt;
To make sure the iptables rules are applied on a startup/reboot we'll create a new file:&lt;br /&gt;
&lt;br /&gt;
 nano /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
Add these lines to it:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 /sbin/iptables-restore &amp;lt; /etc/iptables.up.rules&lt;br /&gt;
&lt;br /&gt;
The file needs to be executable so change the permissions:&lt;br /&gt;
&lt;br /&gt;
 chmod +x /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
Start iptables&lt;br /&gt;
&lt;br /&gt;
 /etc/init.d/iptables start&lt;br /&gt;
&lt;br /&gt;
If the startup shows errors then you have probably not activated the needed iptables modules. See above.&lt;br /&gt;
&lt;br /&gt;
Check inside the container that your iptables rules are indeed applied:&lt;br /&gt;
&lt;br /&gt;
 iptables -L&lt;br /&gt;
&lt;br /&gt;
If the rules do not show up as you would expect on a physical server then you might not have activated the needed iptables modules.&lt;br /&gt;
&lt;br /&gt;
== Start it! ==&lt;br /&gt;
&lt;br /&gt;
 # [sudo] /etc/init.d/vz start&lt;br /&gt;
&lt;br /&gt;
This does not make the vz system automatically start at boot time.  For automatic start:&lt;br /&gt;
&lt;br /&gt;
 # [sudo] update-rc.d vz defaults 98&lt;br /&gt;
&lt;br /&gt;
== Use it! ==&lt;br /&gt;
&lt;br /&gt;
After installing the OpenVZ kernel, user tools and a minimal OS template&lt;br /&gt;
to create a first container and do some [[basic operations in OpenVZ environment]]. Read the [[download:doc/OpenVZ-Users-Guide.pdf]], browse this wiki.&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Debian]]&lt;br /&gt;
[[Category: Installation]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Monitoring_openvz_resources_using_munin&amp;diff=9518</id>
		<title>Monitoring openvz resources using munin</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Monitoring_openvz_resources_using_munin&amp;diff=9518"/>
		<updated>2010-12-13T13:09:29Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: Add openvzcpu plugin from Munin Exchange&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Monitoring]]&lt;br /&gt;
&lt;br /&gt;
[http://exchange.munin-monitoring.org/plugins/openvzcpu/details There is a plugin available on the Munin Exchange web site] which tracks CPU usage accross different containers.&lt;br /&gt;
&lt;br /&gt;
[http://exchange.munin-monitoring.org/plugins/openvz_/details A second is also available via the Munin plugin exchange] which tracks beancounter values.&lt;br /&gt;
&lt;br /&gt;
Additionally, there are several plugins available on this page to monitor beancounter values in [http://munin.projects.linpro.no/ Munin].&lt;br /&gt;
The third one tries to combine the other two.  (FIXME, maybe these should live in the Munin Exchange too?)&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Simple&amp;quot; munin plugin =&lt;br /&gt;
&lt;br /&gt;
The plugin listed below grabs all the beancounters' values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# plugin to monitor OpenVZ bean counters.&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#%# family=auto&lt;br /&gt;
#%# capabilities=autoconf suggest&lt;br /&gt;
&lt;br /&gt;
ATTR=`basename $0 | sed 's/^vebc_//g'`&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;autoconf&amp;quot; ]; then&lt;br /&gt;
        if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
                echo yes&lt;br /&gt;
                exit 0&lt;br /&gt;
        else&lt;br /&gt;
                echo &amp;quot;no (/proc/bc/0/resources not found)&amp;quot;&lt;br /&gt;
                exit 1&lt;br /&gt;
        fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;suggest&amp;quot; ]; then&lt;br /&gt;
        if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
            cat /proc/bc/0/resources |&lt;br /&gt;
            while read str; do&lt;br /&gt;
                vals=($str)&lt;br /&gt;
                echo ${vals[0]}&lt;br /&gt;
            done&lt;br /&gt;
                exit 0&lt;br /&gt;
        else&lt;br /&gt;
                exit 1&lt;br /&gt;
        fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;config&amp;quot; ]; then&lt;br /&gt;
#       echo &amp;quot;graph_order down up&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_title $ATTR beancounter for containers&amp;quot;&lt;br /&gt;
        echo 'graph_category system'&lt;br /&gt;
        echo &amp;quot;graph_info 'Containers beancounters info'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        for CTID in `ls -d1 /proc/bc/???`; do&lt;br /&gt;
            id=`basename $CTID`&lt;br /&gt;
            grep $ATTR $CTID/resources |&lt;br /&gt;
            while read str; do&lt;br /&gt;
&lt;br /&gt;
                vals=($str)&lt;br /&gt;
                name=${vals[0]}&lt;br /&gt;
                echo ${id}.label $id&lt;br /&gt;
                echo &amp;quot;${id}.warning  ${vals[3]}&amp;quot;&lt;br /&gt;
                echo &amp;quot;${id}.critical  ${vals[4]}&amp;quot;&lt;br /&gt;
            done&lt;br /&gt;
        done&lt;br /&gt;
&lt;br /&gt;
        exit 0&lt;br /&gt;
fi;&lt;br /&gt;
&lt;br /&gt;
for CTID in `ls -d1 /proc/bc/???`; do&lt;br /&gt;
    id=`basename $CTID`&lt;br /&gt;
    grep $ATTR $CTID/resources |&lt;br /&gt;
    while read str; do&lt;br /&gt;
        vals=($str)&lt;br /&gt;
        name=${vals[0]}&lt;br /&gt;
        echo &amp;quot;$id.value ${vals[1]}&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Extended Version for old system using user_beancounter =&lt;br /&gt;
&lt;br /&gt;
Put it with the munin plugins and make a link for every&lt;br /&gt;
graph which should be produced named like:&lt;br /&gt;
&lt;br /&gt;
vebc_VALUENAME1_VALUENAME2_..._CTID&lt;br /&gt;
&lt;br /&gt;
e.g.: vebc_numflock_numpty_numsiginfo_101&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# plugin to monitor OpenVZ bean counters.&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#%# family=auto&lt;br /&gt;
#%# capabilities=autoconf suggest&lt;br /&gt;
&lt;br /&gt;
ATTR=`basename $0 | sed -e 's/^vebc_.*_//'`&lt;br /&gt;
STATS=`basename $0 | sed -e 's/^vebc_//' -e 's/_[0-9]*$//' -e 's/_/ /g'`&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;autoconf&amp;quot; ]; then&lt;br /&gt;
        if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
                echo yes&lt;br /&gt;
                exit 0&lt;br /&gt;
        else&lt;br /&gt;
                echo &amp;quot;no (/proc/bc/0/resources not found)&amp;quot;&lt;br /&gt;
                exit 1&lt;br /&gt;
        fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;suggest&amp;quot; ]; then&lt;br /&gt;
        if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
            cat /proc/bc/0/resources |&lt;br /&gt;
            while read str; do&lt;br /&gt;
                vals=($str)&lt;br /&gt;
                echo ${vals[0]}&lt;br /&gt;
            done&lt;br /&gt;
                exit 0&lt;br /&gt;
        else&lt;br /&gt;
                exit 1&lt;br /&gt;
        fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;config&amp;quot; ]; then&lt;br /&gt;
#       echo &amp;quot;graph_order down up&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_title beancounter for CT$ATTR: $STATS&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_category CT$ATTR&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_info 'Container bean counters info'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        readme=&amp;quot;false&amp;quot;&lt;br /&gt;
        cat /proc/user_beancounters | while read myid stuff; do&lt;br /&gt;
                line=&amp;quot;&amp;quot;&lt;br /&gt;
                if [ &amp;quot;$myid&amp;quot; == &amp;quot;$ATTR:&amp;quot; ]; then&lt;br /&gt;
                        readme=&amp;quot;true&amp;quot;&lt;br /&gt;
                        line=&amp;quot;$stuff&amp;quot;&lt;br /&gt;
                        echo $line&lt;br /&gt;
                else&lt;br /&gt;
                        loid=`echo $myid | sed -e 's/.*:/:/'`&lt;br /&gt;
                        if [ &amp;quot;$loid&amp;quot; == &amp;quot;:&amp;quot; ]; then&lt;br /&gt;
                                readme=&amp;quot;false&amp;quot;&lt;br /&gt;
                        fi&lt;br /&gt;
                        if [ &amp;quot;$readme&amp;quot; == &amp;quot;true&amp;quot; ]; then&lt;br /&gt;
                                line=&amp;quot;$myid $stuff&amp;quot;&lt;br /&gt;
                        echo $line&lt;br /&gt;
                        fi&lt;br /&gt;
                fi&lt;br /&gt;
        done | while read name value top warn max; do&lt;br /&gt;
                okname=&amp;quot;dummy&amp;quot;&lt;br /&gt;
                for statname in $STATS; do&lt;br /&gt;
                        if [ &amp;quot;$name&amp;quot; == &amp;quot;$statname&amp;quot; ]; then&lt;br /&gt;
                                okname=$name&lt;br /&gt;
                        fi&lt;br /&gt;
                done&lt;br /&gt;
&lt;br /&gt;
                if [ &amp;quot;$okname&amp;quot; != &amp;quot;dummy&amp;quot; ]; then&lt;br /&gt;
                        echo $okname.label $name&lt;br /&gt;
                        echo $okname.warning $warn&lt;br /&gt;
                        echo $okname.critical $max&lt;br /&gt;
                fi&lt;br /&gt;
        done&lt;br /&gt;
        exit 0&lt;br /&gt;
fi;&lt;br /&gt;
&lt;br /&gt;
readme=&amp;quot;false&amp;quot;&lt;br /&gt;
cat /proc/user_beancounters | while read myid stuff; do&lt;br /&gt;
        line=&amp;quot;&amp;quot;&lt;br /&gt;
        if [ &amp;quot;$myid&amp;quot; == &amp;quot;$ATTR:&amp;quot; ]; then&lt;br /&gt;
                readme=&amp;quot;true&amp;quot;&lt;br /&gt;
                line=&amp;quot;$stuff&amp;quot;&lt;br /&gt;
                echo $line&lt;br /&gt;
        else&lt;br /&gt;
                loid=`echo $myid | sed -e 's/.*:/:/'`&lt;br /&gt;
                if [ &amp;quot;$loid&amp;quot; == &amp;quot;:&amp;quot; ]; then&lt;br /&gt;
                        readme=&amp;quot;false&amp;quot;&lt;br /&gt;
                fi&lt;br /&gt;
                if [ &amp;quot;$readme&amp;quot; == &amp;quot;true&amp;quot; ]; then&lt;br /&gt;
                        line=&amp;quot;$myid $stuff&amp;quot;&lt;br /&gt;
                echo $line&lt;br /&gt;
                fi&lt;br /&gt;
        fi&lt;br /&gt;
done | while read name value x; do&lt;br /&gt;
        okname=&amp;quot;dummy&amp;quot;&lt;br /&gt;
        for statname in $STATS; do&lt;br /&gt;
                if [ &amp;quot;$name&amp;quot; == &amp;quot;$statname&amp;quot; ]; then&lt;br /&gt;
                        okname=$name&lt;br /&gt;
                fi&lt;br /&gt;
        done&lt;br /&gt;
        if [ &amp;quot;$okname&amp;quot; != &amp;quot;dummy&amp;quot; ]; then&lt;br /&gt;
                echo $okname.value $value&lt;br /&gt;
        fi&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is not too performant but should do and the graphs are much&lt;br /&gt;
more readable then the first solution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Extended plugin from Jan Tomasek =&lt;br /&gt;
* Jan has posted another plugin on http://forum.openvz.org/index.php?t=msg&amp;amp;goto=15122, where I've fixed two things:&lt;br /&gt;
*# &amp;quot;exit 0&amp;quot; in the &amp;quot;config&amp;quot; block&lt;br /&gt;
*# Replaced &amp;quot;vals=($str); echo ${vals[0]}&amp;quot; with &amp;quot;echo ${str%% *}&amp;quot; (the former was causing problems I don't remember anymore)&lt;br /&gt;
* v1.3.2 (2008/08/09)&lt;br /&gt;
*# If only 1 variable is graphed, also display maxheld, barrier and limit&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# Munin's plugin to monitor OpenVZ bean counters.&lt;br /&gt;
#&lt;br /&gt;
# $Log$&lt;br /&gt;
# Revision 1.3 2007/07/19 12:57:00 Jan Tomasek &amp;lt;jan@tomasek.cz&amp;gt;&lt;br /&gt;
# * rewrited to work with /proc/bc/&amp;lt;VEID&amp;gt;/resources instead of&lt;br /&gt;
# /proc/user_beancounters, that simplified code and result&lt;br /&gt;
# is also bit faster.&lt;br /&gt;
# * added references to OpenVZ wiki&lt;br /&gt;
# Revision 1.3.1 2008/05/13 01:26:00 Daniel Hahler &amp;lt;http://daniel.hahler.de/&amp;gt;&lt;br /&gt;
# * Minor fixes&lt;br /&gt;
#   - &amp;quot;exit 0&amp;quot; in &amp;quot;config&amp;quot; block&lt;br /&gt;
#   - Use &amp;quot;echo ${str%% *}&amp;quot; in &amp;quot;suggest&amp;quot;, instead of &amp;quot;vals=($str); echo ${vals[0]}&amp;quot;&lt;br /&gt;
#&lt;br /&gt;
# Revision 1.3.2 2008/08/09 12:30:00 Christian Rubbert &amp;lt;crubbert@xrc.de&amp;gt;&lt;br /&gt;
# * Feature&lt;br /&gt;
#   - If only 1 variable is graphed, also display maxheld, barrier and limit&lt;br /&gt;
#&lt;br /&gt;
# Original revision taken from:&lt;br /&gt;
# http://wiki.openvz.org/Monitoring_openvz_resources_using_munin&lt;br /&gt;
#&lt;br /&gt;
#%# family=auto&lt;br /&gt;
#%# capabilities=autoconf suggest&lt;br /&gt;
 &lt;br /&gt;
VEID=`basename $0 | sed -e 's/^vebc_.*_//'`;&lt;br /&gt;
STATS=`basename $0 | sed -e 's/^vebc_//' -e 's/_[0-9]*$//' -e 's/_/ /g'`&lt;br /&gt;
x=0; STATSCNT=`for i in $STATS; do x=$[$x+1]; done; echo $x`&lt;br /&gt;
 &lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;autoconf&amp;quot; ]; then&lt;br /&gt;
    if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
        echo yes&lt;br /&gt;
        exit 0&lt;br /&gt;
    else&lt;br /&gt;
        echo &amp;quot;no (/proc/bc/0/resources not found)&amp;quot;&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
 &lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;suggest&amp;quot; ]; then&lt;br /&gt;
    if [ -r /proc/bc/0/resources ]; then&lt;br /&gt;
        cat /proc/bc/0/resources | while read str; do&lt;br /&gt;
        # Print everything before &amp;quot; &amp;quot;&lt;br /&gt;
        echo ${str%% *}&lt;br /&gt;
        done&lt;br /&gt;
        exit 0&lt;br /&gt;
    else&lt;br /&gt;
        exit 1&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
 &lt;br /&gt;
if [ ! -f /proc/bc/$VEID/resources ]; then&lt;br /&gt;
    exit 0;&lt;br /&gt;
fi&lt;br /&gt;
 &lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;config&amp;quot; ]; then&lt;br /&gt;
    #echo &amp;quot;graph_order down up&amp;quot;&lt;br /&gt;
    echo &amp;quot;graph_title VE$VEID: $STATS&amp;quot;&lt;br /&gt;
    echo &amp;quot;graph_vlabel bean counters&amp;quot;&lt;br /&gt;
    echo &amp;quot;graph_category VE$VEID&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    # Note on URLs. General graph info is by munin version 1.2.5&lt;br /&gt;
    # accepted even with HTML code. But for value.info it escapes URL,&lt;br /&gt;
    # I expect that authors of munin will note that in future and put&lt;br /&gt;
    # escaping even for graph.info.&lt;br /&gt;
    echo &amp;quot;graph_info VE bean counters info. Documentation of the OpenVZ resource management is located at &amp;lt;a href=\&amp;quot;&lt;br /&gt;
http://wiki.openvz.org/UBC\&amp;quot;&amp;gt;http://wiki.openvz.org/UBC&amp;lt;/a&amp;gt;.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    cat /proc/bc/$VEID/resources | while read name value top warn max stuff ; do&lt;br /&gt;
        for statname in $STATS; do&lt;br /&gt;
        if [ &amp;quot;$name&amp;quot; = &amp;quot;$statname&amp;quot; ]; then&lt;br /&gt;
            URL=&amp;quot;http://wiki.openvz.org/$name&amp;quot;&lt;br /&gt;
            if [ &amp;quot;$warn&amp;quot; = &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
                warn=$max&lt;br /&gt;
            fi&lt;br /&gt;
            echo $name.label $name&lt;br /&gt;
            echo $name.warning $warn&lt;br /&gt;
            echo $name.critical $max&lt;br /&gt;
            echo $name.info Description of this resource is located at $URL&lt;br /&gt;
        fi&lt;br /&gt;
        done&lt;br /&gt;
    done&lt;br /&gt;
&lt;br /&gt;
    if [ &amp;quot;$STATSCNT&amp;quot; == &amp;quot;1&amp;quot; ]; then&lt;br /&gt;
        echo maxheld.label Maxheld&lt;br /&gt;
        echo maxheld.draw LINE2&lt;br /&gt;
        echo maxheld.info Maximum value&lt;br /&gt;
        echo barrier.label Barrier&lt;br /&gt;
        echo barrier.draw LINE2&lt;br /&gt;
        echo barrier.info Barrier&lt;br /&gt;
        echo limit.label Limit&lt;br /&gt;
        echo limit.draw LINE2&lt;br /&gt;
        echo limit.info Limit&lt;br /&gt;
    fi&lt;br /&gt;
    exit 0&lt;br /&gt;
fi;&lt;br /&gt;
 &lt;br /&gt;
cat /proc/bc/$VEID/resources | while read name value top warn max stuff ; do&lt;br /&gt;
    for statname in $STATS; do&lt;br /&gt;
    if [ &amp;quot;$name&amp;quot; = &amp;quot;$statname&amp;quot; ]; then&lt;br /&gt;
        echo $name&amp;quot;.value &amp;quot;$value;&lt;br /&gt;
&lt;br /&gt;
	if [ &amp;quot;$STATSCNT&amp;quot; == &amp;quot;1&amp;quot; ]; then&lt;br /&gt;
	    echo maxheld.value $top&lt;br /&gt;
	    echo barrier.value $warn&lt;br /&gt;
	    echo limit.value $max &lt;br /&gt;
	fi&lt;br /&gt;
    fi&lt;br /&gt;
    done&lt;br /&gt;
done&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Munin plugin setup =&lt;br /&gt;
== Run as root ==&lt;br /&gt;
Please note, you have to configure plugin to run as root. Therefore, add the following to /etc/munin/plugin-conf.d/ somewhere:&lt;br /&gt;
  [vebc*]&lt;br /&gt;
  user root&lt;br /&gt;
&lt;br /&gt;
== Installing the plugins ==&lt;br /&gt;
There's a single plugin file, which can be installed several times and can put several values into the same graph.&lt;br /&gt;
You should install the plugin from above to e.g. &amp;lt;code&amp;gt;/usr/local/share/munin/plugins/vebc_&amp;lt;/code&amp;gt; and then put symlinks to there from /etc/munin/plugins.&lt;br /&gt;
The following script allows you to handle this easily:&lt;br /&gt;
To install this, you can use the following script:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
FILE=`mktemp /tmp/ln-vebc-XXXXXX`&lt;br /&gt;
&lt;br /&gt;
cd /etc/munin/plugins&lt;br /&gt;
&lt;br /&gt;
for resources in kmemsize \&lt;br /&gt;
    lockedpages_privvmpages_shmpages_physpages_vmguarpages_oomguarpages \&lt;br /&gt;
    numproc \&lt;br /&gt;
    numtcpsock_numflock_numpty_numsiginfo_numothersock_numiptent \&lt;br /&gt;
    tcpsndbuf_tcprcvbuf_othersockbuf_dgramrcvbuf \&lt;br /&gt;
    dcachesize \&lt;br /&gt;
    numfile&lt;br /&gt;
do&lt;br /&gt;
    for VE in 0 `/usr/sbin/vzlist | sed &amp;quot;s/^ *//&amp;quot; |grep '^[0-9]' | cut -f 1 -d &amp;quot; &amp;quot;` ; do&lt;br /&gt;
        ln -sf /usr/local/share/munin/plugins/vebc_ &amp;quot;vebc_&amp;quot;$resources&amp;quot;_&amp;quot;$VE&lt;br /&gt;
        echo &amp;quot;vebc_&amp;quot;$resources&amp;quot;_&amp;quot;$VE &amp;gt;&amp;gt; $FILE&lt;br /&gt;
    done&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# remove no longer deserved links (ie. links pointing to machines&lt;br /&gt;
# which were destroyed or stoped)&lt;br /&gt;
&lt;br /&gt;
find -type l -name vebc_\* | sed &amp;quot;s/\.\///&amp;quot; | while read LN; do&lt;br /&gt;
    if grep ^$LN$ $FILE &amp;gt;/dev/null; then&lt;br /&gt;
        true&lt;br /&gt;
    else&lt;br /&gt;
        rm $LN&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
rm $FILE&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Alternative: Using vzlist =&lt;br /&gt;
This simple script will generate an overview of the requested stat from all VE's.&lt;br /&gt;
When using vzlist your saved from any changes to the beancounters.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
Simply append the variable you want to monitor:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;ln -s /usr/share/munin/plugins/openvz_ /etc/munin/plugins/openvz_physpages&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# Munin's plugin to monitor OpenVZ bean counters.&lt;br /&gt;
#&lt;br /&gt;
# $Log$&lt;br /&gt;
# 2008/08/14 Rene Weselowski &amp;lt;http://www.dead.at&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#%# family=auto&lt;br /&gt;
#%# capabilities=autoconf&lt;br /&gt;
&lt;br /&gt;
ATTRIBUTE=`basename $0 | sed 's/^openvz_//g'`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;autoconf&amp;quot; ]; then&lt;br /&gt;
        echo yes&lt;br /&gt;
        exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;config&amp;quot; ]; then&lt;br /&gt;
        echo &amp;quot;graph_title $ATTRIBUTE&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_args --base 1000 -l 0&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_scale yes&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_vlabel $ATTRIBUTE Value&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_category openvz&amp;quot;&lt;br /&gt;
        echo &amp;quot;graph_info This graph shows OpenVZ: $ATTRIBUTE&amp;quot;&lt;br /&gt;
        vzlist -a -H -o hostname | awk '{gsub(/\./,&amp;quot;_&amp;quot;,$1)&lt;br /&gt;
        print(&amp;quot;'$ATTRIBUTE'&amp;quot;$1&amp;quot;.label &amp;quot;$1&amp;quot;\n&amp;quot; \&lt;br /&gt;
        &amp;quot;'$ATTRIBUTE'&amp;quot;$1&amp;quot;.info '$ATTRIBUTE' for VE&amp;quot;$1)}'&lt;br /&gt;
        exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
vzlist -a -H -o hostname,$ATTRIBUTE | awk '{gsub(/\./,&amp;quot;_&amp;quot;,$1)&lt;br /&gt;
         print(&amp;quot;'$ATTRIBUTE'&amp;quot;$1&amp;quot;.value &amp;quot;$2)}'&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=9283</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=9283"/>
		<updated>2010-10-29T10:40:21Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* Using udev anyway */  /dev/random was missing&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 ssh 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;
{{Note|Do 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 &amp;quot;catch the latest changes&amp;quot; which is faster.}}&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 --numeric-owner -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;
&lt;br /&gt;
 sed -i -e 's/^[0-9].*getty.*tty/#&amp;amp;/g'  /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;
 ln -sf /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 lines for &amp;lt;code&amp;gt;/dev/pts&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; and such):&lt;br /&gt;
&lt;br /&gt;
 mv /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 egrep '/dev/pts|/dev/shm|/proc|/sys' /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;
==== Using udev anyway ====&lt;br /&gt;
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&lt;br /&gt;
 mkdir /vz/private/123/etc/udev/devices&lt;br /&gt;
 /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&lt;br /&gt;
 /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&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 SERVICENAME off &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;
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or&lt;br /&gt;
/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:&lt;br /&gt;
 mv ifdown-venet SKIP.ifdown-venet&lt;br /&gt;
&lt;br /&gt;
Failing to do this will prevent networking from starting up correctly in the container.&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;
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009&lt;br /&gt;
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}&lt;br /&gt;
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)&lt;br /&gt;
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)&lt;br /&gt;
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC) &lt;br /&gt;
* Redhat 4 -- 20:32, 18 August 2010 (UTC)&lt;br /&gt;
* Fedora 4 -- 15:06, 20 August 2010 (UTC)&lt;br /&gt;
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010 &lt;br /&gt;
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=9282</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=9282"/>
		<updated>2010-10-29T10:37:48Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* /etc/init.d services */  Fix chkconfig invocation - previous invocation would result in the service being re-enabled when the package was upgraded (e.g. security fix etc.)....&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 ssh 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;
{{Note|Do 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 &amp;quot;catch the latest changes&amp;quot; which is faster.}}&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 --numeric-owner -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;
&lt;br /&gt;
 sed -i -e 's/^[0-9].*getty.*tty/#&amp;amp;/g'  /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;
 ln -sf /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 lines for &amp;lt;code&amp;gt;/dev/pts&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; and such):&lt;br /&gt;
&lt;br /&gt;
 mv /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 egrep '/dev/pts|/dev/shm|/proc|/sys' /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;
==== Using udev anyway ====&lt;br /&gt;
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&lt;br /&gt;
 mkdir /vz/private/123/etc/udev/devices&lt;br /&gt;
 /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 urandom zero ram0&lt;br /&gt;
 /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 urandom zero ram0&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 SERVICENAME off &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;
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or&lt;br /&gt;
/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:&lt;br /&gt;
 mv ifdown-venet SKIP.ifdown-venet&lt;br /&gt;
&lt;br /&gt;
Failing to do this will prevent networking from starting up correctly in the container.&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;
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009&lt;br /&gt;
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}&lt;br /&gt;
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)&lt;br /&gt;
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)&lt;br /&gt;
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC) &lt;br /&gt;
* Redhat 4 -- 20:32, 18 August 2010 (UTC)&lt;br /&gt;
* Fedora 4 -- 15:06, 20 August 2010 (UTC)&lt;br /&gt;
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010 &lt;br /&gt;
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=9280</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=9280"/>
		<updated>2010-10-28T16:11:02Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* /etc/fstab */&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 ssh 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;
{{Note|Do 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 &amp;quot;catch the latest changes&amp;quot; which is faster.}}&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 --numeric-owner -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;
&lt;br /&gt;
 sed -i -e 's/^[0-9].*getty.*tty/#&amp;amp;/g'  /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;
 ln -sf /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 lines for &amp;lt;code&amp;gt;/dev/pts&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; and such):&lt;br /&gt;
&lt;br /&gt;
 mv /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 egrep '/dev/pts|/dev/shm|/proc|/sys' /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;
==== Using udev anyway ====&lt;br /&gt;
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&lt;br /&gt;
 mkdir /vz/private/123/etc/udev/devices&lt;br /&gt;
 /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 urandom zero ram0&lt;br /&gt;
 /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 urandom zero ram0&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;
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or&lt;br /&gt;
/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:&lt;br /&gt;
 mv ifdown-venet SKIP.ifdown-venet&lt;br /&gt;
&lt;br /&gt;
Failing to do this will prevent networking from starting up correctly in the container.&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;
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009&lt;br /&gt;
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}&lt;br /&gt;
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)&lt;br /&gt;
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)&lt;br /&gt;
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC) &lt;br /&gt;
* Redhat 4 -- 20:32, 18 August 2010 (UTC)&lt;br /&gt;
* Fedora 4 -- 15:06, 20 August 2010 (UTC)&lt;br /&gt;
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010 &lt;br /&gt;
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=9279</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=9279"/>
		<updated>2010-10-28T16:09:53Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* /etc/mtab */  Tidy, remove useless rm&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 ssh 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;
{{Note|Do 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 &amp;quot;catch the latest changes&amp;quot; which is faster.}}&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 --numeric-owner -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;
&lt;br /&gt;
 sed -i -e 's/^[0-9].*getty.*tty/#&amp;amp;/g'  /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;
 ln -sf /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 lines for &amp;lt;code&amp;gt;/dev/pts&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; and such):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 egrep '/dev/pts|/dev/shm|/proc|/sys' /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;
==== Using udev anyway ====&lt;br /&gt;
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&lt;br /&gt;
 mkdir /vz/private/123/etc/udev/devices&lt;br /&gt;
 /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 urandom zero ram0&lt;br /&gt;
 /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 urandom zero ram0&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;
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or&lt;br /&gt;
/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:&lt;br /&gt;
 mv ifdown-venet SKIP.ifdown-venet&lt;br /&gt;
&lt;br /&gt;
Failing to do this will prevent networking from starting up correctly in the container.&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;
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009&lt;br /&gt;
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}&lt;br /&gt;
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)&lt;br /&gt;
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)&lt;br /&gt;
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC) &lt;br /&gt;
* Redhat 4 -- 20:32, 18 August 2010 (UTC)&lt;br /&gt;
* Fedora 4 -- 15:06, 20 August 2010 (UTC)&lt;br /&gt;
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010 &lt;br /&gt;
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Physical_to_container&amp;diff=9278</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=9278"/>
		<updated>2010-10-28T16:08:33Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: /* /etc/inittab */  Change sed to comment out, not nuke in case you ever want to reverse etc.&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 ssh 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;
{{Note|Do 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 &amp;quot;catch the latest changes&amp;quot; which is faster.}}&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 --numeric-owner -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;
&lt;br /&gt;
 sed -i -e 's/^[0-9].*getty.*tty/#&amp;amp;/g'  /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 lines for &amp;lt;code&amp;gt;/dev/pts&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; and such):&lt;br /&gt;
&lt;br /&gt;
 cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old&lt;br /&gt;
 egrep '/dev/pts|/dev/shm|/proc|/sys' /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;
==== Using udev anyway ====&lt;br /&gt;
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&lt;br /&gt;
 mkdir /vz/private/123/etc/udev/devices&lt;br /&gt;
 /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 urandom zero ram0&lt;br /&gt;
 /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 urandom zero ram0&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;
If the files /vz/private/{CTID}/etc/sysconfig/network-scripts/ifdown-venet or&lt;br /&gt;
/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:&lt;br /&gt;
 mv ifdown-venet SKIP.ifdown-venet&lt;br /&gt;
&lt;br /&gt;
Failing to do this will prevent networking from starting up correctly in the container.&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;
* CentOS 5.3 (Apache2, Mysql, Cacti) --[[User:kofl|kofl]] September 12 2009&lt;br /&gt;
* Scientific Linux 3.0.9 (Macrovision FLEXlm) {{unsigned|137.226.90.94|11:34, 4 November 2009}}&lt;br /&gt;
* Red Hat Enterprise Linux 4 (rhel4) --[[User:Bpuklich|Bpuklich]] 17:20, 15 February 2010 (UTC)&lt;br /&gt;
* Debian SID up-to-date with apache2, MySQL, posgrey etc. --nyquist 14:04, 06 July 2010 (UTC)&lt;br /&gt;
* Centos 5.x with Plesk -- 05:33, 17 August 2010 (UTC) &lt;br /&gt;
* Redhat 4 -- 20:32, 18 August 2010 (UTC)&lt;br /&gt;
* Fedora 4 -- 15:06, 20 August 2010 (UTC)&lt;br /&gt;
* Fedora 9 x64 with FDS and samba PDC --burn 23:20 10 October 2010 &lt;br /&gt;
* Fedora 3 x32 with Plesk -- 23 October 2010 --[[User:Rexwickham|Rex Wickham (2020media.com)]] 13:15, 23 October 2010 (UTC)&lt;br /&gt;
[[Category:HOWTO]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Container_enter_failed&amp;diff=7306</id>
		<title>Container enter failed</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Container_enter_failed&amp;diff=7306"/>
		<updated>2009-05-08T16:02:47Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Problem''': container created succesfully and started.&lt;br /&gt;
But when trying to do&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl enter 101 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
you get&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
container enter failed(?)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using strace, you see:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# strace -ff vzctl enter&lt;br /&gt;
....&lt;br /&gt;
fstat64(...st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0)...) fail&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Solution''':&lt;br /&gt;
Recompile the kernel with the following option:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONFIG_LEGACY_PTYS=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Other solutions''':&lt;br /&gt;
&lt;br /&gt;
1) enter the VE  manually creating the LEGACY_PTYS devices&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl exec  101 /sbin/MAKEDEV tty&lt;br /&gt;
vzctl exec 101 /sbin/MAKEDEV pty&lt;br /&gt;
vzctl enter 101&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2A) If you want udev in VE,  save the changes forcing udev to make LEGACY_PTYS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;gt; /etc/udev/makedev.d/51-udev.nodes&lt;br /&gt;
# These device have to be created manually&lt;br /&gt;
tty0&lt;br /&gt;
tty1&lt;br /&gt;
tty2&lt;br /&gt;
tty3&lt;br /&gt;
....&lt;br /&gt;
ttyp0&lt;br /&gt;
ttyp1&lt;br /&gt;
ttyp2&lt;br /&gt;
ttyp3&lt;br /&gt;
....&lt;br /&gt;
ptyp0&lt;br /&gt;
ptyp1&lt;br /&gt;
ptyp2&lt;br /&gt;
ptyp3&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2B) If you think is better disable udev in VE, comment out in the VE the line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/sbin/start_udev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
in&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/rc.d/rc.sysinit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
.. &amp;lt;b&amp;gt;however&amp;lt;/b&amp;gt; updates to the package which owns this file may revert your changes, so you must take steps to guard against this.&lt;br /&gt;
&lt;br /&gt;
Restart the VE and make the devices with MAKEDEV:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl exec  101 /sbin/MAKEDEV tty&lt;br /&gt;
vzctl exec 101 /sbin/MAKEDEV pty&lt;br /&gt;
vzctl enter 101&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I have used this method also to create zap dummy devices for asterisk in VE:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/dev/zap/ctl&lt;br /&gt;
/dev/zap/pseudo&lt;br /&gt;
/dev/zap/channel&lt;br /&gt;
/dev/zap/timer&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2C) The devices can be setup also with a line in VE config&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grep DEV /etc/vz/conf/101.conf&lt;br /&gt;
DEVNODES=&amp;quot;zap/ctl:rw zap/channel:rw zap/pseudo:rw zap/timer:rw &amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* {{Bug|130}}&lt;br /&gt;
* {{Bug|578}}&lt;br /&gt;
&lt;br /&gt;
[[Category: Troubleshooting]]&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Creating_a_CentOS_5.0_Template&amp;diff=6529</id>
		<title>Creating a CentOS 5.0 Template</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Creating_a_CentOS_5.0_Template&amp;diff=6529"/>
		<updated>2008-10-16T16:53:40Z</updated>

		<summary type="html">&lt;p&gt;TimSmall: Add link to page with instructions for bootstrapping a centos rootfs using yum.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
{{wikify}}&lt;br /&gt;
&lt;br /&gt;
# Install a system (virtual or physical) with the default CentOS installation that you wish to package. This could be a minimal distro or the default distro or even something custom.&lt;br /&gt;
## It's generally quicker to bootstrap a CentOS system on another yum/rpm-based, or Debian based system by following the instructions in [http://faiwiki.informatik.uni-koeln.de/index.php/FAI_multi-distribution#bootstrapping_the_base_images__for_other_distributions]&lt;br /&gt;
# Once the OS has been installed, you need to '''tar''' the contents of the OS.&lt;br /&gt;
## First, create a file called '''/tmp/exclude''' and add the following lines to it:&lt;br /&gt;
#:  .bash_history&lt;br /&gt;
#:  lost+found&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;
## Now, tar the OS file up by typing: '''tar –czvf /tmp/centos-5.0-&amp;lt;ARCH&amp;gt;-&amp;lt;DISTRO&amp;gt;-image.tar.gz –X /tmp/exclude''' where &amp;lt;'''ARCH'''&amp;gt; represents the system architecture ('''i386''' or &lt;br /&gt;
#: '''x86_64''') and &amp;lt;'''DISTRO'''&amp;gt; represents the distribution (default, minimal, etc.).&lt;br /&gt;
## Now transfer the file over to the OpenVZ server into '''/vz/template/cache''' folder.&lt;br /&gt;
# On the OpenVZ server create a “dummy” container by creating a folder called '''/vz/private/50''' &lt;br /&gt;
#: and copying the '''/etc/vz/conf/ve-vps.basic.conf-sample''' to '''/etc/vz/conf/50.conf'''.&lt;br /&gt;
#: '''NOTE''': 50 is the CTID for the container. You can choose any unused CTID on the OpenVZ server.&lt;br /&gt;
# Now create a new folder called '''/vz/template/centos/5.0/&amp;lt;ARCH&amp;gt;/config''' again where &lt;br /&gt;
#: &amp;lt;'''ARCH'''&amp;gt; represents the system architecture.&lt;br /&gt;
# Create a file in the folder called rpm and add the following line:&lt;br /&gt;
#:  43&lt;br /&gt;
# Create a file called '''yum.conf''' in the folder and add the following lines:&lt;br /&gt;
#:  [main]&lt;br /&gt;
#:  &lt;br /&gt;
#:  cachedir=/vz/template/centos/5.0/&amp;lt;ARCH&amp;gt;/yum-cache/&lt;br /&gt;
#:  &lt;br /&gt;
#:  reposdir=/dev/null&lt;br /&gt;
#:  &lt;br /&gt;
#:  installonlypkgs=&lt;br /&gt;
#:  &lt;br /&gt;
#:  [centos5-base]&lt;br /&gt;
#:  name=CentOS 5 - &amp;lt;ARCH&amp;gt; - Base&lt;br /&gt;
#:  &lt;br /&gt;
#:  baseurl=http://mirror.centos.org/centos/5/os/&amp;lt;ARCH&amp;gt;/&lt;br /&gt;
#:  &lt;br /&gt;
#:  enabled=1&lt;br /&gt;
#:  &lt;br /&gt;
#:  gpgcheck=1&lt;br /&gt;
#:  &lt;br /&gt;
#:  [centos5-updates-released]&lt;br /&gt;
#:  &lt;br /&gt;
#:  name=CentOS 5 - &amp;lt;ARCH&amp;gt; - Released Updates&lt;br /&gt;
#:  &lt;br /&gt;
#:  baseurl=http://mirror.centos.org/centos/5/updates/&amp;lt;ARCH&amp;gt;/&lt;br /&gt;
#:  &lt;br /&gt;
#:  enabled=1&lt;br /&gt;
#:  &lt;br /&gt;
#:  gpgcheck=1&lt;br /&gt;
# Copy '''/etc/vz/dists/centos-4.conf''' to '''/etc/vz/dists/centos-5.0.conf'''.&lt;br /&gt;
# Change to the '''/vz/private/50''' folder and then run the command '''gunzip –dc /vz/template/cache/centos-5.0-&amp;lt;ARCH&amp;gt;-&amp;lt;DISTRO&amp;gt;-image.tar.gz | tar –xvf''' – to unpack the base image to the folder.&lt;br /&gt;
# Make sure you are in the '''/vz/private/50''' folder.&lt;br /&gt;
# Edit '''etc/shadow''' and remove the replace the '''root''' password with !! instead of the hashed value.&lt;br /&gt;
# Edit the '''etc/inittab''' file and comment out the lines that respawn '''/sbin/mingetty''' on '''tty1''' through '''tty6'''. Just put a # at the beginning of the line.&lt;br /&gt;
# Remove the '''etc/mtab''' file and then create a symbolic link by typing '''ln –s /proc/mounts etc/mtab'''.&lt;br /&gt;
# Remove all of the lines from '''etc/fstab''' except for the line that mounts '''/dev/pts'''.&lt;br /&gt;
# Edit '''etc/rc.d/rc.sysinit''' and comment out the line that starts '''/sbin/start_udev''' by placing a # at the beginning of the line.&lt;br /&gt;
# Now create device nodes by typing:&lt;br /&gt;
#:  mknod dev/ptmx c 5 2&lt;br /&gt;
#:  mkdir dev/pts&lt;br /&gt;
#:  /sbin/MAKEDEV –d /vz/private/50/dev ttyp ptyp&lt;br /&gt;
#:  mknod dev/null c 1 3&lt;br /&gt;
#:  mknod dev/urandom c 1 9&lt;br /&gt;
# Create the '''var/lock/rpm''' folder.&lt;br /&gt;
# If you wish to disable IPv6, do the following:&lt;br /&gt;
## Edit '''etc/sysconfig/network''' and set '''NETWORKING_IPV6''' to '''no'''.&lt;br /&gt;
## Add the following lines to '''etc/modprobe.d/blacklist''':&lt;br /&gt;
#:  blacklist ipv6&lt;br /&gt;
#:  blacklist net-pf-10&lt;br /&gt;
# Disable any physical NICs by modifying the '''etc/sysconfig/network-scripts/ifcfg-ethX''' files (where '''X''' is the interface number starting from '''0''') and setting '''ONBOOT''' to '''no'''.&lt;br /&gt;
# Now you’re ready to start the template. Type '''vzctl start 50''' and wait for it to start.&lt;br /&gt;
# You can install additional packages into the container by typing '''vzyum 50 install &amp;lt;package&amp;gt;''' at the prompt where &amp;lt;'''package'''&amp;gt; represents the name of the software package you wish to install.&lt;br /&gt;
# Finally, you should turn off unnecessary services.&lt;br /&gt;
## Enter the container by typing '''vzctl enter 50'''.&lt;br /&gt;
## View the services that are set to run at startup by typing '''chkconfig --list | grep 5:on'''.&lt;br /&gt;
## Disable any unwanted service by typing '''chkconfig --levels 2345 &amp;lt;service&amp;gt;''' off where &amp;lt;'''service'''&amp;gt; represents the service to disable.&lt;br /&gt;
#: Services that you can (and should) turn off without harm are acpid, apmd, kudzu, and  microcode_ctl.&lt;br /&gt;
# Exit the container by typing '''exit''' at the prompt.&lt;br /&gt;
# Stop the container by typing '''vzctl stop 50'''.&lt;br /&gt;
# Finally, package up the new template by typing '''tar –czvf /vz/template/cache/centos-5.0-&amp;lt;ARCH&amp;gt;-&amp;lt;DISTRO&amp;gt;.tar.gz'''.&lt;br /&gt;
# The template is ready for use.&lt;/div&gt;</summary>
		<author><name>TimSmall</name></author>
		
	</entry>
</feed>