How to add a new SATA disk to a running VirtualBox guest?

I installed a Centos7, booted it and want to add a new SATA disk online, but the "storage" part is grey. Other VirtualBox version supports it or is it fully not possible to add a new local disk for a running VM?

I don't want to power it off/on just because to add a new disk.


Solution 1:

You can, in fact, hot-add storage to a running VirtualBox VM, using VBoxManage storageattach:

VBoxManage storageattach <VM Name> \
  --storagectl <Controller Name> \
  --port <Port Number> \
  --device <Device Number> \
  --type hdd \
  --medium <Path to Disk Image>

(Please note that on Windows you may have to remove the backslashes and line breaks.)

If you have a SATA controller, the device number is always 0 and the entire parameter is optional.

If the VM name has spaces, enclose them in quotes. Same goes for the storage controller name and image path.

There are important preconditions, (check with VBoxManage showvminfo):

  • A hot-plug-capable controller must exist (like SATA, SCSI, SAS)
  • The storage controller must have unused ports or you’ll have to replace a disk
    • By default, the VirtualBox GUI allocates only as many ports as required, so a free port is most likely not available
  • The operating system running inside the VM must support hot-plugging disks

IIRC the GUI does not offer support for any of this.

Solution 2:

Inspired by Daniel's post, I was able to add new disks to a running CentOS 6 VM in VirtualBox 5.2.18 (host OS Linux Mint 19) via GUI by clicking the small plus sign on the squared blue icon sitting on the right side of Controller: SATA (it is not grayed out).
The prerequisite is to already have some available ports on the SATA controller. "Port Count" is 2 in the below image, only one disk attached, giving room for one more disk to add on the fly.

VirtualBox GUI's "Port Count:"

Adjust GUI's "Port Count:" to a desirable value before starting the VM, so at running time you'll have some spare capacity. I had one extra just because the VM had a (log ago removed) secondary disk.