I performed these steps using VMware software, it covers hotplug a hard drive in a virtual machine running Ubuntu.
- Power on your virtual machine if it isn't - in my case it was Ubuntu server already powerd on.
- Right click on the VM and select Edit setting, and add a new virtual hard drive or existing (for more detailed instruction search Internet or check this page).
- Back to your Ubuntu VM terminal, make sure that you have root access to perform rest of the steps.
- If you use now fdisk -l it doesn't list the hard drive we have just added to our virtual machine. We have to rescan the SCSI bus.
- List of all available hosts using this command: ls /sys/class/scsi_host (output should show for example host0 host1 host2)
- To rescan SCSI bus I use this command: echo "- - -" > /sys/class/scsi_host/host#/scan replace # by available host in your system (in my case I would rescan host0, host1, and host2)
- If you check now what hard drives operating system can see by typing: fdisk -l you should be able to see hard drive we added.
- At this stege system can see attached hard drive: you can mount it and search for files or what you need to do with it.
I did not know that you can do something like this and I have to say it is nice and handy feature. I repeated above instruction again at home: VMware Workstation, guest OS Ubunut 12.04LTS, hotplug a new hard drive and it worked without problem.
I tried to add a virtual hard drive to powered on VM under VirtualBox but it looked like it was not possible to perform that. I did some further research just to make sure that I was not missing something and it confirmed that at some stage there was added only experimental feature to VirtualBox that allowed with command line program VBoxManage to add hard drive when VM was powered on (at least theoretically as I did not test if this is true). I looked at changelog for VirtualBox 4.2 (this is the current release of VirtualBox when I am writing my notes) and there was not single word about this feature.
I understand that most people use VirtualBox for home use and there is not much problem to power off VM, add a virtual hard drive to VM and power it on again. But I would like to see this feature especially that with VMPlayer you are able to do that.