Using a physical drive on a virtual machine

Discussions related to using VirtualBox on Linux hosts.
AngusM
Posts: 25
Joined: 13. Jun 2011, 22:45
Primary OS: openSUSE
VBox Version: OSE other
Guest OSses: WinXP

Using a physical drive on a virtual machine

Post 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.
stefan.becker
Volunteer
Posts: 7639
Joined: 7. Jun 2007, 21:53

Re: Using a physical drive on a virtual machine

Post 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.
AngusM
Posts: 25
Joined: 13. Jun 2011, 22:45
Primary OS: openSUSE
VBox Version: OSE other
Guest OSses: WinXP

Re: Using a physical drive on a virtual machine

Post 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.
47tuc
Posts: 3
Joined: 23. Jun 2011, 10:53
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: FreeBSD
Location: Hobart, Tasmania, Australia

Re: Using a physical drive on a virtual machine

Post by 47tuc »

I'm having exactly the same issue. Have you managed to to find a solution?
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Using a physical drive on a virtual machine

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
47tuc
Posts: 3
Joined: 23. Jun 2011, 10:53
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: FreeBSD
Location: Hobart, Tasmania, Australia

Re: Using a physical drive on a virtual machine

Post 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.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Using a physical drive on a virtual machine

Post 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?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
47tuc
Posts: 3
Joined: 23. Jun 2011, 10:53
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: FreeBSD
Location: Hobart, Tasmania, Australia

Re: Using a physical drive on a virtual machine

Post 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.
stefan.becker
Volunteer
Posts: 7639
Joined: 7. Jun 2007, 21:53

Re: Using a physical drive on a virtual machine

Post 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.
mblahay
Posts: 13
Joined: 27. Sep 2009, 05:00
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux, Windows

Re: Using a physical drive on a virtual machine

Post 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?
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Using a physical drive on a virtual machine

Post 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?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
mblahay
Posts: 13
Joined: 27. Sep 2009, 05:00
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux, Windows

Re: Using a physical drive on a virtual machine

Post by mblahay »

Please explain the mechanics of
how corruption can occur in that situation and how I can remedy the situation.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Using a physical drive on a virtual machine

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
mblahay
Posts: 13
Joined: 27. Sep 2009, 05:00
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux, Windows

Re: Using a physical drive on a virtual machine

Post by mblahay »

Thanks, I will try unmounting the disk from the host and see if that helps.
mblahay
Posts: 13
Joined: 27. Sep 2009, 05:00
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux, Windows

Re: Using a physical drive on a virtual machine

Post 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.
Post Reply