Stupid VirtualBox & ZFS Tricks

So the other day I had the idea to flip things around, instead of running a Windows 7 guest within an OpenSolaris host (with virtualbox) on my desktop, run an OpenSolaris guest within a Windows 7 host.

I thought I'd do this on my primary desktop at work. The only problem is that I have a ZFS pool that contains the large majority of all my work at Sun over the nearly 20 years. Without access to that, the whole "experiment" would be of little use.

Fortunately the pool was on a second set of disks in the desktop, so I could happily leave it alone while I did the first part of the switch, install Windows 7 (64bit) and VirtualBox on bare metal, and then an OpenSolaris guest. This was all pretty straight forward, nothing additional I can offer over what is out there already.

Now the interesting part(s), first hurdle, how do I get VirtualBox to recognize the physical disks the ZFS pool resides on. After a little web searching, it ended up being pretty easy, the key is to use the VBoxManage internalcommands createrawvmdk command that VirtualBox provides.

Using this command, you can create a vmdk definition that points to a physical disk or partition. In my case, I wanted to point to the entire disk, so I used the following commands.

VBoxManage internalcommands createrawvmdk -filename C:\\Users\\Mocker\\.VirtualBox\\HardDisks\\PhysicalDrive2.vmdk" -rawdisk \\\\.\\PhysicalDrive2 -register
VBoxManage internalcommands createrawvmdk -filename C:\\Users\\Mocker\\.VirtualBox\\HardDisks\\PhysicalDrive3.vmdk" -rawdisk \\\\.\\PhysicalDrive3 -register

Now, here's the rub, in order to do this, VBoxManage needs to be run as administrator. Windows 7 apparently has some pretty tight restrictions on who/what is allowed to access raw disks. One of the easier ways to do this is to just run a command shell as administrator, which will then execute VBoxManage as administrator.

I did this by simply clicking the Start menu, entering "cmd" in the search box, which will present cmd.exe as a result, right click on cmd.exe and select "Run as Administrator".

Ok so now I had created vmdks for the physical drives. I needed to attach them as virtual disks to my OpenSolaris guest. I just used the VirtualBox UI for this. Click on the guest (make sure its not running), then click on the Storage section of the configuration, Add a couple of hard disks using the "Add Hard Disk" button of the IDE controller, then select the physical drive vmdks for each.

Note, same rub as above applies, I needed to run VirtualBox as administrator. This is getting to be a drag.

Finally, the moment of truth, time to fire up the OpenSolaris guest, and see if it will recognize the ZFS pool...

After the guest booted up, I logged in, using the format command, I could see the guest recognized the new disks, good.

Next, I ran zpool import, and, drum roll, yes, it indeed found my ZFS pool!

Finally, I ran zpool import <poolname> and voila! OpenSolaris happily imported the pool - lock, stock and barrel --

# zpool status storage
  pool: storage
 state: ONLINE
 scrub: none requested
    storage     ONLINE       0     0     0
      mirror-0  ONLINE       0     0     0
        c8d1s0  ONLINE       0     0     0
        c7d1s0  ONLINE       0     0     0

One caveat, I noticed Windows 7 doesn't play well with EFI labels. Although this initial attempt worked fine, later on I found that the pool became inaccessible after reboots of the guest. Running the Disk Management tool in Windows would complain about these two disks since they had EFI labels on them.

I managed to fix this pretty easily though, I simply booted back into OpenSolaris on bare metal (yeah, I actually created a dual boot system), then though a process of zfs detach, format, zfs attach, I relabeled the disks and Windows 7 was much happier.


[Trackback] Your story was featured in! Here is the link to vote it up and promote it:

Posted by on February 28, 2010 at 04:15 AM PST #


On there is a post where a guy did exactly what you did on WinXP. He installed OpenSolaris into VB and accessed all his raw drives. Then he created a zfs raid and used it. But because VB does not honour the "flush write"(?), he lost all his data on his ZFS raid. It got corrupted. ZFS gets a report from VB that everything is written to disc, but that is not true because VB rearranges writes because it does not obey "flush write"(?). So ZFS thought everything was safe, but it was not safe.

Hence, if you run OpenSolaris virtually and accesses raw discs for ZFS, your entire pool may be corrupted. I would never do that.

Posted by kebabbert on March 21, 2010 at 10:11 AM PDT #

In VB there is an option to enable the flush command.

Search in the VB documentation.

So your concerne is pointless afterall.

Posted by Philip Weber on May 30, 2010 at 03:52 AM PDT #

Actually, here it is:

Posted by Philip Weber on May 30, 2010 at 04:01 AM PDT #

Hello and great post!

I have some troubles understanding the last bit where you talk about relabeling. Are these two disks still labeled as EFI? Which label should we use to avoid Windows complaining and hence causing potential damage to those disks or not allow to access those disks under VirtualBox OpenSolaris without some drastic (like rebooting to bare metal OpenSolaris)?

And about those comments:
What would be command to enable flushes for the setup mentioned in this post?
He is using PhysicalDrive2 and PhysicalDrive3. (Is 2 and 3 what we are entering in X?)
Something like:
VBoxManage setextradata "VM name" "VBoxInternal/Devices/ahci/0/LUN#[2]/Config/IgnoreFlush" 0
VBoxManage setextradata "VM name" "VBoxInternal/Devices/ahci/0/LUN#[3]/Config/IgnoreFlush" 0

Also a bit confused with "Add a couple of hard disks using the "Add Hard Disk" button of the IDE controller".
Is VirtualBox treating disks as IDE regardless if they are in fact SATA. Would that affect upper Flush Ignoring (what about here; how to figure out what X is?):
VBoxManage setextradata "VM name" "VBoxInternal/Devices/piix3ide/0/LUN#[2]/Config/IgnoreFlush" 0
VBoxManage setextradata "VM name" "VBoxInternal/Devices/piix3ide/0/LUN#[3]/Config/IgnoreFlush" 0

Thank you for your answers.

Posted by goran on January 01, 2011 at 11:12 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed



Top Tags
« October 2016

No bookmarks in folder