Reese Knowledgebase

How to make a copy of a container and change the CTID / VEID

View Kristian Reese's profile on LinkedIn


If you like this article, please +1 or Recommend via FB with the provided buttons above:

Article ID: 125
by: Reese K.
Posted: 13 Sep, 2013
Last updated: 04 Dec, 2013
Views: 2272

How to make a copy of a Virtuozzo Container and change the VEID / CTID

Using vzmlocal

In this example, the CTID is 21273, and it is being relocated to a different directory on the same hwnode.

~# vzmlocal '21273:21273:/root/vz/private/$VEID' --online

To change both root and private areas, use this command.  This may be necessary if /vz is mounted over NFS and you don't want to have the local private area mounted to an NFS directory/mount point.  This example shows moving the container to /vzlocal

~# vzmlocal '16343:16343:/vzlocal/private/$VEID:/vzlocal/root/$VEID'

Do specity '$VEID', otherwise, the container number will be used in the /etc/vz/conf/CTID.conf file for the VE_PRIVATE parameter.

The vzmlocal man page shows how to create a clone.


       # vzmlocal -C 200:201
              Clone CT 200.  New CT will be numbered 201.  Disposition of its private and root areas will be autogenerated.

       # vzmlocal -C 200:202::/mnt/root202
              Clone CT 200.  New CT will be numbered 202 and its root area will reside under /mnt/root202

       # vzmlocal 300:301:/sda2/private/build_server
              Renumber CT 300 to 301 and move its private area under /sda2/private/build_server

       # vzmlocal 301:::/mnt/root/build_server
              Move root area of CT 301 under /mnt/root/build_server


Instead of deleting the text below, I've decided to keep it around for future reference.  This is how I've done this in the past as this is just one of those things that isn't done on a regular basis...

There may be other ways to do this, just as there are many ways to skin a cat in the realm of UNIX.  I've devised this procedure myself by reading the man pages and isn't something I need to do on a regular basis, so it hasn't been refined in any way.  Please comment for any suggested improvements or other ways you've found to do this:

Aside from creating a base container, stopping it, and untaring a copy of the container that's to be copied into the private area of the newly created base container, I decided to make use of vzbackup and vzrestore.

To illustrate the example, container 16844 is to be copied as we need to test  a software update, and it resides on hwnode vps12.  The process beings by making a backup of that container:

Backup Container

~# vzbackup -i -Cg vps12 -e 16844

-Cg    Compress the resulting CT backups with the gzip algorithm.
-e CT1 ...
       List of containers to back up. Back up all the Virtuozzo Containers if omitted.

Where is the backup being stored?

/etc/vzbackup.conf contains a parameter that defines the directory where all the backups will be stored:

       BACKUP_DIR
              Directory where all the backup files will be stored.

              Default: /vz/backups

              Example:
BACKUP_DIR=/vz/backups

If this needs to be changed, update BACKUP_DIR prior to running the vzbackup command.


Restore Container

Once the backup is finished, it can be restored to a new container ID.

~# vzrestore -e 16844:100

       -e CT1[:NEWCT1] ...
              List  of  containers  to restore. If NEWCT1 is specified, backup of Container CT1 is restored with that ID. Restore all the containers if omitted.

When I ran this, I was presented with some error about CTID 100 not existing, but irregardless, the restoration of the container completed as the vzrestore process first creates a temporary container to perform the inital restoration to.  The CTID of this temproary container is usually 100000000, and it can be changed to whatever CTID you want, as in my example, 100 by using the vzmlocal command:

Change VEID number

~# /usr/sbin/vzmlocal 100000000:100

All that's left to do is update /etc/vz/conf/100.conf with the new hostname and IP address of the cloned container and it's ready to be started.  If the source container remains online, please don't forget to change the IP before starting the clone or you'll run into a duplicate IP address assignment issue.

This article was:   Helpful | Not Helpful
Prev   Next
No buffer space available     Watch active MySQL queries as they come and go

RSS