How to attach a virtual hard disk using VBoxManage?

Solution 1:

Pretty old question but here is how I do it:

VBoxManage storageattach my-vm-name \
                         --storagectl "SATA Controller" \
                         --device 0 \
                         --port 0 \
                         --type hdd \
                         --medium /path/to/my-new.vdi

This assumes you want to replace the old disk. If you want to want to just add another disk use another port, for example 1 if you have only 1 disk (on port 0). Please note you could also add disks (or cd/dvd images) to "IDE Controller".

Solution 2:

I believe this should do it for a virtual hard drive.

VBoxManage modifyvm winxp-web-dev --hda "/home/vbox/.VirtualBox/HardDisks/my_new_disk.vdi"

(That is how I do it when I create vm's from the console)