Sponsored Links

VirtualBox on Windows 7 Host with Raw Disk Access – Solution to Randomly Changing Disc Assignment Numbers

I recently updated one of my systems to multiboot Windows 7 64-bit and Linux Mint 64-bit, on a spare 500GB hard drive.

On the old hard drive I had Windows XP and Ubuntu 11.04, and I wanted access mainly to the old Ubuntu Installation, in case there was information on there that I needed for the fresh OS installs, so that was attached to a spare SATA interface as well, and I had set up Virtualbox 4.1 on WIndows 7 with raw disk access, to boot straight up into the old Ubuntu installation at my leisure.

It all worked great, until I booted into Win7, fired up VirtualBox and tried to start the “OldSystem” VM…

Ruh-Roh!

 

 

 

“What on earth is going on!?”, I wondered – note that that’s the polite version of what I said ;)

 

 

 

 

 

Eventually I figured out that there’s nothing wrong with the old system disk, and that it must be something to do with the way the raw disk was configured in the Virtualbox VM settings. So I took a peek at the Disk Management utility of Windows 7…

 

Something fishy going on here...

 

There we go… upon bootup, Windows 7 has enumerated the hard disks in my machine differently from when I first set up Virtualbox!

The new 500GB system disk has been designated as “Disc 1″ and the old disk as “Disk 0″ – argh!

[As an aside, note that the old disk ( now known as Disc 0) is also marked as "Offline" - you need that to be that way if you want Virtualbox to be able to access the disk as a raw partition and have read/write permission. If the disk is Online in Windows, you'll only get read access.]

So. “How Can This Be!?!?!?” was the next question asked. A lot of googling and it turns out that Windows 7 does in fact change Disc number assignments, seemingly at random during each boot. This is Not A Good Thing, because of the way Virtualbox Raw Disk Access needs to be configured, at the time of writing this article.

 

 

What I need to do is to tell Virtualbox to look specifically for the target hard drive, no matter what Windows decides to do that morning as I boot my machine up, so, here’s how I did it…

 

1) Obtain a utility called WinObj

Search google for “Windows 7 WinObj” and download it from whichever source you trust/ are comfortable with. It’s part of the SysInternals utilties at http://technet.microsoft.com/en-us/sysinternals  .

Then after you’ve unzipped it somewhere (and scanned for viruses I might add) , run it as Administrator – you’ll need to otherwise you won’t have permission to see the data you’re looking for.

WinObj showing the "GLOBAL??" part of the Windows Object Tree

 

 

Go to where you see “GLOBAL??” in the tree view on the left, and click on that. You’ll see lots of entries appear on the right hand side.

 

 

I highlighted the part about my old system disk.

 

 

Scroll down a bit and you’ll see entries for your HDD’s – depending on how many physical hard drives you have installed and the order in which Windows randomly enumerated them.

 

 

Now mosey on over to the left hand side again and click on the tree view where it says “Device”…

Shows the entry for "Harddisk0"

 

This shows the list of partitions for each hard disc enumerated during boot (or presumably added after boot if someone has done so). In this case, though, it only shows a “Partition 0″ – probably because I have set the disk as being Offline.

 

 

The entry for "Harddisk1"

 

This corresponds to the new 500GB hard drive I put in and installed Win7 & Ubuntu onto.

 

 

 

So, looks like I need to keep “Harddisk0″ in mind when looking for the ARCNAME entry which we’re coming to in a moment.

Go back to the tree view on the left hand side again and click on the entry called “ArcName”…

Entries in the ArcName tree view

 

As you can see there are 3 headings on the right hand pane; Name , Type, and Symlink, followed by loads of entries for each of the enumerated hard drives on your system.

For example multi(0)disk(0)rdisk(0) corresponds to a symlink of DeviceHarddisk1Partition0 on my system at least – yours will be different.

It is these entries (  multi(blah)disk(blah)rdisk(blah) ) that we’re interested in, as we’re going to use the one or ones that we want, to give to Virtualbox as a persistent entry to use and look for, no matter how many times you reboot Windows.

 

 

Before we do that, allow me to visually sum up the relationship between the Disk Management utility, and  GLOBAL??, Device, and ArcName  in the Windows objects database, of course relevant for my particular hardware setup…

Diagram starts from the middle, top half for one disc, bottom half for the other.

 

 

 

I hope I’ve made the relationships clear enough for you, and that the diagram makes sense.

As you can see from what I’ve said above and the screenshots of Disk Manager and the diagram to the left, the Disk my “old system” resides in, is currently known as “Disc 0″ to Windows 7.

 

 

 

 

Subsequent to that, using the SysInternals WinObj utility, I can now trace the Object name right back to;

multi(0)disk(0)rdisk(1)

So, what do we do after that?

2) Configure your VirtualBox VM so that from now on, even if Windows randomly changes the Disc # designation upon reboot, VirtualBox knows where to look!

A) For an existing VM configuration with an already configured VMDK file for Raw Disk Access…

On Windows, my VirtualBox VM configurations are stored in C:\Users\kcave\.VirtualBox . Of course your username will be different.

My VMDK file, OldSystem.vmdk,  describes to VBox where to go and look for my hard drive.

Currently, the file contains the following…

# Disk DescriptorFile
version=1
CID=8f361a5a
parentCID=ffffffff
createType="fullDevice"

# Extent description
RW 625142448 FLAT "\\.\PhysicalDrive1" 0

# The disk Data Base
#DDB

ddb.virtualHWVersion = "4"
ddb.adapterType="ide"
ddb.geometry.cylinders="16383"
ddb.geometry.heads="16"
ddb.geometry.sectors="63"
ddb.uuid.image="ccafde72-8d92-462e-b70d-897ce8e1641e"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="0b229951-5750-4e2e-a606-41d10be37dac"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
ddb.geometry.biosCylinders="1024"
ddb.geometry.biosHeads="255"
ddb.geometry.biosSectors="63"

NOTE : Make a backup copy of this VMDK file before editing it!

What needs to be changed, is the parameter under the comment “#Extent Description”;

# Extent description
RW 625142448 FLAT "\\.\PhysicalDrive1" 0

Specifically, what I have highlighted above.

Edit your VMDK file so that it specifies the Object we discovered earlier, it needs to be like this… once again this is for my specific hardware configuration, yours will be different, depending on the number of hard disks you have installed, among other things;

# Extent description
RW 625142448 FLAT "\\.\GLOBALROOT\ArcName\multi(0)disk(0)rdisk(1)" 0

You can obviously see what is going on here.  ”GLOBALROOT” is how VirtualBox will reference entries under the tree of Objects we examined using WinObj, and the enumerated hard drive will be referenced by “multi…” under “ArcName”. It’s actually very simple when you get the hang of it.

Save your file, and load up VirtualBox…

No complaints...looks good so far.

 

 

 

 

Looking at the “Storage” section on this screen for my “OldSystem” virtual machine, there are no error messages, so it seems we can fire up the Virtual Machine. It should be okay, so………

 

 

 

 

 

 

Hurrah!

 

 

 

And seemingly successfully reading the hard drive. Lets boot up Linux to test further…

 

 

 

 

 

 

Lookin good!

 

 

 

And it successfully boots up and works.

 

 

 

 

And that’s it for changing an existing VM configuration. From now on, no matter what Windows 7 does to the Disc # designation, Virtualbox should always know where to find it :)

B) Setting a VM up from scratch…

I won’t go into the fine details of how to set up a Windows 7-hosted virtual machine with full raw disk access – there are countless places which show you how to do that (okay, I will, if and when someone specifically requests this).

Basically, go through all the Disk identification steps I outlined above, and once you have your disk Object identified, and are about create a VMDK file using the VBoxManage internalcommands createrawvmdk command, instead of giving “PhysicalDrive1″ as your argument, use the “\\.\GLOBALROOT\ArcName\multi(0)disk(0)rdisk(1)” string instead.

Thus the VBoxManage command should look something like this…

VBoxManage internalcommands createrawvmdk -filename “C:\Users\kcave\.VirtualBox\SomeRawDiskNameOfYourChoice.vmdk” -rawdisk “\\.\GLOBALROOT\ArcName\multi(0)disk(0)rdisk(1)”

 

Well, it’s now 0019hrs and I’m sleepy :)

I do hope this article has been of help.

Edit: I have in fact tested this by switching the 2 hard drives onto different SATA ports and booting back up… no matter what order Windows enumerates the drives, the Virtualbox configuration still accesses the correct disk :)

 

VN:F [1.9.17_1161]
Rate This Article
Rating: 10.0/10 (8 votes cast)
VirtualBox on Windows 7 Host with Raw Disk Access - Solution to Randomly Changing Disc Assignment Numbers, 10.0 out of 10 based on 8 ratings
Share the knowledge :
Facebook Twitter Pinterest Linkedin Digg Delicious Reddit Stumbleupon Email

Related Posts :
Just copy/paste this entire line into a terminal window... sudo cd /usr/share/virtualbox/src/vboxhost && for file in `grep "autoconf.h" * -R| cut -f1 -d:`; do sed -i 's/^#(s*)include <linux/autoconf.h>/#1include <generated/autoconf.h>/g' $file; done Then ...
READ MORE
Ugh. My websites are self-hosted and run in virtual machines by way of Virtualbox. I have two physical servers, both can access the virtual drives used by my VM's via LVM ...
READ MORE
Problems with virtualbox 4.0.2 and linux kernel 2.6.38?
Problem with Virtualbox 4.1 and Teleporting

4 comments to VirtualBox on Windows 7 Host with Raw Disk Access – Solution to Randomly Changing Disc Assignment Numbers

  • avatar Chas

    OMG this saved me from a major headache!

    Thanks!

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  • I am testing your post now to solve that problem… I suggest you to edit your post to point to the current sysinternals website. They were aquired by Microsoft, http://technet.microsoft.com/en-us/sysinternals. This could prevent others to download modified (malwared) versions of WinObj.

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  • avatar Guest

    Thanks for this guide, I use an external eSATA drive as raw disk and the drive order is rearranged by Windows constantly, so it was a lifesaver.
    The online/offline issue was a bit different for me though.
    If I keep the drive online I can always write to it.
    If I deleted the existing partitions in diskmgmt.msc and then set the drive offline, I was able to write to while offline. I then created a partition in the guest OS and tested write access. As long as I kept it offline and Windows didn’t discover what was happening to the drive, everything worked. But if I switch the status to online again (which would happen if I reconnect the external drive anway), Windows discovers the new partition. Write access was still working. When I set it to offline while there was a partition visible to Windows, VirtualBox terminated with an VERR_WRITE_PROTECT error when attempting to use write to this drive in the guest OS. When I set it to online again, I was once again able to write to the drive.

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>