Cloning a Virtual Server with OpenVZ

by Mike on May 17, 2009

in Virtualization

There may be many reasons for cloning a VPS.  It could be to backup a server or it could be to have a template that makes it easy to create a new server.

Cloning a VPS to Create a New Server
A common goal would be to have a server set up exactly like you want and then clone it in less than five minutes have a new one running that is the same.  The best way to do this is to create a VPS and configure it exactly like you need.  That means you must install all of the necessary programs and modify them so they are working like you want.  Set up the security and networking as well.  Once you have a running VPS, then make sure it is turned off to clone it.

In this example, a VPS 26 is cloned to create 27.  The data that you will create for a VPS is located in the /vz/private/ directory.  Be sure to use the switch -a when you use cp as it is important in getting the permissions right.  The -a options maintains all of the archival attributes which is very important.

cp -a /vz/private/26 /vz/private/27

Next you need to copy the configuration for the VPS so that all of the settings are available.  The configuration files are found in /etc/vz/conf.  Once you have copied the configuration file over you will need to edit two lines:
HOSTNAME=”admin26″
IP_ADDRESS=”192.168.4.26″

These two lines are important to set up the correct IP Address and the hostname to distinguish the virtual servers.

cp /etc/vz/conf/26.conf /etc/vz/conf/27.conf

#  Copyright (C) 2000-2007 SWsoft. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

ONBOOT=”yes”

# UBC parameters (in form of barrier:limit)
# Primary parameters
AVNUMPROC=”40:40″
NUMPROC=”65:65″
NUMTCPSOCK=”80:80″
NUMOTHERSOCK=”80:80″
VMGUARPAGES=”6144:2147483647″
# Secondary parameters
KMEMSIZE=”2752512:2936012″
TCPSNDBUF=”319488:524288″
TCPRCVBUF=”319488:524288″
OTHERSOCKBUF=”132096:336896″
DGRAMRCVBUF=”132096:132096″
OOMGUARPAGES=”6144:2147483647″
# Auxiliary parameters
LOCKEDPAGES=”32:32″
SHMPAGES=”8192:8192″
PRIVVMPAGES=”49152:53575″
NUMFILE=”2048:2048″
NUMFLOCK=”100:110″
NUMPTY=”16:16″
NUMSIGINFO=”256:256″
DCACHESIZE=”1048576:1097728″

PHYSPAGES=”0:2147483647″
NUMIPTENT=”128:128″

# Disk quota parameters (in form of softlimit:hardlimit)
DISKSPACE=”1048576:1153434″
DISKINODES=”200000:220000″
QUOTATIME=”0″

# CPU fair sheduler parameter
CPUUNITS=”1000″
VE_ROOT=”/vz/root/$VEID”
VE_PRIVATE=”/vz/private/$VEID”
OSTEMPLATE=”centos-4-i386-default”
ORIGIN_SAMPLE=”vps.basic”
HOSTNAME=”admin26″
IP_ADDRESS=”192.168.4.26″
NAMESERVER=”12.32.34.32″

Once this is complete and you have saved it you may start the VPS.

Previous post:

Next post: