I was able to get my Windows 7 install running as a VM inside of Linux, and then when I want to play games (note to my advisor: by games, I mean research!), I can boot into it natively. Furthermore, I wanted to do this from 1 hard drive (two partitions). Some commercial products can do this (I think), but I wanted to do it for free, cause I'm cheap. In retrospect, this was fairly easy. I haven't used it too much, but it seems to be working. As I write this, I'm updating some Steam games and chatting a bit.
Remember to always back up any important files (preferably an off site backup!).
I make no guarantees/warranties about whether this'll actually work for you, or whether you will not lose data/damage your computer
The way that I do this requires root privileges, as we're doing some risky things with the hard drive.
With my previous attempts to get Windows 7 to boot in a VM and bootable outside the VM, I kept getting blue screens with an error code of 0x7E (which is related to not being able to read the storage media). These steps fixed that problem for me.
Side note: this 'solution' may require Intel VT-X or AMD-V process (hardware based virtualization support). Here's a simple way to check for this. I am merely documenting how I was able to get Windows 7 to be bootable both in a VM and natively. It may not be the best way. Some steps may not be necessary, but I really don't feel like redoing things and finding out if any steps are not necessary.
#!/bin/bash
sudo virt-install -r 2000 --vcpus=2 --os-type=windows --import --disk path=/dev/sda,bus=ide,sparse=false --name Win7-Dual-Boot --sdl --accelerate -v
You may have to change a few things:
If you run the script you should hopefully see your normal Grub menu. Then, be sure to select Windows 7/the Windows boot loader entry from the list. Things might hopefully work. I did get a blue screen once (seemingly related to graphics drivers) but after a restart of the VM (see below) I was able to login to the VM.
I'm not KVM expert, so maybe this is overkill, but each time I want to leave Linux, I explicitly shutdown and kill the VM. After all, all of its data is saved on the hard drive. To see how I kill the VM, see the script below.
If your Windows 7 VM blue screens, I use a script like the following to shut it down. It's a bit stupid, but it works.
Be sure to set the VM= line to use whatever name you used in your virt-install command.
#!/bin/bash VM='Win7-Dual-Boot' #ask the VM to shutdown nicely (if it hasn't blue screened, it probably will comply) sudo virsh shutdown $VM #Give it 60 seconds to comply echo Sleeping for 60s... sleep 60 #Rip the power cord away from the VM sudo virsh destroy $VM #Remove the VM configuration from the system sudo virsh undefine $VM