Introduction
In this article, we will discuss how to clone a Windows drive using QEMU while selectively handling the boot partition (100MB). This process is useful when you want to clone the operating system and essential applications while excluding large data partitions, such as game files (300GB).
Prerequisites
To follow this guide, you need:
- A source Windows drive (2TB, 300GB C: drive, and 1.7TB games partition)
- A target drive with sufficient space (minimum 2TB)
- QEMU installed on your system
Prerequisite: Creating a QEMU Virtual Disk
Before we begin cloning the Windows drive, we need to create a new virtual disk using QEMU. Open a terminal and run the following command:
qemu-img create -f qcow2 target.qcow2 2TB
Step 1: Cloning the Windows Drive
Now, we will clone the source Windows drive to the target virtual disk using the "dd" command:
sudo dd if=/dev/sdaX bs=4M status=progress of=/path/to/target.qcow2 conv=sync,noerror
Replace "/dev/sdaX" with the path to your source Windows drive.
Step 2: Mounting the Virtual Disk
After cloning the drive, we need to mount it as a loop device:
sudo losetup --find --show target.qcow2
sudo mount /dev/loopX /mnt
Replace "/dev/loopX" with the loop device identifier returned by the "losetup" command.
Step 3: Identifying the Boot Partition
Use the "fdisk" command to list the partitions:
sudo fdisk -l /dev/loopX
Identify the boot partition (usually the smallest partition, e.g., /dev/loopX1).
Step 4: Creating a New Boot Partition
We will create a new boot partition on the target drive using the cloned boot partition:
sudo dd if=/dev/loopX1 of=/path/to/new_boot.img bs=512 count=1
sudo dd if=/dev/loopX1 of=/path/to/new_boot.img bs=4M skip=1
Replace "/path/to/new_boot.img" with the desired path and name for the new boot partition image file.
Step 5: Setting Up the Target Drive
We will create a new partition table and mount the target virtual disk:
sudo fdisk /dev/target
sudo mkfs.ext4 /dev/target1
sudo mount /dev/target1 /mnt
Step 6: Copying the Boot Files
Copy the essential boot files from the cloned boot partition to the new boot partition:
sudo cp /mnt/EFI/BOOT/BOOTX64.EFI /mnt/new_boot.img/EFI/BOOT/
sudo cp /mnt/EFI/Microsoft/Boot/bootmgfw.efi /mnt/new_boot.img/EFI/Microsoft/Boot/
Step 7: Setting Up the Grub Bootloader
Install the GRUB bootloader on the new boot partition:
sudo grub-install --force --target=x86_64-efi --boot-directory=/mnt/new_boot.img
Step 8: Updating the Master Boot Record (MBR)
Update the MBR on the target drive:
sudo grub-install --force --target=i386-pc --boot-directory=/mnt --recheck
Step 9: Unmounting the Virtual Disks
Unmount the virtual disks:
sudo umount /mnt
sudo losetup --detach /dev/loopX
In this article, we learned how to clone a Windows drive using QEMU while selectively handling the boot partition. This process allows you to create a new system with the operating system and essential applications while excluding large data partitions.
References