Attach physical disk to a virtual box VM

From Wiki
Jump to: navigation, search

Virtual Box does support attaching physical (raw) drives to a VM but there is no option for it in the GUI. To attach a drive to a VM you will first need to install the Oracle VM VirtualBox Extension Pack available here:

http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

After that is done you can create and attach a new virtual disk from the command line.

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
     -rawdisk /dev/sdf

This creates the image /path/to/file.vmdk (must be absolute), and all data will be read and written from /dev/sdf.

Just like with regular disk images, this does not automatically attach the newly created image to a virtual machine. This can be done with e.g.

VBoxManage storageattach <NAME> --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /path/to/file.vmdk

See http://www.virtualbox.org/manual/ch09.html#idp13208480 for more details.

Change UUID of a disk:

VBoxManage internalcommands sethduuid disk_image.vdi

Attach iSCSI target:

VBoxManage storageattach <vm> --storagectl IDE --medium iscsi --server 10.20.34.127 --target iqn.2001-05.com.equallogic:0-8a0906-b990cd108-a42000000d152a8a-wattersm-test --username username --password password --port 0 --device 0 --type hdd