I was very much surprised just how easy it is to convert a Microsoft Windows 7 laptop into a virtual machine running within Sun’s VirtualBox. This is what I did:
- Pull the hard drive from the laptop. On my Dell Latitude, it was simply unscrewing the two screws on the bottom of the laptop marked with the hard drive simble
- Attach the drive to a SATA to USB connector and plug it in to your Linux box
- If you don’t have VirtualBox installed, do so now using apt-get, rpm, or whatever you use to install software
- Follow How to migrate existing Windows installations to VirtualBox but make sure you specify the entire drive (i.e. /dev/sdh) and not individual partitions else you will miss the hidden partitions that Vista and Windows 7 create
You should have a working Windows 7 Virtual Machine. You’ll notice that you probably have a huge vdi file. Let’s shrink that down:
- Within Windows
- download and install sdelete from Microsoft
- download and install PowerDefragmenter
- Run PowerDefragmenter on your c: drive (as administrator)
- Run “sdelete -c c:” from a cmd window (as administrator)
- shutdown windows
- On the host
- run “VBoxManage modifyvdi my_disk.vdi compact” replacing “my_disk.vdi” with the name of your vdi file you created earlier
- Note that if you get a “Shrink hard disk operation is not implemented” error, then you’ve hit bug #2833 and you will want to download the latest VirtualBox to fix it.
« FW (Sun): MVC, DCI, and NetBeans Platform Applications How to create an iTunes/iPod compatible audiobook (MPEG4 m4b) on Linux using MP4Box and mp4v2 v1.9.1 – it can be done! »




Oh yes, you will most likely have to reactivate your windows. It is a simple thing to do – just follow Microsoft’s instructions.
If you’re going to be attaching USB devices to the virtual machine, then you need to add yourself (and any other user you wish) to the vboxusers group in /etc/group. GUI way to do the same: http://news.softpedia.com/news/How-to-Fix-VirtualBox-USB-Support-111715.shtml
For Windows 7, did you have to run the MergeIDE utility or deal with the agp440.sys file? The instructions on the Virtual Box website were specifically for XP, so didn’t know if these still applied for Windows 7.
Nope, when I performed the physical to virtual of win7, I didn’t have to do anything outside of what I posted. Running MergeIDE by itself as a ‘rule of thumb’ probably wouldn’t be a bad idea anyways.
As far as MergeIDE & agp440.sys combo, I’ve only had to use that when moving from virtual to virtual – specifically when moving from VMware to VirtualBox.
Will the newly made vdi-Image be the same size as the regular hard disk? I have just bought a new laptop and I would LOVE to move the running Win7 to a virtual box. I simply don’t own a hard disk (external or bound to another PC), that is big enough. Allthough I might buy one.
As I have to install (and uninstall) new software regularly, my experiences with windows are not the best.
[I reply one year after, but I had the exact same problem and found this post very useful, so I try and contribute to it]
I had a 300G disk in the laptop and managed to move it on a 34GB vdi file, without extracting the disk.
Here is what I did.
1. within W7 on the laptop: remove all what is big and useless (in my case, I got rid of many GB of HP multimedia stuff I don’t use). I went from 40G to about 30G.
2. remove useless HP restore partition (using HP restore tool, and after having spent hours burning the 5 restoration DVD.
3. shrink c: partition. I used Windows to shring its main partition from 300G to 50G, and to make a partition with the free disk space.
4. follow Jason’s recommendation: defrag and zero the disk garbage.
I did the linux way, but sdelete should do fine: boot linux on a liveCD, mount all partitions, fill them with a file full of zero and delete it:
mkdir /tmp/sdaN; mount /dev/sda1 /tmp/sdaN
dd /dev/zero > /tmp/sdaN/fillwithzeros (this will take some time …)
sync
rm /tmp/sdaN/fillwithzeros; umount /dev/sdaN
5. still on the linux liveCD: copy the full disk -compressed- to a usb drive.
dd bs=512K conv=noerror if=/dev/sda |gzip -c –fast > /media//sda.img.gz
Nota1: I ran into a dd “input/output” error several times at the same point, after 50GB. As I could not solve or understand the problem, I added the “noerror” flag and hope the “error” would be somewhere it does not cause any problem. until now it is what happened.
Nota2: this takes a huge time. You can do “kill -USR1 ” to get some stats, stop and restart with different parameters to find an optimal bs size. bs=512K was good for me. gzip “-1″ or “–fast” made the total a few GB bigger but was twice as faster than default -6
6. Then I could easily move the 19.6GB gziped disk image and make the vdi from that :”gunzip -c sda.img.gz |VBoxManage convertfromraw stdin W7Laptop.vdi ” and get a 34GB vdi file.
Hope this helps someone some day
The VDI image will be just slightly larger, only a few megs, than the used space from your win7 disk drive. This is due to overhead of the VDI format.
But there’s no following files in Windows 7 ???
expand>NUL “%ctdir%\driver.cab” -f:Atapi.sys “%SystemRoot%\System32\Drivers”
if errorlevel 1 goto fehler1
expand>NUL “%ctdir%\driver.cab” -f:Intelide.sys “%SystemRoot%\System32\Drivers”
if errorlevel 1 goto fehler1
expand>NUL “%ctdir%\driver.cab” -f:Pciide.sys “%SystemRoot%\System32\Drivers”
if errorlevel 1 goto fehler1
expand>NUL “%ctdir%\driver.cab” -f:Pciidex.sys “%SystemRoot%\System32\Drivers”
This will not work in windows 7 or vista as the MergeIDE bat file looks to pull the drivers from the I386 folder or from the XP install cd, Athough you can still import the registry file anyway as it should not hurt your machine, but when you go to launch the virtualbox Win 7 it will most likely hang unless you happen to have those drivers already installed for boot (which is what MergeIDE attempts to do for you). As for me it did not work and I had to go through a long and length process to make sure all the virtualbox drivers were in place before i converted it to vdi and remove all the other drivers that i did not need. Maybe mine was harder because it was 64 bit?
Hi Eric
I seem to be getting a similar problem to you. My converted VM BSOD’s just after the black screen with the animated Windows Logo. I can’t see what the error is because it flashes by too quickly but I’m guessing it’s related to missing virtualbox drivers as I was unable to use the MergeIDE utility like you.
Could you tell me what drivers I need to install on my Windows7 machine before converting it please? I’ve had a look around on Google but can’t seem to find anything telling me what Vbox drivers I need to install on my physical laptop before virtualising.
Thanks very much in advance.
Bryn
By default a VirtualBox W7 VM will use SATA for the hard-drive interface.
If, as Bryn mentioned, your converted W7 VM does start up but then either BSOD or reboots then one suggested work-around is to change your VM settings to use IDE instead of SATA for the converted .VDI connection. This has worked for me numerous times.