Click Technology

Linux, Windows, Mac it's all good

Create Virtual Disk from physical hardware

February6

This came up the other day, how do you add a disk to VirtualBox that physically exists? E.G. you have created a test vbox and would like to plug in your old laptop hard drive and have a look at the contents..

Here goes..


sudo lsblk

And get the following similar output..


NAME                       MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                          8:0    0 465.8G  0 disk  
|-sda1                       8:1    0   243M  0 part  /boot
|-sda2                       8:2    0     1K  0 part  
|-sda5                       8:5    0 465.4G  0 part  
  +-sda5_crypt (dm-0)      252:0    0 465.4G  0 crypt 
    +-mint--vg-root (dm-1) 252:1    0 465.4G  0 lvm   /
sdb                          8:16   1   7.5G  0 disk  
|-sdb1                       8:17   1   459M  0 part  /media/your-username/usbstick
sdc                          8:32   0 465.8G  0 disk  
|-sdc1                       8:33   0   243M  0 part  
|-sdc2                       8:34   0     1K  0 part  
|-sdc5                       8:37   0 111.6G  0 part  

Examine the tree and find out what your old hardware is called, e.g. /dev/sdc in this case.

Now create a directory for the virtual disk..


mkdir -p /home/your-username-here/VirtualBox/spare_disks

And use vBox’s commandline tools to create the image, changing /dev/sdX for your device location, prolly /dev/sdc.


sudo VBoxManage internalcommands createrawvmdk -filename "/home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk" -rawdisk /dev/sdX

Now chown and chmod the varioius relevant locations and that’s it..


sudo chown your-username-here:your-username-here /home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk
sudo chmod 777 "/home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk"
sudo chmod 777 /dev/sdX

Now open VirtualBox and add in the disk in the usual way (Select your box, then –> settings –> storage –> select disk controller –> click ‘adds hard disk’ icon –> Select vmdk file and that’s it. Fire up your machine and voila, the machine sees the external disk. Nice.

posted under Linux Tips

Comments are closed.

This is my website for short blog posts and interesting materials that are noteworthy or have some handy-tip value.