Virtualbox Use Physical Disk

This comes from the good article here, or in the VirtualBox documentation.

Hard Disk Controllers. In a computing device, hard disks and CD/DVD drives are connected to a. So I am trying to set up raw device access w/ VirtualBox to use a ext4/linux disk as a guest OS within Mac OS X, but haven't succeeded yet. Following the VirtualBox docs, Chapter 9.9.1.1, https://.

Virtualization has been a tremendous help to developers such as myself. It keeps us from having to keep a pile of hard drives/machines all running different operating systems. And while this is great, there are some times when you might want to use a raw hard drive. For example, if you pull a hard drive out of an existing system and want to keep the OS/data intact but use it as a virtual machine inside another host OS.

Well, you can set up VirtualBox to use a physical hard drive inside a VM. This method is called “raw hard disk access.” This allows you to mount or boot a secondary hard drive or external USB as your storage device inside the VM.

Warning: Do not attempt to mount or boot the partition that runs the host OS with a VM, as that can lead to severe data corruption. And no matter which drive or partition you want to mount, it’s always a good idea to back up any existing data on it before continuing.

Attach physical drive to virtualbox

Creating the Virtual Machine:

You’ll first want to create a virtual machine within the VirtualBox GUI. Choose all options like normal, but when asked about the virtual hard drive, select Do not add a virtual hard drive.

Next, you’ll need to find the path and drive number of the physical drive you’d like to mount:

In Windows, open Disk Management. You’ll see the associated drive numbers on the left and will identify them later as PhysicalDrive0, PhysicalDrive1, etc.

In Linux, run the following command: sudo fdisk -l. You’ll see a listing of the partitions. Make note of the desired drive in the format of dev/sda0, dev/sda1, etc.

In Max OS X, use the following command: diskutil list. You’ll see a listing of the partitions. Make note of the desired drive in the format of /dev/disk0, /dev/disk1, etc.

Now open the CLI of your OS. If you’re using Windows as the host OS you will also need to go to the root directory of VirtualBox using the following command: cd C:Program FilesOracleVirtualBox

Creating the VirtualBox Hard Drive:

Now you can run the command to create the virtual hard drive file that points to your desired physical drive. For each of the following examples ensure that you input the desired names between the arrows and replace the number or pound sign with your desired drive number.

Attach Physical Drive To Virtualbox

For Windows:
You often must be administrator to run this command. Make sure your cmd.exe is running as administrator. This also means you must start VirtualBox as administrator to use these drive links.

Virtualbox Use Physical Disk Partitioning

VBoxManage internalcommands createrawvmdk -filename 'C:UsersVirtualBox VMs.vmdk' -rawdisk .PhysicalDrive#

Virtualbox Use Physical Disk Recovery

For Linux:

VBoxManage internalcommands createrawvmdk -filename '.vmdk' -rawdisk /dev/sda

Virtualbox Use Physical Disk In Windows 10

For Mac OS X:

VBoxManage internalcommands createrawvmdk -filename '.vmdk' -rawdisk /dev/disk#

This VMDK will be a very small file that simply points to your physical drive. Now you can attach the VMDK to your VM. To do so, open the VirtualBox GUI, select the desired VM, click Settings, clickStorage, click Add Hard Disk button, select Choose existing drive, and then select the VMDK file you just created.

As the virtual machine will most probably expect to see a hard disk built into its virtual computer, Oracle VM VirtualBox must be able to present real storage to the guest as a virtual hard disk. There are presently three methods by which to achieve this:

  • Oracle VM VirtualBox can use large image files on a real hard disk and present them to a guest as a virtual hard disk. This is the most common method, described in Section 5.2, “Disk Image Files (VDI, VMDK, VHD, HDD)”.

  • iSCSI storage servers can be attached to Oracle VM VirtualBox. This is described in Section 5.10, “iSCSI Servers”.

  • You can allow a virtual machine to access one of your host disks directly. This is an advanced feature, described in Using a Raw Host Hard Disk From a Guest.

Each such virtual storage device, such as an image file, iSCSI target, or physical hard disk, needs to be connected to the virtual hard disk controller that Oracle VM VirtualBox presents to a virtual machine. This is explained in the next section.

Copyright © 2004, 2020 Oracle and/or its affiliates. All rights reserved. Legal Notices