Skip to main content

Cloning VirtualBox machines

Much has been written about cloning VirtualBox guests, currently this should all be a matter of:
  VBoxManage export rhel-0 --output /Volumes/HFS/vm/rhel1/rhel1.ovf
  VBoxManage import /Volumes/HFS/vm/rhel1/rhel1.ovf 
  VBoxManage modifyvm rhel-0_1 --name rhel-1
If you forgot to set
   VBoxManage setproperty hdfolder /Volumes/HFS/vm/rhel1/
before importing the VM (hah!), the new (and converted?) rhel-0.vmdk ends up in the "default hdfolder", which is set to "/Volumes/HFS/vm/" in my case and the disks of new imported/cloned VMs would pollute the directory layout :-( Anyway, here's how to relocate the disk, hammer-style:
  # First we're going to detach and close the disk
  VBoxManage storageattach rhel-1 --storagectl "SATA Controller" --port 0 \
                                                    --device 0 --medium none
  VBoxManage closemedium disk 98ba164c-98e4-4892-a3c4-c73c12adc594

  # Move the disk to the right place
  mv ../../rhel-0.vmdk rhel1/rhel-1.vmdk 

  # re-attach the disk
  VBoxManage storageattach rhel-1 --storagectl "SATA Controller" --port 0 \
            --device 0 --type hdd --medium /Volumes/HFS/vm/rhel1/rhel-1.vmdk 
Now we should be able to start the VM with
   VBoxHeadless -s rhel-1 &
...just as any other VM. Yay!