# virt-p2v-make-disk

`virt-p2v-make-disk` is a command-line utility used as part of the **virt-p2v** toolset. The **virt-p2v** project is designed to simplify the migration of physical machines (P2V) to virtual machines (VMs). Specifically, `virt-p2v-make-disk` is used to create a bootable disk image of a physical system, which can then be converted into a virtual machine image.

#### Purpose of `virt-p2v-make-disk`

`virt-p2v-make-disk` helps in converting a physical machine into a virtual machine by creating a bootable disk image. This disk image can then be used with virtualization platforms like **KVM**, **QEMU**, or **libvirt**. The tool is primarily used when you want to migrate an entire physical server (including its operating system and data) into a virtual environment.

The process involves:

1. **Cloning the physical machine**: This tool essentially clones the physical disk of the source machine.
2. **Creating a Virtual Machine Disk**: It generates a disk image that can be used with virtual machines.

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

1. **Physical-to-Virtual (P2V) Conversion**:
   * Converts physical machines into virtual machine disk images.
2. **Generates Bootable Disk Images**:
   * Creates disk images that can be booted and used in a virtual machine environment (e.g., **KVM**, **QEMU**).
3. **Ease of Migration**:
   * Helps automate and simplify the migration process, especially when moving legacy or physical machines to virtualized infrastructure.
4. **Multiple Supported Formats**:
   * Supports converting physical disks into various virtual disk formats, such as **QCOW2**, **RAW**, and others.

#### Basic Syntax

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

* **source**: The physical machine or disk image that you wish to convert to a virtual machine.
* **destination**: The output file or directory where the bootable disk image will be created.

#### Common Options

* `-o, --output`:
  * Specify the output directory or disk image where the virtual machine disk will be created.
* `-f, --format`:
  * Specify the format of the output disk image. Common formats are `qcow2` (default) and `raw`.
* `-b, --boot`:
  * Specifies the boot configuration. The default is usually to make the disk bootable.
* `-v, --verbose`:
  * Enable verbose output for debugging or more detailed logs.
* `-p, --preserve`:
  * Preserve the original disk layout or configuration when creating the VM disk.
* `--size`:
  * Allows specifying the size of the resulting disk image if you wish to modify it.

#### Example Usage

1. **Basic Usage to Create a VM Disk from a Physical Machine**:

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

   * Converts the physical disk `/dev/sda` from the source machine into a virtual machine disk image, stored in `/var/lib/libvirt/images/converted-vm.img`.
2. **Create a Virtual Disk with a Specific Format**:

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

   * Converts the physical disk `/dev/sda` into a `qcow2` disk image.
3. **Create a Virtual Disk with Custom Size**:

   ```bash
   virt-p2v-make-disk --size 100G /dev/sda /var/lib/libvirt/images/converted-vm.img
   ```

   * Creates a virtual machine disk image with a size of 100GB from the physical disk `/dev/sda`.
4. **Verbose Output for Debugging**:

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

   * Runs the tool with verbose output, which can be useful for troubleshooting.

#### Considerations

* **Disk Space**: When creating a virtual disk, ensure that there is sufficient space in the destination directory to store the entire disk image. The size of the disk image will typically be similar to the size of the physical machine’s disk.
* **Disk Format**: The default format for output disk images is often `qcow2`, but it can be specified as `raw` or other formats if needed. Choose a format that suits your virtualization environment (e.g., `qcow2` for KVM).
* **Preserving Partition Layout**: The tool attempts to preserve the partition layout and filesystem integrity. However, when converting physical systems with complex configurations (e.g., RAID setups), there may be additional steps required to ensure proper functionality in the virtual environment.
* **Virtual Machine Configuration**: After generating the disk image, additional steps might be required to configure the virtual machine (e.g., setting up networking, virtual CPU settings, etc.).

#### Post-Migration Steps

After the conversion is complete, the disk image can be used as a virtual disk for a virtual machine in environments like **KVM/QEMU** or **libvirt**. The virtual machine will require additional configuration, including:

* Network setup
* Virtual CPU and memory configuration
* Installation of appropriate guest drivers, such as **virtio drivers** for disk and network devices.

#### Conclusion

`virt-p2v-make-disk` is a useful tool for migrating physical machines to virtual machines by creating bootable disk images. This tool simplifies the process of physical-to-virtual (P2V) conversion, making it easier for administrators to move legacy or physical systems into virtualized environments like KVM/QEMU. However, after the conversion, some additional configuration may be required to ensure the virtual machine runs correctly.
