Last week, a friend of mine needed me to do an audio file conversion, but the app that I use is installed on my windows partition. I really don’t ever boot into Windows unless I have a good reason for it — I’m much happier tooling around in Linux — there’s just something satisfying and comfortable about being able to pop open a shell at any time.
Anyways – it got me thinking: I’ve booted into a Windows XP image, why can’t I use VirtualBox to boot from a whole partition? Surely that is possible…
Tonight I finally got to play with it. And as you can see from the image here, I got success.
It’s a little challenging, but it’s doable. I had to spend some time to iron out the kinks, but you can reap the benefits!
Install Virtual Box
Ok, for starters, you need the CLOSED SOURCE version of VirtualBox. As in — do not install the one from the Ubuntu Software Center. Go directly to Sun’s website and download the appropriate version for your OS.
If you’re clever, you can load their PPA into your software sources list (System->Admin->Software Sources), load the key, and that way you’ll get updates automatically! (plus you can apt-get install it
)
Either way — install the most recent version of the personal edition (NOT “OSE”, which is the open-source version.) As of this post, the current version for Karmic (64-bit) is VirtualBox 3.1.2.
Install “mbr”
In order to successfully trick Windows into booting into a confined space, you need to fake your mbr (no grub). Fortunately this is WAY easier than it sounds:
sudo apt-get install mbr
install-mbr –force ~/.VirtualBox/FAKE.mbr
That’s it! We’ll use that later.
Your system will NOT be affected by this — all it does is copy the MBR from your computer, dump it into a file and that’s it.
Create a VDMK file
This is actually the trickiest part. A VDMK, which I am not sure what that is an acronym for, is essentially a micro-image that contains instructions to tell MBR where it’s booting from. If your computer is modern, your hard drives are likely SATA drives (and thus represented as /dev/sda). If you’re unsure, just go into a shell and type “fdisk -l” (no quotes, and that last part is a “dash lowercase-L” not “dash one”). What you want is the device name for your harddrive… mine is /dev/sda — depending on how many hard drives you have and what type they are, it might be /dev/hda/ or /dev/sdb/ etc.
It’s worth noting that if you are currently mounting your windows partition in Linux (I do) so that you can access your Windows filesystem while in Linux, you will need to unmount (eg. sudo umount /windows) it first.
You’ll want to determine which partition contains Windows, so we can restrict Windows to ONLY using its own partition — this is actually a Linux-exclusive ability (the Windows version of Vbox can’t do this, because Windows is a wuss). So to do this, first you need to know what partition(s) Windows is on. This command will tell you:
VBoxManage internalcommands listpartitions -rawdisk /dev/sda
For the boldfaced part, use whatever you determined from above. It’s PROBABLY /dev/sda for you too, that’s pretty common.
The command will produce output that looks something like this:
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0×83 0 /1 /1 1023/254/63 53348 63
2 0×82 1023/254/63 1023/254/63 4000 109258065
3 0×83 1023/254/63 1023/254/63 155998 117451215
4 0×07 1023/0 /1 1023/254/63 91895 436935870
I have to admit, I feel a little naked showing the whole Internet my partition table…
The last line is the one you want to look for, although yours may not be your last line. Whichever one(s) have 0×07 as their “Type” are the one(s) you want. Jot down the number(s) for those. (In this case, my number is just “4″).
Now there’s one last thing we have to do that may make you a little uncomfortable, if you’re a paranoid person. We need to change the permissions on the hard drive device nodes. If you don’t know what that means, then you are probably not paranoid about that.
Fortunately, we only need to change the permissions slightly, and only on the Windows partitions. So it’s not THAT big of a deal.
In a terminal, type:
sudo chmod 666 /dev/sda
sudo chmod 660 /dev/sda4
That second line should reflect whichever hard drives you are using (remember that fdisk -l we did?) You’ll need to repeat the command for each hard drive that you want Windows to be able to access.
For those of you that are paranoid: You should be able to change the permissions back to 600 after we’ve created the VDMK file — VirtualBox needs access to your partition table so it can do its job.
There’s one last thing we need to do, and that’s adding you to the “disk” group, so you can access the partitions you just opened up. You’ll need to logout and log back in after doing this, so that your permissions are reset.
sudo usermod -a -G disk
Ok, now you’re ready to actually create the VDMK file. Get ready because this is a handful.
VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/winxp.vmdk -rawdisk /dev/sda -partitions 4 -mbr ~/.VirtualBox/FAKE.mbr -relative -register
First off — the “sda” is whatever you determined you’re using, from earlier. It’s probably “sda”, like I mentioned earlier.
The number next to the partitions is the numbers you jotted down from the previous “listpartitions” command (the one where I said I felt naked). If you are using more than one partition, you will need to list them as comma-separated values. So if you wanted partitions 1 and 2 for Windows, you would replace the “4″ I wrote there with “1,2″. Partitions 2, 3 and 4 would be “2,3,4″ and so on.
The “partitions” parameter is what tells VirtualBox “only give Windows access to these partitions, and no where else!”
Just to break down what’s going on here:
VBoxManage internalcommands createrawvmdk – this portion runs the program to “Create Raw VMDK”. Self-explanatory. DO NOT USE SUDO HERE (h/t to Javier, below!)
-filename ~/.VirtualBox/winxp.vmdk – this is the output file that actually holds the micro-image. You can call it whatever you like, and you can put it whereever you like. If you have multiple Virtual Machines, you may like to file them away in a separate folder. Whatever you like.
-rawdisk /dev/sda -partitions 4 -This tells it that the raw Windows installation is located on device /dev/sda and that you only want to use partition 4 (yours may be different, as noted above)
-mbr ~/.VirtualBox/FAKE.mbr -relative – the -mbr parameter tells it to use that Fake MBR we created earlier. It won’t work without this. -relative is a parameter that works in conjunction with the -partitions parameter, to allow you to explicitly specify which partition you want to use.
-register – This tells VirtualBox to register it in its database of available images. Not absolutely necessary, but it’s a nice shortcut.
That’s it. Chances are, if you are going to get errors anywhere, it’s likely to be here.
Possible causes, based on my experience and what I’ve read about on the Internet, is that you didn’t set permissions correctly, didn’t unmount your device, are using the Open-source edition (which doesn’t have createrawvdmk) instead of the closed-source personal edition. If you get an error, you can post it in a comment and I’ll see if I can help you, but google around — there are a LOT of resources online for this. Below, I’ll include links to the places I looked.
Load your new VDMK into Virtual Box
Load up Virtualbox, if you installed it through the automated installation (rather than compiling it manually), you should see it in Applications -> System Tools -> Sun Virtual Box. If you don’t see it there, try logging out and logging back in.
In VirtualBox, click on “New”, and follow the instructions for the first couple of screens. Name it whatever you like and select your OS (these instructions have all applied to Windows XP so far — caveat operor on any other versions / OSs). Once you get to the “Virtual Hard Disk” screen (pictured here) select “Use existing hard disk” and you should see the VDMK file we just created. If you don’t, click the little folder icon next to the drop down list. It will allow you to “add” your vdmk file that you created.
Once that’s done, you’ll be back at the main screen.
Click once on your new Virtual Machine, and click the “Settings” icon at the top. You need to do a few more things first.
Configuring your Virtual Machine
In the “System” area, be sure to check “Enable IO APIC” in the “Motherboard” tab. In “Processor”, specify how many CPUs you want to use (ie. I have a Core 2 Duo, so I can choose more than one). You really only need 1 — if you’re doing stuff that requires more, you should probably boot into Windows natively.
In the Acceleration tab — some CPUs have the native instructions built for virtualization — modern Intel CPUs do. If you paid a little extra for your CPU and you bought it in the past year or two, you might have these. I forget the specific models that have it, but it’s something that’s easy to overlook.
Under “Display” area, adjust the slider to specify how much Video RAM you want to give your VM. I picked “64MB” for mine… very modest. You can also check “Enable 2d Acceleration” and “Enable 3d acceleration” simply because it won’t hurt to do so… but again, if you’re doing things that require hardware acceleration, a VM probably isn’t the best way to do it.
That’s it — the rest of the stuff is just icing. You can tinker with it if you want, but you’re good to go.
Click on “OK” to get out of there, then click “Start” (green arrow at the top). The first time you boot up, it may take a little while longer than usual.
This is the other point that is prone to errors. The first time I did this, I had errors because I didn’t do the -partitions parameter in my VDMK creation, which gave me “disk read” errors. You might get a blue screen of death or some other nonsense. If you get any errors — google it. Like I said earlier, there’s lots of support for it.
Once You’re In Windows
Some of the sites I’ve read have suggested creating an alternate hardware profile for when you boot into Vbox. This is a good idea if you plan on booting into it normally once in a while (for games or whatnot). To create a new Hardware Profile, right click on “My Computer” and click “Properties”. Select “Hardware” then at the bottom, select “Hardware Profiles”. Create a new one and name it “Raw Boot”, and rename the current one to “VBox Boot”.
Windows will go through some growing pains this first boot sequence, as it maps all the hardware drivers to the VirtualBox extensions provided — You will likely need to restart. No guarantees on all the hardware working as it does in a native boot. You should be able to use things like Word, browse the web, use Photoshop (if you allocated enough RAM…you can always change that later), etc. Anything relatively lightweight should be fine.
Congratulations!
That’s it! Tinkering and optimizing aside, you’re done.
Further Reading
I would not have been able to do this without help from many other bloggers and hackers out there. Here are some of the resources I used to get this working:
- Trouble running VirtualBox with “real” partition (UbuntuForums)
- The VirtualBox user manual (search for “vdmk”)
- VirtualBox: How to boot from an existing Windows XP partition in Ubuntu
- How to Run Virtual Box using a Physical Partition in Feisty Fawn (an older distro, but the methods haven’t changed THAT much)
- Accessing RAW Partitions with VDMK (VirtualBox forums)



#1 by Javier on February 2, 2010 - 2:41 pm
Quote
I’m getting stuck at one point:
sudo usermod -a -G disk
I’m using ubuntu Karmic, and I get an error message:
usermod: user ‘disk’ does not exist
Is there an equivalent user in 9.10?
Javier
#2 by Aaron on February 2, 2010 - 2:47 pm
Quote
I did this in Karmic as well — the “disk” is actually a group, not a user. what was the command you typed, exactly? was it verbatim?
#3 by Javier on February 2, 2010 - 2:54 pm
Quote
I copied and pasted from the article:
sudo usermod -a -G disk
Thanks for the quick answer!
Javier
#4 by Javier on February 2, 2010 - 3:09 pm
Quote
Nevermind, I got past that. I added my user to the disk group using the user and group manager on gnome. However, now I’m stuck at adding the VDMK file: When I hit add, I find two files. I tried with both, and I get a
“Failed to open the hard disk /home/javierd/.VirtualBox/winxp-pt.vmdk.
Could not open the medium ‘/home/javierd/.VirtualBox/winxp-pt.vmdk’.
VD: error VERR_ACCESS_DENIED opening image file ‘/home/javierd/.VirtualBox/winxp-pt.vmdk’ (VERR_ACCESS_DENIED).”
Best regards,
Javier
#5 by Aaron on February 2, 2010 - 3:14 pm
Quote
Could you paste the command you typed? I think I know what you did wrong, but knowing your command would help me know for sure.
IIRC, the issue might simply be a permissions issue with your /dev/sd* devices (your hard drives). Show me the command you used to create the VDMK and I should be able to identify the problem.
#6 by Javier on February 2, 2010 - 3:17 pm
Quote
Nevermind that last comment too…
Just a correction for this CLI:
sudo VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/winxp.vmdk -rawdisk /dev/sda -partitions 4 -mbr ~/.VirtualBox/FAKE.mbr -relative -register
Must be run WITHOUT the sudo… otherwise, the permissions will be for root only
#7 by Aaron on February 2, 2010 - 3:18 pm
Quote
Ah!
thank you — I will correct that above.
cheers for that!
#8 by Javier on February 2, 2010 - 5:38 pm
Quote
Sorry to pester again, but I run into another issue: My Windows now asks me for activation!! >:( I have tried manually assigning the MAC ID’s in order to have them match the same as the fisical ones… but no luck!
Native XP still boots up without issues, only when I start it through VB I get prompted to activate it…
Any ideas?
#9 by Aaron on February 2, 2010 - 10:53 pm
Quote
hmm… I didn’t have that problem.
Can you tell me a little more about your situation? You’re using an existing Windows XP installation, right?
On my system, I had a Windows partition that I was already using for dual-booting — that’s like what you have, right?
#10 by Javier on February 3, 2010 - 12:10 am
Quote
Yes, exactly the same.
Hmmm… It may have to do with licensing… mine is a OEM with a laptop. Maybe you have a retail version? For OEM, it checks some hardware serial numbers and uses that as a fingerprint for a machine… I’m guessing that because it doesn’t recognize the new values it believes I may have reinstalled it in another machine. I tried matching the MAC ID’s of the virtual interfaces, but didn’t work. The other thing I thought of, was having my VB use both processors (I have a core 2 duo laptop) instead of 1 as I did it at the beginning… but for some reason, it didn’t work with 2, only accepted one… I may just erase the windows partition and start running everything from VB, it may solve my problem, and I don’t really use Windows for much, just to access a Microsoft CRM web… ies4linux and IE with wine are not estable.
#11 by admin on February 3, 2010 - 1:15 am
Quote
Ahhhh… yeah — I have a retail (well, semi-retail — I bought it from my univ.) version.
Not sure how to address that problem, but perhaps someone else on the Internet has had that experience? Windows is such a fickle beast w/r/t hardware and whatnot… it’s pretty ridiculous.
The only time I ever really boot into windows is to play the 2 games I can’t get to work in Wine, use Reason 4, and use adobe CS4. that’s it. And I rarely do those things, even.
#12 by Balwinder S Dheeman on February 6, 2010 - 6:42 am
Quote
s|winxp|/HardDisks/&|g
#13 by Matt on February 11, 2010 - 6:48 am
Quote
Great post, Aaron. I’ve had a similar setup on my desktop / workstation since I first installed Linux a couple years ago. I must admit, you make the process seem much easier than I remember it being! Definitely useful though, as I do have a couple programs that from time to time I need from that partition. I’ve created a “true” virtual XP machine for the one program I use most often, mainly because when you run the physical WinXP install you don’t get features like snapshots and saving the machine state.
Javier, I’ve encountered the exact same problem as you. I did the same thing with my laptop, using the WinXP key it came with. For some reason it just doesn’t like being booted up both physically and virtually. It always asks for activation when I’ve switched from one to the other, even though I have set up separate hardware profiles. So frustrating. For a while I was having to call Microsoft each time (over some threshold I guess) but now I’ve gotten back to where I just tell it to activate each time and it works. Annoying, but usable in a pinch. My desktop (which has an OEM licensed but self-purchased version of XP) has never once had this problem. Go figure. Good luck!
#14 by Aaron on February 11, 2010 - 8:36 am
Quote
Matt:
I’ve heard that Vbox can translate 3d hardware to the vm, but never actually experimented with that yet — I’m kind of skeptical.
I can totally see why those features would be helpful — really the only reason I am doing this is so that I can pop into InDesign, Dreamweaver, or SoundForge in a pinch.
I’m guessing that you and Javier’s problem with activation is that you were using an OEM copy of WinXP, rather than a purchased copy? The OEM copies tend to be nerfed slightly, since they’re subsisdized.
#15 by Peter on February 11, 2010 - 10:06 pm
Quote
Hello Aaron:
I followed all the steps trying to boot my Win7 partition with a few issues of typing but no big deals. The last 2 steps were:
peter@Mymachine:~$ install-mbr -f ~/.VirtualBox/FAKE.mbr
peter@Mymachine:~$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/win7.vmdk -rawdisk /dev/sda -partitions 1 -mbr ~/.VirtualBox/FAKE.mbr -relative -register
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
RAW host disk access VMDK file /home/phoboz/.VirtualBox/win7.vmdk created successfully.
When i get the VirtualBox GUI i only found an existing hard disk named Win7.vdi so i took it and follow all the next steps.
When i started the VM i get this: FATAL: No bootable medium found! System Halted
Could you tell me which is my mistake?
Regards
#16 by Peter on February 11, 2010 - 10:10 pm
Quote
Hello Aaron:
I followed all the steps trying to boot my Win7 partition with a few issues of typing but no big deals. Some of the important steps were:
peter@Mymachine:~$VBoxManage internalcommands listpartitions -rawdisk /dev/sda
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0×07 0 /32 /33 1023/254/63 84434 2048
peter@Mymachine:~$ install-mbr -f ~/.VirtualBox/FAKE.mbr
peter@Mymachine:~$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/win7.vmdk -rawdisk /dev/sda -partitions 1 -mbr ~/.VirtualBox/FAKE.mbr -relative -register
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
RAW host disk access VMDK file /home/peter/.VirtualBox/win7.vmdk created successfully.
When i get the VirtualBox GUI i only found an existing hard disk named Win7.vdi so i took it and follow all the next steps.
When i started the VM i get this: FATAL: No bootable medium found! System Halted
Could you tell me which is my mistake?
Regards
#17 by Aaron on February 11, 2010 - 10:29 pm
Quote
I don’t know how much help I can be, since I havent used Win7 at all — my first guess is that Win7 has different reqs than XP as far as the MBR is concerned; Windows tends to be very jealous and wants a monogamous relationship with your hard disks. XP wont run unless you spoof its presence in the mbr (as you’ve seen). If Win7 is even more jealous, then your best bet is to start googlin’!
If you DO find anything interesting regarding this particular issue, I’d love to hear about it!
On the off chance its something else, can you post the result of fdisk -l for me? I might be able to help if I can see your partitiion table.
#18 by Peter on February 12, 2010 - 12:10 pm
Quote
Tks Aaron!! Sure… here it is:
Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0×57c6d2a2
Device Boot Start End Blocks Id System
/dev/sda1 * 1 10764 86460806 7 HPFS/NTFS
/dev/sda2 10765 14593 30756442+ 5 Extended
/dev/sda5 10765 14429 29439081 83 Linux
/dev/sda6 14430 14593 1317298+ 82 Linux swap / Solaris
Disk /dev/sdb: 41.1 GB, 41110142976 bytes
255 heads, 63 sectors/track, 4998 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa8418303
Im googling and changing some parameters, if i success ill be happy to share…
#19 by jean.s on February 24, 2010 - 7:00 am
Quote
Hey,
Some users having problems to activating their windows-xp after migrating it to virtualbox due to connectivity problems. The original windows seems to remember the MAC-Address of your network adapter, be sure to set the mac-address of your virtualbox adapter to the one you physically have – worked for me.
Cheers
#20 by jean.s on February 24, 2010 - 7:07 am
Quote
Another note: If you experience Bluescreen after migration, reboot into windows, apply the MergeIDE drivers to your current windows installation. See MergeIDE ( http://www.virtualbox.org/wiki/Migrate_Windows ). MergeIDE populates your windows installation with standard drivers which should work with Virtualbox. After having MergeIDE successfully installed, boot your windows with Virtualbox.
#21 by Aaron on February 24, 2010 - 8:37 am
Quote
Awesome!
Thanks for the notes, Jean — very helpful!