To convert a VMDK disk to QCOW2 format for use with KVM or QEMU on Rocky Linux, you must run the qemu-img utility on the host system where the target VM will reside. ESXi cannot perform this conversion natively because it lacks the necessary user-space tools and does not support installing standard Linux packages like those required by QEMU. The process involves exporting the virtual disk from VMware, transferring it to the Rocky Linux host, and executing the conversion command locally.
Prerequisites and Environment Setup
Before initiating any disk conversion, ensure that your Rocky Linux environment is properly configured to handle virtualization tasks. You need access to the terminal as a user with sufficient privileges, typically root or a user with sudo rights. The core tool required isqemu-img, which is part of the qemu-common package. If this package is not already installed, you can install it using the DNF package manager.
Run the following command to ensure the necessary tools are present:
sudo dnf install qemu-common
Verify the installation by checking the version of the image utility:
qemu-img --version
This step is critical because ESXi operates as a closed hypervisor environment. It does not provide a shell interface for running general-purpose Linux utilities. Therefore, all preparation and execution must occur on the destination host running Rocky Linux, not within the VMware infrastructure. Attempting to run these commands inside an ESXi shell will result in errors due to missing binaries and restricted permissions.
Exporting the VMDK Disk
The first technical hurdle is extracting the raw virtual disk file from the VMware ecosystem. You cannot simply copy the VMDK file while the virtual machine is powered on, as this may lead to data corruption due to inconsistent state. Instead, power down the source virtual machine in vSphere or ESXi Manager. Once the VM is stopped, locate the datastore containing the virtual disk files. A standard VMDK setup usually includes two files: a descriptor file (small text file) and a flat file (the actual data). For conversion purposes, you primarily need the flat file, often named with a suffix like-flat.vmdk. However, qemu-img can often read the descriptor file directly if it correctly references the flat data.
Download the VMDK file to your local machine or directly to the Rocky Linux host via SCP or SFTP. If the file is large, consider compressing it temporarily during transfer to save bandwidth, though this adds an extra decompression step later. Ensure the file permissions on the Rocky Linux host allow the converting user to read the file.
Performing the Conversion
With the VMDK file available on the Rocky Linux host, you can proceed with the actual format transformation. Theqemu-img utility supports a wide variety of input and output formats, making it a versatile tool for interoperability between different hypervisors.
Navigate to the directory containing the downloaded VMDK file. Use the convert subcommand to specify the source format, source file, destination format, and destination file. The command structure is as follows:
qemu-img convert -f vmdk -O qcow2 source_disk.vmdk converted_disk.qcow2
In this command:
-f vmdkspecifies the input format as VMware Virtual Disk Format.-O qcow2specifies the output format as QEMU Copy On Write version 2.source_disk.vmdkis the path to your exported VMware disk.converted_disk.qcow2is the name of the new file to be created.
-o subformat=stream_v2 or specify the encryption type. However, for standard unencrypted disks, the basic command suffices. Monitor the output for any warnings regarding sector alignment or compression issues. Successful completion means the new QCOW2 file is ready for deployment.
Deploying the Converted Image
After conversion, validate the integrity of the new QCOW2 file before attaching it to a new virtual machine. Use theinfo subcommand to check the metadata and verify that the image is not corrupted.
qemu-img info converted_disk.qcow2
This command displays the format, virtual size, and physical size of the disk. If the virtual size matches the original VMDK, the conversion was likely successful. You can now attach this QCOW2 disk to a new VM managed by libvirt, virt-manager, or direct QEMU commands on Rocky Linux.
For users looking to automate this process further, integrating this conversion step into a larger script can streamline migrations. If you encounter permission issues during the creation of the final VM, refer to our guide on resolving permission errors with virt-install. Additionally, if you plan to manage multiple VMs after migration, exploring automation tools like virt-manager can simplify the lifecycle management of these newly converted images.
Performance Considerations
QCOW2 offers features like thin provisioning and compression that VMDK may not utilize in the same way. When creating the new VM, consider enabling discard operations to maintain performance over time. Also, ensure that the CPU model passed to the new VM is compatible with the underlying hardware, as migrating from VMware’s abstraction layer to KVM requires explicit CPU passthrough configuration if you wish to preserve specific instruction sets.Frequently Asked Questions
Can I convert VMDK to QCOW2 directly inside ESXi?
No, ESXi does not include theqemu-img binary or the ability to install third-party Linux packages natively. All conversion must be performed on a host that has access to the QEMU utilities, such as a Rocky Linux server.
What happens if I convert a powered-on VMDK?
Converting a disk while the VM is running can result in a corrupted QCOW2 file because the disk state is inconsistent. Always shut down the virtual machine completely before exporting and converting the disk files to ensure data integrity.Does the QCOW2 file take up less space than the VMDK?
Not necessarily immediately. While QCOW2 supports thin provisioning, the initial file size depends on how the conversion is handled. Using the-c flag in the convert command enables compression, which can reduce the physical size of the resulting QCOW2 file significantly compared to the raw VMDK data.
How do I fix permission denied errors when using the converted disk?
Ensure that the user account running the virtualization software (such as libvirtd or qemu-system-x86_64) has read and write access to the QCOW2 file. You may need to adjust ownership usingchown or modify group permissions so the virtualization daemon can access the storage backend without restriction.