[solved] Migrating physical drive to QEMU image / partition of another drive

I have been using an old, beat up HDD for my virtualized machine, which I pass to QEMU with the option -drive file=/dev/sda,format=raw. I just got a new HDD which I plan to use for my virtualized machine, but also for general storage on my host.
I need to keep the partition layout from my virtual machine drive, as windows would crap itself otherwise (I tested this by passing /dev/sda1, /dev/sda2, and /dev/sda3 individually).
but I also need another partition for storage. I also want to make my virtual machine’s storage bigger.

One option, which I don’t think I’m good enough at linux to make work, is partitioning my new disk, and doing something like dd if=/dev/sda of=/dev/sdb1, (i’m guessing it would’t work if I just do that, as I’m moving a whole drive to a single partition), and I’m left with the problem of resizing.

Another option is using a disk image, which I do know how to create.
Now I’m still left with the problem of resizing.

qemu-img convert -o qcow2 /dev/sda /srv/vm/mywindowsinstall/disk.qcow2

qemu-img resize /srv/vm/mywindowsinstall/disk.qcow2 +50G

Then you’d boot windows from the drive and from disk management from within windows you can increase its partition size by 50G

4 Likes

Thanks!, that worked.

1 Like