# virt-p2v

`virt-p2v` is a set of tools designed to help with the migration of physical machines (P2V) to virtualized environments. It automates the process of converting a physical machine into a virtual machine image that can be used with hypervisors like **KVM/QEMU**.

#### Purpose of `virt-p2v`

The main goal of **virt-p2v** is to simplify and automate the migration of physical machines into virtual environments. This is especially useful for organizations moving from physical hardware to virtualized infrastructure, or for migrating legacy systems into modern virtual machine environments.

#### Key Components of `virt-p2v`

The **virt-p2v** toolset consists of several tools that help automate the conversion process:

1. **`virt-p2v-make-disk`**: This tool is used to create a bootable disk image of a physical system. Once the disk image is created, it can be converted into a virtual machine image.
2. **`virt-p2v`**: The main utility that runs on the physical machine and performs the P2V conversion. It captures the physical machine's disk, system configurations, and any other essential data, then converts this data into a virtual disk image.
3. **Conversion Process**: The physical machine's data, including the operating system, disk partitions, and system settings, are transferred and transformed into a format that can be used by a virtual machine. This process also ensures that the necessary drivers and hardware configurations are set for the virtualized environment.

#### Key Features of `virt-p2v`

1. **Physical-to-Virtual Conversion**:
   * `virt-p2v` enables seamless conversion of physical servers into virtual machines that can be run in a hypervisor like **KVM**, **QEMU**, or **libvirt**.
2. **Bootable Disk Images**:
   * The output of the conversion is a bootable disk image that can be used as a virtual disk for a virtual machine.
3. **Network Configuration**:
   * The tool can automatically detect network interfaces and adjust them for the virtualized environment, allowing the virtual machine to be network-ready after conversion.
4. **Multiple Formats**:
   * The tool supports various virtual disk formats, including **QCOW2** (a widely used format for KVM) and **RAW**.
5. **Preserves Data**:
   * `virt-p2v` aims to preserve the integrity of the data, partition structures, and disk configurations during the conversion, making it easier to migrate the physical machine's environment to the virtual world.
6. **Compatibility**:
   * Supports migration from a variety of physical hardware platforms to virtual machines on **KVM**, **QEMU**, and other hypervisor environments.
7. **Automated Migration**:
   * The tool automates much of the migration process, saving time and reducing the manual work involved in setting up the virtual machine environment.

#### Basic Syntax for `virt-p2v`

```bash
virt-p2v [options] source [destination]
```

* **source**: The physical machine or disk image to be converted.
* **destination**: The output directory or location where the virtual machine disk image will be created.

#### Common Options

* `-o, --output`: Specifies the destination for the converted virtual machine disk. This is usually the directory where the VM image will be saved.
* `-f, --format`: Specifies the format of the resulting virtual disk image (e.g., `qcow2`, `raw`).
* `-v, --verbose`: Enables verbose output for debugging or detailed logs.
* `-p, --preserve`: Ensures that the original disk layout is preserved during conversion.
* `-b, --boot`: Marks the resulting disk image as bootable.

#### Example Usage

1. **Basic Conversion of a Physical Disk to a Virtual Machine Image**:

   ```bash
   virt-p2v /dev/sda /var/lib/libvirt/images/converted-vm.img
   ```

   This command converts the physical disk `/dev/sda` into a virtual machine image and saves it to `/var/lib/libvirt/images/converted-vm.img`.
2. **Specify Format and Output Directory**:

   ```bash
   virt-p2v -f qcow2 /dev/sda /var/lib/libvirt/images/converted-vm.qcow2
   ```

   This command converts the physical disk `/dev/sda` into the `qcow2` format and saves it as `converted-vm.qcow2` in the specified directory.
3. **Verbose Output for Debugging**:

   ```bash
   virt-p2v -v /dev/sda /var/lib/libvirt/images/converted-vm.img
   ```

   This command runs `virt-p2v` with verbose output, providing more detailed information during the conversion process.
4. **Preserve Disk Layout**:

   ```bash
   virt-p2v -p /dev/sda /var/lib/libvirt/images/converted-vm.img
   ```

   This command converts the physical disk `/dev/sda` to a virtual disk, ensuring that the original disk layout is preserved.

#### Considerations

* **Disk Space**: When using `virt-p2v`, make sure the destination disk or directory has enough space to accommodate the converted disk image.
* **VM Configuration**: After the physical machine has been converted to a virtual machine, you may need to adjust certain settings like networking, CPU, or memory configurations to match the virtual environment.
* **Guest Drivers**: Ensure that the converted virtual machine is equipped with the necessary drivers for the virtualized hardware (e.g., virtio drivers for disk and network interfaces) for optimal performance.
* **Data Integrity**: `virt-p2v` attempts to preserve data integrity, but it’s a good idea to back up your data before starting the migration process, especially when dealing with critical systems.

#### Conclusion

`virt-p2v` is a powerful tool for migrating physical machines to virtual environments. It automates the process of creating bootable disk images from physical systems, converting them into virtual machine formats that are compatible with hypervisors like **KVM/QEMU**. This makes it easier for organizations to move legacy or physical systems into virtualized infrastructure with minimal downtime and effort.
