Converting Containers to Virtual Machines with the c2v-convert Tool
The c2v-convert tool converts a Virtuozzo Server 7 system container to a virtual machine. This tool is tested to work with containers based on the following operating systems:
- AlmaLinux 9
- AlmaLinux 8
- CentOS 9
- CentOS 8
- CentOS 7
- Debian 12
- Debian 11
- Debian 10
- RockyLinux 8
- Ubuntu 24.04
- Ubuntu 22.04
- Ubuntu 20.04
c2v-convert to access guest OS vendor repositories.To install c2v-convert, use the following command:
| |
Find below a list of options you can use when running the c2v-convert command.
| |
| Name | Description |
|---|---|
ct | The name of the container to be converted to a virtual machine. |
-h, --help | Provides a list of flags used with the c2v-convert command. |
--version | Specifies the program's version number. |
-q, --quiet | Skips the confirmation prompt and suppresses the output. Useful when calling from a script. |
-y, --yes | The system automatically selects Y for all requests. The -y option assumes Ask me later for data collection by CEP. |
-v, --verbose | The verbose mode provides detailed processing information. |
-b, --batch_log | Creates a batch log file that provides log records for the containers subject to conversion. |
--timeout TIMEOUT | The operation timeout in minutes [5..60]. By default, it is 30 minutes. |
--swap SWAP | The swap size in the target virtual machine in MB. The default value is 2,048 MB. |
--target-state {keep,start,stop} | This option specifies the desired target state of virtual machine(s) after conversion: 1. 2. 3. By default, the value of this option is |
--log LOG | The path to the directory to store log files. |
--temp TEMP | The path to the directory to store temporary files. By default, it is /vz/tmp. |
-f FROM_FILE, --from-file FROM_FILE | The path to the batch file. |
Operation
The container-to-virtual-machine conversion consists of 11 stages:
- Checking the configuration of the container to be converted.
- Checking disk consistency and snapshot presence. (If a container has snapshots, it may take longer to complete the conversion.)
- Installing
kernelandgrub. (The performance of this stage depends on the Internet speed.) - Creating a target virtual machine in a temporary directory.
- Converting the copies of the container’s disks to a virtual machine format.
- Connecting the disks to the target virtual machine.
- Configuring the target virtual machine’s network. (The network in the container is disconnected to avoid potential conflicts.)
- Installing Guest Tools on the target virtual machine.
- Executing the
virt-v2vscripts in the target virtual machine. - Starting the target virtual machine.
- The cleanup stage.
Conversion Time
The conversion time will depend on the node CPU and storage performance. Typically, a single container conversion completes within less than 5 minutes.
Conversion Fallback The resulting virtual machine acquires the name of the original container.
The source system container’s name will include the C2V_ prefix to identify the converted containers easily. The source system container is left in the stopped state without IP configuration as a fallback.
Interactive and Non-interactive Modes
You can convert containers in interactive and non-interactive modes:
- Interactive mode encompasses default settings and is used without any flags. Use this mode to test the conversion process or if you have a few containers to convert.
- Non-interactive mode is used when you have many containers to convert and want the system to do it automatically. For example, you can specify options, such as
-yand-v, etc., to instruct that the system automatically selectsyfor all requests and provides detailed processing information.
Example 1: Converting a Single Container in Interactive Mode
Converting a single container in the interactive mode is a good way to test the conversion process for the container types you have in your infrastructure. For example, you may have 40 containers based on Debian 9 and 120 containers based on CentOS 7, with half of CentOS 7 containers having MariaDB installed. You can set up new Debian 9, CentOS 7, and CentOS 7 containers with MariaDB containers and test the conversion. Alternatively, you can create three clones of each type and test the conversion using these clones.
To convert a single container with the name centos7 to a virtual machine in the interactive mode, run c2v-convert:
| |
Here is an example output:
| |
The new virtual machine acquires the name of the original container, and the system assigns the C2V_ prefix to the container’s name. After the conversion is complete, run prlctl list -a to confirm that the new virtual machine centos7 is present in the system:
Run prlctl list -a to view a list of available virtual environments:
| |
Execute prlctl list -i to receive information on the new virtual machine centos7:
| |
Use the prlctl start command to start the new virtual machine:
| |
Example 2: Converting Multiple Containers in Interactive Batch Mode
You can specify multiple containers when calling c2v-convert. In this case, the tool will run in batch mode and convert the containers sequentially. Use the interactive batch mode if you want to oversee the conversion process of multiple containers.
To convert two containers centos7_1 and centos7_2 to virtual machines in the interactive batch mode, run the following:
| |
In this mode, you will be prompted to confirm the conversion of both containers. The tool will convert them one after another in the order you specified them.
In the following example, we will convert two system containers to virtual machines and will not request a batch log file. Here is an example output of c2v-convert for two containers:
| |
Now, the output shows not only the conversion stage but also the currently processed and total number of containers to convert: Container [1/2] and Container [2/2]. It allows you to see how many containers have already been processed at a glance.
Logging in Batch Mode
If you specified more than one container to convert, c2v-convert will create a separate log file for each container in the working directory you started the conversion process. You may add the -b option to create a separate batch log file that will contain brief log information on each container and/or --log to specify the name of the folder to store log files with detailed information on each container:
| |
Conversion in Batch Mode Using GNU Screen
When converting containers in batch mode, we recommend using the GNU screen terminal program. It creates a virtual terminal persistent across SSH sessions and ensures a strong connection to the target host. With Screen, the program will continue working in the screen session in case of any SSH session disruption.
To start a screen session, run the following in your terminal:
| |
To detach from the screen session, execute Ctrl-a+d.
To reattach or resume your screen session, run as follows:
| |
Example 3: Converting Multiple Containers in Non-Interactive Batch Mode
The non-interactive batch mode is useful when converting many containers in a pre-defined maintenance window. Use the -y option to instruct the system to select y for all requests automatically. As with the interactive batch mode, we recommend starting c2v-convert in the non-interactive mode in the GNU screen.
Batch File
To simplify calling c2v-convert on large numbers of containers, we recommend preparing a batch file with container names or CTIDs that you want to convert during a maintenance window. The format of the batch file is as follows:
| |
It is possible to generate such a file based on the prlctl list output. For example, to create a batch file with the names of all containers apart from containers with Virtuozzo Automator, Virtuozzo Storage UI, and PowerPanel, use the following command:
| |
You can use different batch files for containers based on a specific template, end-user, or any other criteria you select. For example, if you confirmed a maintenance window with an end user owning 20 containers.
Example: Converting Containers in Unattended Mode Using Batch File
In this example, we want to convert all containers containing centos7 and dev in their names. We aligned the maintenance window with the users of said containers, and there are enough of them to justify running conversion in the quiet and unattended mode. We will create a batch file based on the prlctl list output and our filter and a batch log file to review once the conversion process ends.
We will be running the conversion in a screen session.
Create Batch File
To create a batch log file, we will use prlctl list and grep:
| |
Execute Conversion
Let’s open a screen session:
| |
Next, we will call c2v-convert by specifying the following:
- The
-qflag to run the conversion in quiet mode, i.e., without confirmation prompts and output. - The
-bflag to create a high-level batch log. -fto point the tool to the file with container names.
Here is the command:
| |
Because we are using quiet mode, nothing will be printed on the screen. Let’s detach from the screen session (Ctrl-a+d) and look at the batch log file:
| |
As we can see, the conversion process is underway. Running the conversion in quiet mode allows you to call it from external automation systems or scripts.
Troubleshooting
Running the Tool in Verbose Mode
In case the conversion process fails without a clear error message, rerun the conversion with the --verbose option:
| |
A verbose output provides much more information about the steps performed, which is useful for troubleshooting. Here is an example of c2v-convert running in the verbose mode:
| |
Falling Back to Converted Container in Case of Unsuccessful Conversion
If the conversion is a success, but the resulting virtual machine does not work as expected, you can:
Stop the converted virtual machine
centos7:1# prlctl stop centos7Assign the transferred IP address back to the converted container
C2V_centos7:1# prlctl set C2V_centos7 --device-add <venetX|netX> --ipadd <addr>Start the container:
1# prlctl start C2V_centos7
Locale-Related Errors on macOS
When running the c2v-convert utility on Virtuozzo Server, macOS users may encounter the locale-related error message while logging into Virtuozzo Server:
| |
During conversion, it may cause errors as follows:
| |
or
| |
To avoid this issue, add the following to the /etc/environment file on Virtuozzo Server and log into it again:
| |
Unmounted Disk After Conversion
If a container to be converted has additional disks, add information about the mount point of these disks in the configuration file unless it has been added before:
| |
Otherwise, the disk will be unmounted after conversion and will need to be mounted manually.
Usage Data Collection
The c2v-convert tool collects anonymous statistics about conversion attempts if the host where the tool is used participates in the Customer Experience Program (CEP). It helps Virtuozzo proactively identify issues in the tool’s operation. The system will not gather personal data, such as hostnames, IP addresses, names, etc. The hosts already enrolled in CEP will send conversion statistics by default. If the host with the tool used on it does not participate in CEP, no statistics will be collected.
Below is a list of data gathered by CEP:
- Unique identifier based on the CTID of the container subject to conversion
- Conversion attempt date
- Conversion result: success or failure. For failed conversions, the step where the conversion failed and the reason
- The container OS template of the attempted conversion
- The container App template of the attempted conversion
- The number and type of NICs attached to the container
- The number and size of disks attached to the container
- The execution time of the conversion
Here is an example of the collected data:
| |