Need to move a virtual machine, only to find that copying and pasting doesn’t work? Perhaps you just want to know what to backup? Take a look at this quick guide on the process to get a better understanding of VirtualBox
First things first: be sure that your virtual machine is shut down and powered off. Next, make sure you get rid of any snapshots you have. There isn’t a fool-proof and safe way to do this without getting rid of them, unfortunately. Select your virtual machine and click on the “Snapshots” tab.
Select your snapshot and click the delete button. Be prepared to wait a while as VirtualBox merges differences with your machine’s current state. The machine’s state won’t actually change, though, so don’t worry. Now that the prep stuff is out of the way, we can start the moving process.
Once that’s done, go to File > Virtual Media Manager. You’ll see a list of media that you’ve used or have attached to your machines.
Select which virtual machine you want to move, then click on the “Release” icon above. In my case, I’ll be moving W7.vdi from my home directory to another hard drive.
Once you have it released, close VirtualBox go to its default settings directory, /home/user/.VirtualBox/
You can copy your .vdi file from inside the HardDisks directory if you want to just back it up, or you can move it. Be patient, as this can take a while depending on your configuration.
Meanwhile, let’s edit the VirtualBox.xml file to our liking. This is the step most people don’t really know much about, but it’s pretty vital in making sure things work smoothly. Open it up in gedit.
Scroll down a bit and you’ll get to the parts we need to edit.
If you’re changing the location of your virtual machines, find the xml tags for “MachineEntry” and change the source path. If you’re changing the location of your virtual disk images, find the xml tags for “HardDisk” and change the location there. As you can see, each machine is tied to a disk image by its UUID, which should not be changed. If you’re moving virtual machines to a new computer, be sure to copy these this file over and replace the previous configuration file.
In my particular case, I just wanted to move the disk image to a more spacious drive, so I left the other things intact.
If you’re changing hosts between Windows and Linux, be sure to change the version declaration at the top of the file to say “windows” instead of “linux” as well.
Once you’ve moved the .vdi file, fire up VirtualBox and go to File > Virtual Media Manager.
Click on the old .vdi file and click remove. Now, click “Add,” navigate to its new location, and click “Open.” Click “OK.”
Now that the new .vdi is added to VirtualBox’s list, we have to attach it to your virtual machine. At the main screen select it, go to “Settings,” and click on the “Storage” panel.
Under the appropriate IDE controller, click the “Add Attachment” button. You’ll see a hard disk get added automatically, but it probably won’t be the correct one.
Click it and on right side, under “Hard Disk,” choose the correct .vdi file. Click “OK.”
If you followed all the steps and you edited the VirtualBox.xml correctly you should be able to start up the machine without any problems! There are a few hairy areas, so if things aren’t working, be sure you’re using the correct paths and you’ve edited only the relevant areas of VirtualBox.xml.
The overall process is a bit more intricate than just copying and pasting, but it’s still relatively quick and painless. Share your backup stories about VirtualBox in the comments!
Yatri Trivedi is a monk-like geek. When he's not overdosing on meditation and geek news of all kinds, he's hacking and tweaking something, often while mumbling in 4 or 5 other languages.
- Published 12/1/10