Add an extra virtual hard drive to your virtual machine

In this article I am going to describe process of adding an extra virtual hard drive to a running virtual machine (hotplug a hard drive). It can be a new virtual hard drive to add an extra storage to VM or an existing virtual hard drive that you want to attach to recover some files that are stored on it for example. I faced this task last week and with help from my work colleague I succeed and I decided that it may be good to make a note how it can be done for future reference. It was not possible to power off machine as it was running websites for some projects the only option was to hotplug hard drive and enable it under operating system.

I performed these steps using VMware software, it covers hotplug a hard drive in a virtual machine running Ubuntu.

  1. Power on your virtual machine if it isn't - in my case it was Ubuntu server already powerd on.
  2. 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).
  3. Back to your Ubuntu VM terminal, make sure that you have root access to perform rest of the steps.
  4. 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.
  5. List of all available hosts using this command: ls /sys/class/scsi_host (output should show for example host0 host1 host2)
  6. 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)
  7. 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.
  8. 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.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.