Editing Physical to container
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
A rough description of how to migrate existing physical server into a [[container]]. | A rough description of how to migrate existing physical server into a [[container]]. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Prepare a new “empty” container == | == Prepare a new “empty” container == | ||
For OpenVZ this would mean the following (assume you chose CT ID of 123): | For OpenVZ this would mean the following (assume you chose CT ID of 123): | ||
− | + | ||
mkdir /vz/root/123 /vz/private/123 | mkdir /vz/root/123 /vz/private/123 | ||
− | cat /etc/vz/conf/ve-basic.conf-sample > /etc/vz/conf/123.conf | + | cat /etc/vz/conf/ve-vps.basic.conf-sample > /etc/vz/conf/123.conf |
− | |||
− | |||
− | + | == Preparing to migrate == | |
+ | |||
+ | Stop most services on a machine to be migrated. “Most” means services such as web server, databases and the like — so you will not lose your data. Just leave the bare minimum (including ssh daemon). | ||
== Copying the data == | == Copying the data == | ||
Line 25: | Line 17: | ||
=== rsync === | === rsync === | ||
− | + | rsync example (run from the new HN): | |
− | + | rsync -arvpz --numeric-ids --exclude dev --exclude proc --exclude tmp -e "ssh -l root@a.b.c.d" root@a.b.c.d:/ /vz/private/123/ | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | rsync - | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
'''Advantage:''' Your system doesn't really go down. | '''Advantage:''' Your system doesn't really go down. | ||
− | |||
− | |||
=== Live CD === | === Live CD === | ||
Line 70: | Line 39: | ||
Then create the tar. But remember, when the system is 'not' using udev, you have to look into /proc/ after creating your container because some devices might not exist. (/dev/ptmx or others) | Then create the tar. But remember, when the system is 'not' using udev, you have to look into /proc/ after creating your container because some devices might not exist. (/dev/ptmx or others) | ||
− | # tar | + | # tar cjpf /tmp/mysystem.tar.bz2 / -X /tmp/excludes.excl |
Naturally, you can only do this when the critical services (MySQL, apache, ..) are stopped and your /tmp filesystem is big enough to contain your tar. | Naturally, you can only do this when the critical services (MySQL, apache, ..) are stopped and your /tmp filesystem is big enough to contain your tar. | ||
Line 80: | Line 49: | ||
=== OSTEMPLATE === | === OSTEMPLATE === | ||
You have to add <code>OSTEMPLATE=xxx</code> line to <code>/etc/vz/conf/123.conf</code> file, where <code>xxx</code> would be distribution name (like <code>debian-3.0</code>) for vzctl to be able to make changes specific for this distribution. | You have to add <code>OSTEMPLATE=xxx</code> line to <code>/etc/vz/conf/123.conf</code> file, where <code>xxx</code> would be distribution name (like <code>debian-3.0</code>) for vzctl to be able to make changes specific for this distribution. | ||
− | |||
− | |||
=== IP address(es) === | === IP address(es) === | ||
Line 100: | Line 67: | ||
A container does not have real ttys, so you have to disable getty in <code>/etc/inittab</code> (i. e. <code>/vz/private/123/etc/inittab</code>). | A container does not have real ttys, so you have to disable getty in <code>/etc/inittab</code> (i. e. <code>/vz/private/123/etc/inittab</code>). | ||
− | + | sed -i -e '/getty/d' /vz/private/123/etc/inittab | |
− | sed -i -e ' | ||
=== /etc/mtab === | === /etc/mtab === | ||
Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, for <code>df</code> to work properly: | Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, for <code>df</code> to work properly: | ||
− | ln - | + | rm -f /vz/private/123/etc/mtab |
+ | ln -s /proc/mounts /vz/private/123/etc/mtab | ||
{{out|The problem here is container's root filesystem (<code>/</code>) is mounted not from the container itself, but rather from the host system. That leaves <code>/etc/mtab</code> in container without a record for <code>/</code> being mounted, thus df doesn't show it. By linking <code>/etc/mtab → /proc/mounts</code> we make sure /etc/mtab shows what is really mounted in a container. | {{out|The problem here is container's root filesystem (<code>/</code>) is mounted not from the container itself, but rather from the host system. That leaves <code>/etc/mtab</code> in container without a record for <code>/</code> being mounted, thus df doesn't show it. By linking <code>/etc/mtab → /proc/mounts</code> we make sure /etc/mtab shows what is really mounted in a container. | ||
Line 113: | Line 80: | ||
=== /etc/fstab === | === /etc/fstab === | ||
− | Since you do not have any real disk partitions in a container, /etc/fstab (or most part of it) is no longer needed. Empty it (excluding the | + | Since you do not have any real disk partitions in a container, /etc/fstab (or most part of it) is no longer needed. Empty it (excluding the line for /dev/pts): |
− | + | ||
− | + | cp /vz/private/123/etc/fstab /vz/private/123/etc/fstab.old | |
− | + | grep devpts /vz/private/123/etc/fstab.old > /vz/private/123/etc/fstab | |
− | |||
You can also mount a devpts in a running (but not fully functional) container: | You can also mount a devpts in a running (but not fully functional) container: | ||
vzctl exec 123 mount -t devpts none /dev/pts | vzctl exec 123 mount -t devpts none /dev/pts | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== /dev === | === /dev === | ||
− | |||
==== Introduction: static /dev ==== | ==== Introduction: static /dev ==== | ||
Line 138: | Line 94: | ||
Note that in some distributions <code>/dev</code> is mounted on <code>tmpfs</code> — this will not work in case of static <code>/dev</code>. So what you need to do is find out where <code>/dev</code> is being mounted on <code>tmpfs</code> and remove this. This is highly distribution-dependent; please add info for your distro here. | Note that in some distributions <code>/dev</code> is mounted on <code>tmpfs</code> — this will not work in case of static <code>/dev</code>. So what you need to do is find out where <code>/dev</code> is being mounted on <code>tmpfs</code> and remove this. This is highly distribution-dependent; please add info for your distro here. | ||
− | |||
− | |||
After you made sure your <code>/dev</code> is static, populate it with needed device nodes. | After you made sure your <code>/dev</code> is static, populate it with needed device nodes. | ||
Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by <code>umask</code> ([[w:umask]]). You can use --mode option for <code>mknod</code> to set the desired permissions. | Please pay attention to the access permissions of the device files being created: a default file mode for newly created files is affected by <code>umask</code> ([[w:umask]]). You can use --mode option for <code>mknod</code> to set the desired permissions. | ||
− | |||
− | |||
==== tty device nodes ==== | ==== tty device nodes ==== | ||
Line 178: | Line 130: | ||
Check that /dev/urandom exists. If it does not, create with: | Check that /dev/urandom exists. If it does not, create with: | ||
mknod --mode 444 /vz/private/123/dev/urandom c 1 9 | mknod --mode 444 /vz/private/123/dev/urandom c 1 9 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===/proc=== | ===/proc=== | ||
− | |||
− | |||
Make sure the /proc directory exists: | Make sure the /proc directory exists: | ||
ls -la /vz/private/123/ | grep proc | ls -la /vz/private/123/ | grep proc | ||
Line 196: | Line 140: | ||
=== /etc/init.d services === | === /etc/init.d services === | ||
− | Some system services can (or in some cases should) be disabled | + | Some system services can (or in some cases should) be disabled. A few good candidates are: |
* acpid, amd (not needed) | * acpid, amd (not needed) | ||
Line 208: | Line 152: | ||
* lm_sensors (container does not have access to hardware sensors) | * lm_sensors (container does not have access to hardware sensors) | ||
* microcodectl (container can not update CPU microcode) | * microcodectl (container can not update CPU microcode) | ||
− | * netplugd (container does not have real Ethernet device | + | * netplugd (container does not have real Ethernet device) |
− | |||
− | |||
− | |||
− | |||
To see which services are enabled: | To see which services are enabled: | ||
Line 221: | Line 161: | ||
To disable the service: | To disable the service: | ||
− | * RedHat/Fedora/SUSE: <code>/sbin/chkconfig SERVICENAME | + | * RedHat/Fedora/SUSE: <code>/sbin/chkconfig --del SERVICENAME </code> |
* Debian: <code>' update-rc.d -f hdparm remove '</code> | * Debian: <code>' update-rc.d -f hdparm remove '</code> | ||
* Gentoo: <code>/sbin/rc-update del SERVICENAME</code> | * Gentoo: <code>/sbin/rc-update del SERVICENAME</code> | ||
Line 233: | Line 173: | ||
Make the following look like this: | Make the following look like this: | ||
ONBOOT=no | ONBOOT=no | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== Debian/Ubuntu ==== | ==== Debian/Ubuntu ==== | ||
Line 251: | Line 185: | ||
iface lo inet loopback | iface lo inet loopback | ||
− | iface eth0 inet | + | iface eth0 inet dhcp |
address 10.0.0.4 | address 10.0.0.4 | ||
netmask 255.0.0.0 | netmask 255.0.0.0 | ||
Line 259: | Line 193: | ||
You can either comment out the eth* interface stanza(s), or take it out of the "auto" line(s). | You can either comment out the eth* interface stanza(s), or take it out of the "auto" line(s). | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== openSUSE/SLES ==== | ==== openSUSE/SLES ==== | ||
Use Yast. | Use Yast. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Other adjustments === | === Other adjustments === | ||
Line 294: | Line 208: | ||
Now check that everything works fine. If not, see [[#Troubleshooting]] below. | Now check that everything works fine. If not, see [[#Troubleshooting]] below. | ||
− | |||
== Troubleshooting == | == Troubleshooting == | ||
Line 303: | Line 216: | ||
mkdir tmp | mkdir tmp | ||
− | chmod | + | chmod 777 tmp |
+ | |||
=== Can't enter container === | === Can't enter container === | ||
Line 329: | Line 243: | ||
If anything goes wrong, try to find out why and fix. If you have enough Linux experience, it can be handled. Also check out IRC and please report back on this page. | If anything goes wrong, try to find out why and fix. If you have enough Linux experience, it can be handled. Also check out IRC and please report back on this page. | ||
− | + | == Success Stories == | |
− | |||
− | |||
− | |||
− | |||
− | == Success | ||
− | |||
− | |||
* Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST) | * Debian 3.1 Sarge with MySQL, apache2, PowerDNS --[[User:Stoffell|stoffell]] 08:41, 8 February 2007 (EST) | ||
* Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST) | * Red Hat 7.2 with MySQL 3.23, apache, Chilisoft --[[User:Stoffell|stoffell]] 13:26, 9 February 2007 (EST) | ||
* Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST) | * Gentoo with Courier, Postfix, MySQL, Apache2 --[[User:bfrackie|bfrackie]] 19:00, 18 March 2007 (EST) | ||
− | * AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] | + | * AltLinux Master with qmail, MySQL, Apache, etc - to Debian/testing with OpenVZ --[[User:alexkuklin|alexkuklin]] |
− | * Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] | + | * Centos 4.4 with apache2, SVN, TRAC, etc. --[[User:bitherder|bitherder]] |
− | * Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] | + | * Centos 4.6 with apache2, Tomcat 5.0.x, postgresql, etc on CentOS 5.1 64bit Host --[[User:laslos|laslos]] |
− | * Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] | + | * Debian Etch with apache2 etc... on CentOS 4.6 Host --[[User:laslos|laslos]] |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:HOWTO]] | [[Category:HOWTO]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |