How to Move a Directory of VB Virtual Machines (Ubuntu Host)
Posted: 12. Nov 2008, 04:06
I'm certain there is a better way to do this. I just couldn't find it. Perhaps something to do with VBoxManager register? Life would be nice if there was a
My problem: I took the default configuration for VirtualBox V 2.0.4 so the default .VirtualBox directory for my LinuxUbuntu 8.04 host was/home/lj/.VirtualBox. I soon realized this was inconvenient. I should have set up a separate partition and stored my VM's in there. So how to move my collection of 11 virtual machines to a new separate partition mounted as /vm ?
This is the way I did it and probably was the hard way!
1. Create a separate partition on your hard drive. I used the LiveCD PartedMagic 3.1 I sized it generously. HD's are relatively cheap these days. You might need as much as 10 GB per VM (or more)
2. Add an entry to /etc/fstab so the new partition (/dev/sda6 in my case) is mounted as /vm. My entry looks like
Remember you can determine the UUID of your partition by entering (in a terminal)
which for my host prints shows this for /dev/sda6. (Partition 6 which was a logical partition created in the extended partition /dev/sda4)
4. Create the destination directory in your new /vm directory
5. Next completely copy your old .VirtualBox directory to the new location. I used Grsync but copy should work also. Something similar to
6. Change to the old .VirtualBox directory (in my case this is /home/lj/.VirtualBox)
In there, find the file VirtualBox.xml. Rename it VirtualBox.xml.original for safe keeping.
7. Change to the new .VirtualBox directory (in my case this is /vm/.VirtualBox)
In there find the Machines directory. In the Machines directory descent into one of your Virtual Machine directories. In it, find the file with the extension of .xml. Rename it *.xml.original. Something similar to
8. Start the VirtualBox Gui. In File->Preferences, Change the default Hard Disk Folder to /vm/.VirtualBox/VDI and the Default Machine Folder to /vm/.VirtualBox/Machines. Click OK
9. Click New -> Next in the Name textedit enter the directory where you virtual machine is stored. Here I entered "Kubuntu_8.04". I then selected Ubuntu as the OS Type. Click Next and Next again. Click Existing then the Add from the Virtual Disk Manager gui. Find the .vdi assoicated with this machine. Here I selected Kubuntu-8.04.vdi from the /vm/VirtualBox/VDI directory. Click Open. Kubuntu-8.04.vid should be highlighted. Click Select. Click Next. Click Finish.
Obviously, if your VM is XP, then the OS type will be XP, not Ubuntu.
10. With any luck, Kubuntu_8.04 should be appear in the VirtualBox gui list and run when you click Start.
11.To verify the move was successful, rename your /home/lj/.VirtualBox/VDI directory to /home/lj/.VirtualBox/VDI.old. If you can still run your VM's from the VirtualBox Gui, then you can safely think about deleting the Machines and VDI directorie located in your original .VirtualBox directory (not the new one in /vm!!).
Code: Select all
VBoxManager --moveDir dirOld dirNew.
This is the way I did it and probably was the hard way!
1. Create a separate partition on your hard drive. I used the LiveCD PartedMagic 3.1 I sized it generously. HD's are relatively cheap these days. You might need as much as 10 GB per VM (or more)
2. Add an entry to /etc/fstab so the new partition (/dev/sda6 in my case) is mounted as /vm. My entry looks like
Code: Select all
# Added by LJ to mount /dev/sda6 as /vm. Note all VMs for virtualbox reside in this partition.
# /dev/sda6
UUID=f597569c-cc5b-4738-86b7-3c1a6fa7e969 /vm ext3 relatime 0 2
Code: Select all
ls -al /dev/disk/by-uuidNow reboot and verify that you have an empty /vm directory. Check it's size. Should be MANY gigabytes. Mine was 18 GB.lrwxrwxrwx 1 root root 10 2008-11-11 14:12 f597569c-cc5b-4738-86b7-3c1a6fa7e969 -> ../../sda6
4. Create the destination directory in your new /vm directory
Code: Select all
mkdir /vm/.VirtualBoxCode: Select all
cp -r /home/lj/.VirtualBox/* /vm/.VirtualBox6. Change to the old .VirtualBox directory (in my case this is /home/lj/.VirtualBox)
In there, find the file VirtualBox.xml. Rename it VirtualBox.xml.original for safe keeping.
Code: Select all
mv /home/lj/.VirtualBox/VirtualBox.xml /home/lj/.VirtualBox/VirtualBox.xml.originalIn there find the Machines directory. In the Machines directory descent into one of your Virtual Machine directories. In it, find the file with the extension of .xml. Rename it *.xml.original. Something similar to
Code: Select all
mv /vm/.VirtualBox/Machines/Kubuntu_8.04/Kubuntu_8.04.xml /vm/.VirtualBox/Machines/Kubuntu_8.04/Kubuntu_8.04.xml.original9. Click New -> Next in the Name textedit enter the directory where you virtual machine is stored. Here I entered "Kubuntu_8.04". I then selected Ubuntu as the OS Type. Click Next and Next again. Click Existing then the Add from the Virtual Disk Manager gui. Find the .vdi assoicated with this machine. Here I selected Kubuntu-8.04.vdi from the /vm/VirtualBox/VDI directory. Click Open. Kubuntu-8.04.vid should be highlighted. Click Select. Click Next. Click Finish.
Obviously, if your VM is XP, then the OS type will be XP, not Ubuntu.
10. With any luck, Kubuntu_8.04 should be appear in the VirtualBox gui list and run when you click Start.
11.To verify the move was successful, rename your /home/lj/.VirtualBox/VDI directory to /home/lj/.VirtualBox/VDI.old. If you can still run your VM's from the VirtualBox Gui, then you can safely think about deleting the Machines and VDI directorie located in your original .VirtualBox directory (not the new one in /vm!!).