20

What is the best method for setting the virtual hard drive (VDI) of the primary controller for an existing virtual machine?

Does the syntax change if the VDI is really a child differencing disk of some other parent disk? Do you need to attach the parent VDI and then the child VDI in some way?

Situation:

I have an existing VM --- I want to replace the hard drive it uses to boot - with either another normal virtual HD or possibly a differencing disk. Can this be done with VBoxManage?

Adam
  • 975
  • 1
  • 8
  • 13

6 Answers6

28

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".

calas
  • 381
  • 3
  • 5
4

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)

Sencer H.
  • 532
  • 1
  • 8
  • 17
Jontas
  • 261
  • 2
  • 5
2

You need first add de contoller on your vm machine:

vboxmanage storagectl YourVMNameOrID --name "SATA Controller" --add sata --controller IntelAHCI --portcount 1 --bootable on

and then attach the virtual disk image to the storage controller:

vboxmanage storageattach YourVMNameOrID --storagectl "SATA Controller" --device 0 --port 0 --type hdd --medium YourVirtualDiskImage.vdi 
rüff0
  • 121
  • 4
1

Just want to add to @calas with a VM managed by vagrant (run in VM's folder and replace sandbox_default_ with your VM name prefix):

VBoxManage storageattach `VBoxManage list vms | grep \"sandbox_default_ | awk '{print $2;}'` --storagectl SATA --port 0 --type hdd --medium box-disk1.vmdk
Martin Tapp
  • 131
  • 3
0

I'm not sure if you can do it though VBoxManage, I've always changed it through the GUI after using CloneHD, you answer may be in the VBoxManage Manuel

Mr Shoubs
  • 363
  • 2
  • 9
  • 32
0

In case this is helpful for anyone else working with a BootCamp partition that you have to make a new .vmdk for each boot, I had to do this in order to attach the image and avoid the annoying UUID mismatch problem:

Disconnect the medium from the virtual machine VBoxManage storageattach YourVMNameHere --storagectl "IDE" --device 0 --port 0 --type hdd --medium none

That way it doesn't complain when you remove the medium VBoxManage closemedium disk /path/to/your/medium.vmdk

Then when you attach the recreated medium you don't get checksum errors VBoxManage storageattach YourVMNameHere --storagectl "IDE" --device 0 --port 0 --type hdd --medium /path/to/your/medium.vmdk

Dave M
  • 4,494
  • 21
  • 30
  • 30