Page 1 of 2

Using a physical drive on a virtual machine

Posted: 13. Jun 2011, 23:33
by AngusM
It is possible for a virtual machine to mount a physical drive? It only seems to want to make/use virtual drives.

I'm running a Ubuntu 10.04 host and Oracle VirtualBox 4.0.8.

Re: Using a physical drive on a virtual machine

Posted: 13. Jun 2011, 23:54
by stefan.becker
Yes, its possible. But its a feature for professionials because of disk may get corrupted.

Its decribed in the manual (raw disk access). But first use the standard mode (guest on a vdi image), so that you know, what virtualization is.

Re: Using a physical drive on a virtual machine

Posted: 14. Jun 2011, 00:25
by AngusM
Hmm, yes I see. Could I add it as read-only? I have to need no write to the drive.

But I'm running into a few problems:
  1. I tried

    Code: Select all

    VBoxManage internalcommands createrawvmdk -filename /home/angus/VirtualBox\ VMs/XP/my_hdd.vmdk -rawdisk /dev/sda
    but it told me
    VBoxManage: error: Cannot open the raw disk '/dev/sda': VERR_ACCESS_DENIED
  2. Assuming it was a permissions issue I put a sudo in front of it, and it worked
  3. Now trying to add my_hdd.vmdk in the GUI gave me:
    Failed to open the hard disk /home/angus/VirtualBox VMs/XP/my_hdd.vmdk.
    and for details:
    Result Code:
    NS_ERROR_FAILURE (0x80004005)
    Component:
    Medium
    Interface:
    IMedium {9edda847-1279-4b0a-9af7-9d66251ccc18}
    Callee:
    IVirtualBox {d2de270c-1d4b-4c9e-843f-bbb9b47269ff}
  4. Then, assuming it was because it'd created my_hdd.vmdk as owned by root, I changed the ownership and group to angus, but I still get the same error.
  5. Code: Select all

    VBoxManage storageattach XP --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/angus/VirtualBox\ VMs/XP/my_hdd.vmdk
    returns
    VBoxManage: error: The medium '/home/angus/VirtualBox VMs/XP/my_hdd.vmdk' can't be used as the requested device type
    VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Medium, interface IMedium, callee nsISupports
    Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, pMedium.asOutParam())" at line 209 of file VBoxManageDisk.cpp
    VBoxManage: error: Invalid UUID or filename "/home/angus/VirtualBox VMs/XP/my_hdd.vmdk"
    (although, this might not be what I wanted it to do, because the manual promises that the vm will boot off the physical disk)
I've been through the manual and I'm out of ideas.

Re: Using a physical drive on a virtual machine

Posted: 25. Jun 2011, 14:32
by 47tuc
I'm having exactly the same issue. Have you managed to to find a solution?

Re: Using a physical drive on a virtual machine

Posted: 25. Jun 2011, 14:47
by Sasquatch
Direct disk access is a special privilege that is dangerous to have. So only the disk user and root can access them in read/write raw mode. You found that out when creating the VMDK.

You can't use RAW disk and make it read only. Especially when using it for boot. Want to access the files, use network shares or shared folders.

Re: Using a physical drive on a virtual machine

Posted: 25. Jun 2011, 14:57
by 47tuc
What I want to do is boot my freebsd VM from the normal virtual disk provided through the host OS but I want that VM to also have access to a second disk in "raw" mode. I want to have the FreeBSD access that raw disk using ZFS and I don't want to layer the ZFS filesystem on top of whatever filesystem the host is using. I understand that it may be dangerous in some circumstances but my machine has several physical drives and the one I want for raw access is not used by the host at all and I'm prepared to accept the risks.

John.

Re: Using a physical drive on a virtual machine

Posted: 25. Jun 2011, 15:32
by Sasquatch
So? How does that change the facts I've just noted? The post above showed how it's done, the manual shows how you use RAW disk. What's keeping you?

Re: Using a physical drive on a virtual machine

Posted: 26. Jun 2011, 02:12
by 47tuc
What I was hoping for was some helpful advice on how to set up the raw disk facility. I've read the manual several times and tried it several times on a test system but I get the same issues as AngusM mentioned earlier in this thread.
It may be that I've simply overlooked a minor detail or it may be that there's a bug in the system. Either way I'd like someone to suggest what I could try next.

Re: Using a physical drive on a virtual machine

Posted: 26. Jun 2011, 07:05
by stefan.becker
That is what i said.

There are 2 possibilities: You know what you do and it works.

Or it works not, And that is better, because of disk corruption will be following this way.

Use the standard way with an image for the guest and shared folders. That is an approach without any risk.

Re: Using a physical drive on a virtual machine

Posted: 8. Jul 2011, 05:43
by mblahay
Lets do everyone a favor and keep this discussion clear of the negative talk. We all know the risks involved, but for whatever reason, we want to use a raw disk.

I also have need of this solution. I was using raw disk access on a Windows host, but have changed the host to Linux. I am not having difficulty. I believe I have gotten one step further than the others on this discussion in that I was able to assign the disk to the guest and boot up.

You have to make sure the user running VirtualBox has read/write access to the device. The way I accomplished this was assigning the disk group to the user using the adduser command.

So, like I said, the guest booted fine, then when I tried the access the drive on the guest (a Windows guest) it froze up on me and I had to power down the VM.

I had not unmounted the device from the host file system, would that have caused a problem? Any thoughts?

Re: Using a physical drive on a virtual machine

Posted: 8. Jul 2011, 23:51
by Sasquatch
mblahay wrote:I had not unmounted the device from the host file system, would that have caused a problem? Any thoughts?
Trying to use one partition from two places is exactly where the corruption occurs. You know the risks of RAW disk, but you don't know how extremely dangerous this is?

Re: Using a physical drive on a virtual machine

Posted: 9. Jul 2011, 04:50
by mblahay
Please explain the mechanics of
how corruption can occur in that situation and how I can remedy the situation.

Re: Using a physical drive on a virtual machine

Posted: 9. Jul 2011, 13:05
by Sasquatch
I already explained that: make the data available on two separate systems at the same time using RAW disk. If you don't unmount the partition/drive when using VB, then two OSes that have no idea about the other's whereabouts will attempt to read and write the same file system. Have you ever tried to write on the same piece of paper on the exact same place as someone else, and you didn't know about the other's existence? That's what you have here.

Re: Using a physical drive on a virtual machine

Posted: 9. Jul 2011, 18:56
by mblahay
Thanks, I will try unmounting the disk from the host and see if that helps.

Re: Using a physical drive on a virtual machine

Posted: 20. Jul 2011, 14:56
by mblahay
I got it working, though the disk I was initially trying to mount to the VM I am still having issues with. I must have some underlying problem with that disk that is causing my Windows VM to not read it. The disk is read just fine by the ubuntu host. The second disk I tried, also an NTFS, attaches to the VM as expected and works. Surprisingly, it works whether it is mounted on the host or not. Please note that I am not advocating that the drive stay mounted on the host, its just that the mounting tends to happen automatically with Ubuntu and I have to figure out how to prevent it.

I hope my experience with this helps.