43

I created a virtualbox raw disk pointing to a functioning, booting USB drive with a small linux distro on it.

sudo ./VBoxManage internalcommands createrawvmdk -filename ~/VirtualBox\ VMs/MyTinyLinux/rawdiskonusb.vmdk -rawdisk /dev/disk2 -partitions 2

When I try to add it to a virtualbox VM, I get this error:

Failed to open the disk image file ~/VirtualBox VMs/MyTinyLinux/rawdiskonusb.vmdk.

Permission problem accessing the file for the medium '~/VirtualBox VMs/MyTinyLinux/rawdiskonusb.vmdk' (VERR_ACCESS_DENIED).

Result Code: VBOX_E_FILE_ERROR (0x80BB0004)
Component: MediumWrap
Interface: IMedium {4afe423b-43e0-e9d0-82e8-ceb307940dda}
Callee: IVirtualBox {0169423f-46b4-cde9-91af-1e9d5b6cd945}
Callee RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)

I saw that the raw disk vmdk file was owned by root. I chown'ed it to my own user.

Still get the same error. I suspect it would work if I ran virtualbox as root, but I really do not want to do that. Is there anyway to make this work?

adapt-dev
  • 1,329
  • 2
  • 13
  • 18
  • VirtualBox needs root access for a bunch of things, and you already use sudo so you might as well do a proper root startup to get proper environment and user properties. – Julie Pelletier May 21 '16 at 22:43
  • That's probably related to the "method" you used to create the disk. So, you're trying to access the USB disk, but the Error is referencing the previous image file location. – ILMostro_7 May 22 '16 at 01:55
  • Same issue for me. When I try to execute as sudo, it does not allow x64 machines, that was my case, and then there is no solution for me... :'( - usind on linux – kokbira Feb 08 '19 at 20:01

9 Answers9

42

User should be in a disk group to access raw partitions (as Gilles mentioned by last reference in his answer).

sudo usermod -a -G disk $USER
ASten
  • 671
  • 5
  • 7
  • 15
    this works for me too - **note** that you are required to log out after adding yourself to the group, or this change will not be applied. That goes for any group modifications actually – CybeX Dec 28 '17 at 07:53
  • Using only that command was sufficient for me – kokbira Mar 28 '19 at 17:59
  • 1
    You have to logout/in to have group membership reevaluated. You can do `su - $USER` to reevaluate it for a single terminal. https://superuser.com/questions/272061/reload-a-linux-users-group-assignments-without-logging-out – robm Jan 21 '22 at 22:46
  • 1
    As user you can also activate the new group by `newgrp disk; newgrp $USER` w/o logout. – abu_bua Mar 25 '22 at 17:07
  • What about on macOS, where `usermod` doesn't exist? – Tiago Feb 07 '23 at 10:45
  • 2
    OK so for anyone on Mac, it's enough to chown the disk you're trying to access: ``` sudo chown ${USER} /dev/disk3 ``` – Tiago Feb 07 '23 at 10:47
37

The poster used linux on the host machine. If you came here and use Windows as a host (like me) there is an easy solution to this error. Windows doesn't allow raw disk access if you don't start VirtualBox with administrator priviledges.

Pascal
  • 479
  • 4
  • 6
  • 1
    This answer used to work for me when I used VirtualBox 5.x, but I just tried with VirtualBox 6.1.38 and it doesn't seem to be working any more. Furthermore, with old versions of VirtualBox, when I started VirtualBox.exe as administrator it showed the VMs attached to the system's administrator account rather than my own user's, but now it shows my own VMs no matter how I start it. I guess they've updated it to drop admin priveleges? – occipita Dec 03 '22 at 23:00
18

from 2020 here:

  1. run virtual box service as administrator (VBoxSVC.exe), if running kill it first.
  2. run virtual box main executable (VirtualBox.exe whatever is on your desktop) as adminstrator too
kapodamy
  • 181
  • 1
  • 4
  • 2
    This answer is a bit unclear, also it is for Windows, not Linux… – Jaleks Apr 25 '20 at 20:00
  • This a thousand times... The fact that it's for Windows is irrelevant. This is information you cannot find anywhere else. I tried every combination of offline-ing disks, double clearing readonly attributes just to be sure, running as admin, not running as admin, etc to no avail... Finally, a solution to this damn problem that creeps up on me randomly once a year. Running VBovSVC as admin/su is crucial when you are running virtual machines on a physical medium. Thank you kapo! – DeeJayh Feb 19 '21 at 09:01
  • 4
    There is no need to start `VBoxSVC.exe` as Administrator. It's enough to kill it, if it wasn't started with elevated credentials. Then when you run `VBoxManage` or `VirtualBox` as Administrator, they will start `VBoxSVC.exe` automatically with the required integrity level. – facetus Nov 03 '22 at 19:12
  • @facetus - this used to work for me on older versions of virtualbox, but with 6.1.x I now find you do have to manually run VBoxSVC as suggested in the answer. – occipita Dec 04 '22 at 00:06
  • I don't think it has anything to do with the version of VirtualBox, but there is something with your setup. `VBoxManage` and `VirtualBox` of course start `VBoxSVC.exe` automatically, how else it could have worked. I've been using VirtualBox since first releases, it always worked this way, and works now. – facetus Dec 04 '22 at 01:17
12

Check the permission on all the files involved, including the directories: ~/VirtualBox VMs, ~/VirtualBox VMs/MyTinyLinux, ~/VirtualBox VMs/MyTinyLinux/rawdiskonusb.vmdk, /dev/disk2. The directories need to be readable and traversable by your user (chmod +rx) and the image file and the raw disk need to be readable and writable (chmod +rw).

You'll need to allow your user to access the disk; since /dev is populated automatically at each boot, you'll need to add a udev to do this. See Give a specific user permissions to a device without giving access to other users

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
6

Since there's no accepted answer, I'll post this as an answer for the moment. In addition to ensuring you're in the right groups, as others have posted above:

sudo usermod -a -G disk $USER
sudo usermod -a -G vboxusers $USER

If you are still getting the VERR_ACCESS_DENIED error, you need to, as per the comment by @Cybex, logout and log back in for the above group additions to take effect.

gone
  • 187
  • 2
  • 9
  • "vboxusers" was not needed for my case, only "disk" (fedora29). On mint19, I could not run that VM with rawdisk, except using sudo. – kokbira Mar 28 '19 at 18:00
5

Depending on the distribution, you might have to add your username to the VirtualBox group.

usermod -a -G vboxusers myusername

Additionally, according a similar Q&A on askubunt, you might have a corrupt ISO. In your case, I would guess it means a botched conversion to raw disk. Try searching on how to correctly do that procedure and repeat it, in case the conversion got botched somehow during the first procedure.


If that's still not a solution, then follow the advice in the VirtualBox Manual and add the -relative option:

Creating the image requires read/write access for the given device. Read/write access is also later needed when using the image from a virtual machine. If this is not feasible, there is a special variant for raw partition access (currently only available on Linux hosts) that avoids having to give the current user access to the entire disk. To set up such an image, use

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda -partitions 1,5 -relative

When used from a virtual machine, the image will then refer not to the entire disk, but only to the individual partitions (in the example /dev/sda1 and /dev/sda5). As a consequence, read/write access is only required for the affected partitions, not for the entire disk. During creation however, read-only access to the entire disk is required to obtain the partitioning information.

ILMostro_7
  • 3,199
  • 1
  • 21
  • 27
2

The problem (for me) was To show only file name without the entire directory path. ... Only filename is needed:

VBoxManage internalcommands createrawvmdk -filename rawdiskonusb.vmdk -rawdisk \\.\PhysicalDrive#

worked nicely.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
  • this worked for me on windows with ubuntu VM -- for some reason when i was doing like -filename C:\rawdisk it did not work, but -filename rawdisk does. It puts the file in the virtual box directory though (which is fine) – Richard DiSalvo May 31 '20 at 17:29
1

For A Windows Host (my case) I found THE only solution was a simple reboot of the host machine. Immediately attached without errors upon restart.

Jay Lepore
  • 111
  • 1
  • 1
  • 7
0

I had a similar problem but the issue was that I was running the sudo command while in finder I was in my home volume, I cd'd to Volume/Users/Owner where my profile is called owner and then it worked perfectly.