Abstract:
We propose an extension to the LXD server that will allow the lxd-migrate tool and LXD UI to support additional VM image formats when importing an instance into LXD. Currently, only raw disk images can be imported. Our goal is to include support for VMDK (Virtual Machine Disk) and QCow2 (QEMU copy-on-write) formats. This involves integrating image conversion on the server side, to enable various clients (particularly the LXD UI) to seamlessly support instance imports. Additionally, we aim to streamline the import process for Windows virtual machines by automating the installation of required drivers during import.
Rationale:
Expanding the lxd-migrate tool to support multiple virtual machine import formats, including VMDK and QCow2, will significantly increase its utility.
Automating the installation of necessary drivers during the migration process will further streamline the workflow and make the tool more user-friendly and efficient.
Specification
Background
The current iteration of the lxd-migrate tool is limited to importing raw disk image formats. This limitation requires users to convert their disk images to the raw format before importing them into LXD.
For Windows disk images that originate from different hypervisors (other than QEMU/KVM), it is essential to install the virtio-win driver beforehand. This process currently requires users to manually download the necessary drivers and use the virt-v2v tool, which installs those drivers during disk image conversion.
We have also observed that some older Linux distributions have virtio drivers present but not in the initramfs, which leads to boot issues after instance is imported. Utilizing the virt-v2v tool for conversion to raw format can effectively resolve this problem by rebuilding drivers into the initramfs.
To address the above issues and improve the user experience when importing instances to LXD, we plan to convert any imported disk image (except for raw format) using a virt-v2v tool once the image is uploaded to the server.
Import Workflow
The import process in LXD involves transferring the disk image to the LXD server’s backups directory. The storage.backups_volume setting allows specifying a storage pool for this transfer.
Upon successful transfer the image is analyzed using qemu-img info to extract the image format and its final size (after potential decompression). If instance’s volume is large enough to fit the converted image, the image is converted to a raw format directly into instance’s root volume. Otherwise the process is aborted.
If driver injection is enabled, the instance’s root volume is further analyzed to determine whether any partition is formatted as NTFS . In such case, we assume that the image contains Windows operating system, and required Windows drivers are downloaded into LXD’s cache directory. Additional files required for Windows conversion are as follows:
virtio-win.iso→cache/virtio-win/- Downloaded and cachedrhsrvany.exeandpvvxsvc.exe→cache/virt-tools/- TBD Downloaded or provided as part of the Snap package (GitHub - rwmjones/rhsrvany: Free equivalent of Windows "srvany" program for turning any Windows program or script into a service)
Note that in the initial implementation, the virt-v2v-in-place will not be shipped with LXD Snap package, as it was initially planned. Therefore, the virt-v2v-in-place needs to be manually installed on the host where LXD server is running.
Packaging Changes:
LXD Snap
Snap package will be potentially extended with virt-v2v-in-place tool, and rhsrvany.exe and pvvxsvc.exe files that are required when importing Windows images. The initial implementation will require manual installation of virt-v2v-in-place on the host where LXD server is running.
API Changes:
The LXD migration API will be extended to support new instance source type conversion and field ConversionOptions. New type is introduced to retain backwards compatibility where instance is created from a raw image format.
Conversion options allow to choose how the image should be converted during the import phase.
The following options will be supported, and they can be enabled at the same time:
-
format(default) - Convert image into a raw format raw format, but virtio drivers are not injected. This works for images that already have virtio drivers present. -
virtio- Inject virtio drivers using virt-v2v-in-place. When enabled, server expects virt-v2v-in-place to be installed on the host.
type InstanceSource struct {
// Add new valid value "conversion".
Type string `json:"type" yaml:"type"`
// Accepts a list of converison options described above.
// Example: ["format", "virtio"]
ConversionOptions []string `json:"conversion_options" yaml:"conversion_options"`
}
CLI Changes:
Introduce new flag --conversion within lxd-migrate tool.
Database Changes:
- None
Upgrade Handling:
- None
Spec Changes:
-
Initially,
virt-v2vwas planned both for image conversion into RAW image format and injecting virtio drives into the raw image. This approach was replaced withqemu-imgfor converting the format andvirt-v2v-in-placefor injecting the virtio drivers. This is becausevirt-v2vsupports only conversion to the filesystem which would in terms of LXD support only storage driverdir. For other storage drivers, the image would first require conversion on the filesystem (inbackupsdirectory) and then to be moved into into instance’s volume. -
The
virt-inspectorwill not be used for detecting Windows operating system, as this would drastically prolong the import/conversion process.Instead, we will check the partition format to determine if any of them is NTFS and download Windows drivers into the cache.Windows drivers need to be preinstalled on the LXD host in order for virt-v2v-in-place to use them.