Here are the steps that need to be taken to change the ID of an OpenVZ Container. OpenVZ is a virtualization technology for Linux.
Method 1: Use a checkpoint and rename the container directories on the shell
In this example, I will change the ID of a Container from 101 to 102. Container ID's should always be > 100, so 101 is normally the first ID used for a VM.
The first step is to create a checkpoint of the VM:
vzctl chkpnt 101 --dumpfile /tmp/ovz-101.dump
Then move the files of the container to 102:
mv /etc/vz/conf/101.conf /etc/vz/conf/102.conf mv /vz/private/101 /vz/private/102 mv /vz/root/101 /vz/root/102
Finally restore the checkpoint:
vzctl restore 102 --dumpfile /tmp/ovz-101.dump
Method 2: Use a vzdump backup
An alternative method is to use the vzdump command to create a backup and restore it with vzrestore under a new ID.
Create the backup directory:
mkdir /home/backup chmod 700 /home/backup chown root:root /home/backup
Backup the container with ID 101:
vzdump --compress --dumpdir /home/backup 101
Restore the backup with container ID 102:
vzrestore /home/backup/vzdump-101.tgz 102
Now shutdown container 101 and start 102:
vzctl stop 101 vzctl start 102
Test that container 102 is fully working. Afterwards, you can delete container 101:
vzctl destroy 101