0

Ingredients: Running system w/ LinuxMint (main system) and other OS's among which is an old Windows 7 image. System boots via GRUB2 into Ubuntu, Windows with no issues.

Here is the system's partion map:

(parted) print                                                            
Modell: ATA HGST HTS721010A9 (scsi)
Festplatte  /dev/sda:  1000GB
Sektorgröße (logisch/physisch): 512B/4096B
Partitionstabelle: msdos
Disk-Flags: 

Nummer  Anfang  Ende   Größe   Typ       Dateisystem     Flags
 1      1049kB  252GB  252GB   primary   ntfs            boot
 4      252GB   306GB  54,6GB  extended
 6      252GB   273GB  21,0GB  logical   ext4
 5      273GB   306GB  33,6GB  logical   linux-swap(v1)
 2      306GB   359GB  52,4GB  primary   ext4
 3      359GB   983GB  624GB   primary   ext4

Partition 1 holds the old W7 image to be converted to a virtual volume.

Scenario:

  1. Converting existing old W7 system to a VM image with disk2vhd tool under Windows. Result w7.vhdx image file ✓ (Note: This image already can be started with QEMU and Super Grub2 Disk.)
  2. Convert w7.vhdx to qcow2 format with qemu-image ✓
  3. Launch w7.qcow2 with qemu-system-x86_64 -enable-kvm -m 4096M -hda 'w7.qcow2' -vga virtio -usb -device usb-tablet -device usb-host,bus=usb-bus.0,hostbus=1,hostport=1.2 -cdrom /dev/sr0 ❌ => System boots into grub rescue
  4. Reboot with qemu-system-x86_64 -enable-kvm -m 4096M -hda 'w7.qcow2' -vga virtio -usb -device usb-tablet -device usb-host,bus=usb-bus.0,hostbus=1,hostport=1.2 -cdrom /dev/sr0 -boot menu=on
  5. Press Esc and boot from Super Grub2 Disk in DVD drive ✓ => I am able to boot the Windows system and everything works fine.
  6. Trying to boot from Live stick or Ubuntu DVD ❌ => system hangs (I was trying to re-install GRUB2 to manage to boot directly into the W7 system on w7.qcow2)

Observations:

Apparently disk2vhd reproduces the disk's partition layout. Super Grub lists the drive's orginal partitions (see above) with "No know filesystem detected" the only exception being the copied W7 partition with correct file system type NTFS and the correct size.

Parted:

(parted) print disk                                                       
Fehler: W7.VHDX: unbekannte Partitionstabelle

Fdisk:

Festplatte W7.VHDX: 226,3 GiB, 242934087680 Bytes, 474480640 Sektoren
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 512 Bytes
E/A-Größe (minimal/optimal): 512 Bytes / 512 Bytes

Question: How do I fix w7.qcow2's boot such that QEMU boots directly into the Windows system or the GRUB boot menu with Windows as default system?

Remark: I tried an approach with kpartx, losetup with /dev/loop0 to get this fixed to no avail.

  • If you don't intend to keep the Linux distributions that were in the image, why not just use fdisk to change which partition is active? – Michael Hampton Apr 24 at 13:19
  • Hmmm. fdisk tells me there is no partition table. – mgw Apr 24 at 13:52
  • The image can't be mounted either. Funny enough the system starts with help of the super grub2 disk. – mgw Apr 24 at 13:56
  • Now I suspect something went wrong with the initial p2v way back at step 1. Perhaps it copied only a single partition and not the whole disk? – Michael Hampton Apr 24 at 13:57
  • Sure - it copied only the windows partition BUT from Super Grub2 Disk's function list partitions I can see the entire disk layout. – mgw Apr 24 at 14:31
1

Here are the steps that produced a bootable VM for QEMU/KVM that boots directly into the virtualized Windows 7 system. My system uses GRUB2 as bootmanager (if yours is different you may want to adopt the following to your needs).

Pre-req's: Windows 7 DVD (download ISO-image from Microsoft if none at hand), Windows license key, SuperGRUB2 disk on CD (download from www.supergrubdisk.org).

  1. Start existing old W7 system from GRUB2 menu.
  2. Download DISK2VHD tool. It is also a good idea to make sure that 7Zip or similar is installed in Windows before starting the conversion.
  3. Convert existing system (you may want to clean up the usual Windows mess upfront) with DISK2VHD. This produces a file .VHDX (w7.vhdx in my case). (Note: This image already can be started with QEMU and a SuperGrub2 disk.)
  4. Convert w7.vhdx to qcow2 format (or another format you prefer) with qemu-image.
  5. With the SuperGRUB2 disk in the DVD drive launch w7.qcow2 with command qemu-system-x86_64 -enable-kvm -m 4096M -drive file=w7.qcow2 -vga virtio -cdrom /dev/sr0 -boot menu=on (This asumes issueing the command from the directory where w7.qcow2 resides; otherwise supply full path e.g. /home/W7/w7.qcow2 in my case. Your cdrom device also may have another name, in case you don't know lsblk will tell.). When the system boots press ESC go to the boot menu. In case the system boots into grub rescue, reboot (good old Ctrl-Alt-Del) and press ESC to enter the boot menu.
  6. Select boot from DVD. The SuperGRUBs menu will appear and after discovery list your Windows (or two in my case). Select any of the Windows systems and boot. Everything should work fine now. However, the first boot is slow and Windows will install several device drivers. Make sure this is completed before you reboot!
  7. The screen resolution in the QEMU Windows system will most probably be awfull so adopt to your needs. Next open a command prompt and type bootrec.exe /?. Windows will most likely tell you that it has no command bootrec available. If this is not the case and bootrec's help is displayed, continue with step 10 below.
  8. Now we need the Windows DVD (bootrec.exe can't be downloaded from Microsoft but is available from the Windows 7 ISO): In QEMU monitor eject the SuperGRUB disk and change to Windows DVD.
  9. With 7Zip (or another tool capable of reading WIM files) open :\sources\boot.wim. Bootrec.exe is located in \1\Windows\System32 - extract and store on your C: drive.
  10. From a windows command prompt issue bootrec /fixmbr followed by bootrec /fixboot. Make sure the device driver installation has finished and finaly shutdown the system with shutdown /s /t 0 in the command prompt (otherwise you may end up with a hibernated system).

This is it. It is a good idea to start the vitual W7 with a QEMU overlay image to preserve the original setup.

Thanks to Nicolai and Brian for the bootrec recommendations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.