TITLE: Add a raw disk to a virtualbox virtual machine
MARK: Eotect
DATE: 2022-11-26
SOURCE: https://ahelpme.com/software/virtualbox/add-a-raw-disk-to-a-virtualbox-virtual-machine/
[Add a raw disk to a virtualbox virtual machine | Any IT here? Help Me!](https://ahelpme.com/software/virtualbox/add-a-raw-disk-to-a-virtualbox-virtual-machine/) |
Add a raw disk to a virtualbox virtual machine
This is strange there is no way to add a physical disk to your virtual machine under virtualbox! Still it is possible and it is simple, but you need to execute few commands under console so you need to open a terminal and to have a root privileges!
To use a raw disk in our virtual machine we must create a special VMDK file and then to use it when adding a hard drive to our virtualbox virtual machine with ※Use an existing virtual hard disk dile§.Here are the right steps to add a raw disk:
STEP 1) Permissions your user must have (write) permissions to access raw disks
In most cases your user do not have write permission to the disk 每 it is the same under MS Windows and any Linux distribution (and probably MAC)! So here is the right way how to give permissions under Linux and Windows:
- Under Linux (Ubuntu, Centos, Fedora, Gentoo and probably all other). There are at least two ways to give WRITE permission to the raw disk (use one of them, the first one is preferred). We want to add our third disk the ※/dev/sdc§ so the examples are with this device:
add your user to ※disk§ group and log out. After you log in you*ll have WRITE permissions to the disks. Probably you must log off your GUI (Gnome, KDE and so on), too!
1
srv@
local
~ $
sudo
sudo
usermod
-a -G disk myuser
※myuser§ is the username of the user I am logged in. The log out and log in (if you are using a GUI 每 gnome, kde or something else, you must log out from the GUI, too and then log in again).
- execute virtualbox with root user
change the permission of the physical device you want to use (this is temporary, because next time you reboot you must change it again)
1
srv@
local
~ $
sudo
chmod
o+rw
/dev/sdc
- Under Windows 10 (or 7) 每 you must start the command prompt and Virtualbox with ※run as Administrator§ 每 look at the next step (STEP 2).
STEP 2) Add the raw disk
Under Linux (use one of these solutions)
With ordinary user and WRITE permission is set:
1
2
srv@
local
~ $ VBoxManage internalcommands createrawvmdk -filename
/home/myuser/
.VirtualBox
/physical-sdc
.vmdk -rawdisk
/dev/sdc
RAW host disk access VMDK
file
/home/myuser/
.VirtualBox
/physical-sdc
.vmdk created successfully.
As you can see no root is required and now you can start VirtualBox without root permissions as always you have done it.
With root user
1
2
3
srv@
local
~ $
sudo
VBoxManage internalcommands createrawvmdk -filename
/home/myuser/
.VirtualBox
/physical-sdc
.vmdk -rawdisk
/dev/sdc
RAW host disk access VMDK
file
/home/myuser/
.VirtualBox
/physical-sdc
.vmdk created successfully.
srv@
local
~ $
sudo
VirtualBox
※/home/myuser§ is my home user directory. Yours could be with different name so change the name accordingly.
Under Windows (7 and 10)
First you must start the command line tool under linux also with administrative privileges!
Search for command prompt and with right click you hit ※Run as administrator§. Change the directory to the VirtualBox executables and then execute the command. Use your path for ※filename§ (c:\Users\homer\.VirtualBox\physical-sdc.vmdk 每 change to your path), your home user directory or nay other directory you use for storing the VirtualBox files.Command Prompt 每 Run as Administrator
Accept the privileges escalation:
Administrator escalation confirmation
Execute the following line:
1
2
3
4
5
6
7
8
9
Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Windows\system32>
cd
C:\Program Files\Oracle\VirtualBox
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe internalcommands createrawvmdk -filename
"c:\Users\homer\.VirtualBox\physical-sdc.vmdk"
-rawdisk \\.\PhysicalDrive3
RAW host disk access VMDK
file
c:\Users\homer\.VirtualBox\physical-sdc.vmdk created successfully.
C:\Program Files\Oracle\VirtualBox>
As you can see now we have a generated file, which can use when creating a virtual machine (look at STEP3))
VMDK file created
* Create virtual machine under Linux and Windows using raw disk
Under Windows 10 (and 7) we must run VirtualBox as administrator. Skip this if you are using linux.
Windows 每 Run as administrator
Confirm administrator privileges escalation under Windows 10 (and 7). Skip this if you are using linux.
Windows 10 administrator confirmation
Create Virtual Machine with name ※test§
Create Virtual Machine
Set the memory to the virtual machine 每 for example 1024Mbytes.
Memory size
Set the hard disk 每 our VMDK file to use our raw disk. Check ※Use an existing virtual hard disk file§ and click on ※Choose a virtual hard disk file#§ 每 a dialog will open.
Set the hard disk
- Navigate to where is your freshly created VMDK file from the STEP 2) and select it to open.
Click ※Create§ to create the virtual machine.
Create
* Here is how it looks like our VMDK file in VirtualBox ※Virtual Media Manager§
* Troubleshooting under Linux
The permission problem accessing the disk under linux 每 NO WRITE permissions here:
1
2
3
srv@
local
~ $ VBoxManage internalcommands createrawvmdk -filename
"sdc-physical.vmdk"
-rawdisk
/dev/sdc
VBoxManage: error: Cannot
open
the raw disk
'/dev/sdc'
: VERR_ACCESS_DENIED
VBoxManage: error: The raw disk vmdk
file
was not created
* Troubleshooting under Windows (10)
The permission problem accessing the disk under linux 每 NO WRITE permissions here:
1
2
3
4
5
6
7
8
9
10
Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\homer>
cd
C:\Program Files\Oracle\VirtualBox
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe internalcommands createrawvmdk -filename
"c:\Users\homer\.VirtualBox\physical-sdc.vmdk"
-rawdisk \\.\PhysicalDrive3
VBoxManage.exe: error: Cannot
open
the raw disk
'\\.\PhysicalDrive3'
: VERR_ACCESS_DENIED
VBoxManage.exe: error: The raw disk vmdk
file
was not created
C:\Program Files\Oracle\VirtualBox>
You did not execute Command Prompt ※Run as administrator§
And if you get the following error:
1
2
3
4
5
6
7
Permission problem accessing the
file
for
the medium
'C:\Users\homer\.VirtualBox\physical-sdc.vmdk'
(VERR_ACCESS_DENIED).
Result Code: VBOX_E_FILE_ERROR (0x80BB0004)
Component: MediumWrap
Interface: IMedium {4afe423b-43e0-e9d0-82e8-ceb307940dda}
Callee: IVirtualBox {9570b9d5-f1a1-448a-10c5-e12f5285adad}
Callee RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)
Create a virtual machine with our VMDK file
Create a virtual machine
Use our VMDK file
Use an existing virtual hard disk file
VirtualBox 每 Error
VBOX_E_FILE_ERROR
What is in the VMDK file generated for a raw disk
Linux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Disk DescriptorFile
version=1
CID=c7936918
parentCID=ffffffff
createType="fullDevice"
# Extent description
RW 1953525168 FLAT "/dev/sdc" 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="6386fe41-7f5c-49b6-930f-1bb7dd811603"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
ddb.geometry.biosCylinders="1024"
ddb.geometry.biosHeads="255"
ddb.geometry.biosSectors="63"
Windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Disk DescriptorFile
version=1
CID=7999bf08
parentCID=ffffffff
createType="fullDevice"
# Extent description
RW 250069680 FLAT "\\.\PhysicalDrive3" 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="70bcd06f-51e5-4468-b9ed-f356be4afd6b"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
Author neoXPosted on May 10, 2018May 16, 2018Categories VirtualBoxTags full virtualization, linux, usermod, VBoxManage, virtualbox, windows