Linux – Sharing a hard disk partition with a Linux VM on VirtualBox

external-hddlinuxvirtual machinewindows

Let me just paint the picture so you can all understand.

My host OS is Windows 10.
I have VirtualBox installed on my Windows OS, and in VirtualBox I have a Kali distro running. This VM and its files are located on my external HDD.

There is a partition on my external HDD which I want to access through my Kali Linux VM.

Adding the external HDD to the virtual machine as a USB device isn't possible, since it would completely disconnect from my host Windows OS and then of course VirtualBox wouldn't be able to access this machine anymore.

Sharing a folder isn't possible since I cannot actually locate this partition from within my Windows host OS.

Is there any work-around possible to access this partition while I'm in Kali Linux, that doesn't involve copying the VM folder to another HDD?

External HDD partition layout is like this:

--- D:/   (Here resides a backup of my Windows host OS)
--- E:/   (Partition where I keep the VirtualBox hard disk file of Kali Linux)
---- HIDDEN ---- (This is the hidden encrypted partition formatted EXT3)
--- F:/   (Partition with games)

Best Answer

Assuming you have sufficient access rights to the device, you should be able to access the hidden partition from the VM by creating a special vmdk file that will map the raw partition to a virtual device.

You need to first identify the wanted partition with something like:

C:\Program Files\Oracle\VirtualBox> VBoxManage internalcommands listpartitions -rawdisk \\.\physicaldriveX

Replace X by the disk identifier (0 is the first internal).

This will show a table with all partitions of the disks, the first columns shows the partition number.

Then, assuming you want to access partition #3 on disk #2, you can create the vmdk file with this command:

C:\Program Files\Oracle\VirtualBox> VBoxManage internalcommands createrawvmdk -filename "C:\Users\Dennis\VirtualBox VMs\kali\part3.vmdk" -rawdisk \\.\PhysicalDrive2 -partitions 3

The part3.vmdk file might then be added as a new device to your VM.

As with any commands dealing with raw disk access, I would strongly recommend doing proper backups of anything valuable present on your disks before attempting this as any mistake might destroy your data/file systems. Especially, having the same file system mounted simultaneously by multiple OSes will quickly corrupt it.

References:

Related Question