welw | About_me Blog WebAssembly

P2V migration is physical to virtual migration

Let's try it on an example. I cloned efi partition with dd and Windows Server partition with ntfsclone.

Go:

  1. Install KVM and QEMU

On Debian:

sudo apt update sudo apt install qemu-system-x86 qemu-utils ovmf bridge-utils

Optionally install libvirt if you want easier VM management:

sudo apt install libvirt-daemon-system virtinst virt-manager

Verify virtualization support:

egrep -c '(vmx|svm)' /proc/cpuinfo

A value greater than 0 indicates hardware virtualization is available.

  1. Create a virtual disk

Assuming your original disk was 500 GB:

qemu-img create -f qcow2 windows2016.qcow2 500G

You can also use a raw disk image:

truncate -s 500G windows2016.raw 3. Partition the virtual disk

Attach it as a network block device:

sudo modprobe nbd max_part=16

sudo qemu-nbd --connect=/dev/nbd0 windows2016.raw

Create the partition table to match the original using gdisk, parted, or fdisk.

For GPT/UEFI, create:

EFI System Partition (typically 100–260 MB, FAT32) Microsoft Reserved (16 MB, no filesystem) Windows (NTFS) Recovery (optional)

The partition sizes should be at least as large as the originals.

  1. Restore the partitions

If you cloned the EFI partition with dd:

sudo dd if=efi.img of=/dev/nbd0p1 bs=4M status=progress

If you created the Windows image with ntfsclone --save-image:

sudo ntfsclone --restore-image \ --overwrite /dev/nbd0p3 \ windows.img

If you instead used dd for the Windows partition, restore it with dd.

  1. Disconnect the NBD device sync sudo qemu-nbd --disconnect /dev/nbd0
  2. Boot the VM

For a UEFI Windows Server 2016 installation:

qemu-system-x8664 \ -enable-kvm \ -machine q35 \ -cpu host \ -smp 4 \ -m 8G \ -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMFCODE.fd \ -drive if=pflash,format=raw,file=OVMF_VARS.fd \ -drive file=windows2016.raw,format=raw \ -boot menu=on

You may need to copy the writable OVMF variables file first:

cp /usr/share/OVMF/OVMF_VARS.fd .