Electronic Team, Inc. uses cookies to personalize your experience on our website. By continuing to use this site, you agree to our cookie policy. Click here to learn more.

How to connect a hard drive to VirtualBox

Olga Weis Olga Weis Dec 18, 2023

Running VirtualBox with an external hard drive is a great way to extend the functionality of your virtual machine. Users can enjoy multiple benefits when they mount a USB hard drive in VirtualBox. However, there are some limitations and potential risks you may encounter. You need to know how to mount an external hard drive in VirtualBox efficiently. This article talks about how to create a hard drive in VirtualBox, the advantages of using an external storage device, and some of the problems you need to avoid.

The reasons to mount an external hard drive in VirtualBox

There are several reasons to mount a hard drive in VirtualBox, such as retaining your old OS and data as you move to a new system, isolating two OS versions, or just increasing productivity and the functionality of your VMs.

  • A physical hard drive attached to a VirtualBox VM adds flexibility to your computer. It allows you to run multiple operating systems simultaneously to facilitate software testing or run programs that require a specific environment.

  • An external hard drive may be necessary to enable users to run certain applications or operating systems that are incompatible with virtual drives. You can install an alternate OS or applications on a physical drive and then access and run them from VirtualBox to eliminate compatibility issues.

  • You can make an old operating system and its data available from a VM by using an external hard drive to store the data and code from the previous OS. Users can access the old OS through VirtualBox.

  • Implementing a physical hard drive with VirtualBox lets you isolate an operating system or application, minimizing possible security concerns. Sensitive data can remain on the external drive rather than being transferred to a virtual drive that may be less secure.

VirtualBox Raw Hard Disk Access

There are multiple methods of accessing the data on a hard drive from within virtual environments. One option is to use the contents of a physical drive to create a virtual hard disk image. At times, it may be more beneficial to mount or boot a physical hard drive directly from a guest VM.

VirtualBox enables you to mount all or part of a hard drive. You can designate specific partitions to be mounted or choose to use the complete disk. We will be discussing the method known as VirtualBox raw hard disk access. This is where the whole VirtualBox physical hard drive is mounted. The advantages of this method include giving users the ability to boot their system from an external USB drive or additional hard disk.

We will demonstrate how to accomplish this on Windows, Mac OS X, and Linux host operating systems.

Note: You should always backup your data before attempting to mount drives or partitions in your virtual machine. Avoid mounting or booting the partition running the host operating system, as it may result in substantial data corruption.

The first step is to use the VirtualBox user interface to create a virtual machine. Use your regular configuration except for the selection of a virtual hard drive. Choose the “Do not add a virtual hard drive” option.
You will need to identify the drive number and path of the physical drive you intend to mount. Use the appropriate method for your host operating system.

Windows: Open Disk Management where the drive numbers will be displayed on the left side. They will be identified as PhysicalDrive0, PhysicalDrive1, etc.

Mac OS X: Enter the “diskutil list” command which returns a list of the available disk partitions. The drive names will be displayed in the format /dev/disk0, /dev/disk1, and so on.

Linux: To list the partitions in Linux, the “sudo fdisk -l” command is used. The format for disks in Linux is dev/sda0, dev/sda1, etc.
Once you have obtained the drive number, you are ready to open the CLI of your operating system. When Windows is the host OS, you need to navigate to VirtualBox’s root directory. Use this command:
“cd C:\Program Files\Oracle\VirtualBox”.
At this point, you are ready to create a virtual hard drive file from the contents of the physical device. The generic commands below require you to use the name and number of your drive where appropriate.

For Windows: VBoxManage internalcommands createrawvmdk -filename
"C:\Users\<user_name>\VirtualBox VMs\<VM_folder_name>file_name.vmdk" -rawdisk \\.\PhysicalDrive#

For Mac OS X: VBoxManage internalcommands createrawvmdk -filename
"</path/to/file>.vmdk" -rawdisk /dev/disk#

For Linux: VBoxManage internalcommands createrawvmdk -filename
"</path/to/file>.vmdk" -rawdisk /dev/sda

The VMDK that is created is a small file that acts as a pointer to the physical hard drive. To use the disk, you just attach the VMDK to your virtual machine. Perform the following steps after opening to VirtualBox GUI.

  1. Select the desired virtual machine that will access the disk.
  2. Click “Settings > Storage > Add Hard Disk”.
  3. Select the “Choose existing drive” option.
  4. Choose the VMDK file previously created.

Your virtual machine can now boot from the physical drive associated with the VMDK file.

USB for Remote Desktop

Risks of Using External Hard Drives in VirtualBox

Some potential risks are involved when using a physical hard drive in a VirtualBox VM. Users need to be aware of these issues before adding an external hard drive to their VirtualBox virtual machine.

  • Data loss is possible if there are configuration problems with the external drive. If you don’t know how to mount an external hard drive in VirtualBox correctly, you'll end up with lost data or corrupted files. Verify that the hard drive you plan to use is compatible with the operating system and VirtualBox.

  • Performance may suffer when using a physical hard drive with a VirtualBox VM. The host and guest operating systems may both be accessing the device at the same time, negatively impacting performance. The user experience may be degraded by delayed response from the external storage device.

  • VirtualBox may have limited functionality or be incompatible with certain operating systems. An example is the known compatibility problems when trying to run VirtualBox on Microsoft Windows 11 systems.

  • Security can be an issue when using VirtualBox with data stored on an external drive. Computers with MMU virtualization enable direct memory access (DMA) where VMs can directly access peripheral devices such as external storage devices or graphics cards. PCI passthrough may allow other VMs to access data on the external hard drive. Users must verify all VMs are configured correctly and that they are running updated anti-malware.
small logo USB Network Gate
#1 at Networking Software
USB Network Gate
Share USB over Ethernet on Windows
4.7 rank based on 372 + users
Get a download link for your desktop
Submit your email address to get a link for quick download on your desktop and get started!
Also Available: USB Network Gate is a cross-platform solution compatible with Mac, Linux and Android OSes:

UNG for Mac

UNG for Linux

UNG for Android