I was trying to set up Metasploitable on VirtualBox. Metasploitable comes as a VMDK. VMDK is a virtual machine disk format developed by VMWare that is supposed to be supported by VirtualBox. Unfortunately, my ViirtualBox GUI wasn’t allowing me to choose the VMDK to attach to my VM. The VMDK just wasn’t showing up in the selection dialog.
Luckily, VirtualBox has command-line tools that allow you to specify whichever file you want. In case it’s important, I’m doing this on Ubuntu 20.04, but it should probably work anywhere. Also, I just read the command descriptions and then kinda trial-and-errored it until it worked, so I’m not promising this is the best way.
I’m assuming you have already created a virtual machine and you want to attach the VMDK to it. For our purposes, we’ll name it MyVirtualMachine.
First make sure you have the right VM name:
VBoxManage showvminfo MyVirtualMachine
Make sure that looks like the VM you are working with. Next, create a SATA controller on the VM if there isn’t already one present:
VBoxManage storagectl MyVirtualMachine --name sata --add sata
Now we can attach the VMDK called MyVirtualDisk.vmdk:
VBoxManage storageattach MyVirtualMachine --storagectl sata --port 0 --type hdd --medium path/to/MyVirtualDisk.vmdk
In this command, the –storagectl option is the name of the storage controller we created in the previous step.
You should now be able to return to the GUI and see the VMDK storage device attached to your VM.