Page 1 of 1

How to Move a Directory of VB Virtual Machines (Ubuntu Host)

Posted: 12. Nov 2008, 04:06
by LarryJ
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

Code: Select all

VBoxManager --moveDir   dirOld    dirNew.
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

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
Remember you can determine the UUID of your partition by entering (in a terminal)

Code: Select all

ls -al  /dev/disk/by-uuid
which for my host prints shows this for /dev/sda6. (Partition 6 which was a logical partition created in the extended partition /dev/sda4)
lrwxrwxrwx 1 root root 10 2008-11-11 14:12 f597569c-cc5b-4738-86b7-3c1a6fa7e969 -> ../../sda6
Now reboot and verify that you have an empty /vm directory. Check it's size. Should be MANY gigabytes. Mine was 18 GB.

4. Create the destination directory in your new /vm directory

Code: Select all

mkdir /vm/.VirtualBox
5. Next completely copy your old .VirtualBox directory to the new location. I used Grsync but copy should work also. Something similar to

Code: Select all

cp -r  /home/lj/.VirtualBox/*  /vm/.VirtualBox


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.

Code: Select all

mv /home/lj/.VirtualBox/VirtualBox.xml  /home/lj/.VirtualBox/VirtualBox.xml.original
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

Code: Select all

mv /vm/.VirtualBox/Machines/Kubuntu_8.04/Kubuntu_8.04.xml /vm/.VirtualBox/Machines/Kubuntu_8.04/Kubuntu_8.04.xml.original
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!!).

Copying Machines

Posted: 15. Nov 2008, 11:37
by RGummi
An easier way is to copy the Machines and VDI folder and than edit with an texteditor the ~/.VirtualBox/VirtualBox.xml file. Search for filepath= and adjust the entries.

R

Re: How to Move a Directory of VB Virtual Machines (Ubuntu H

Posted: 17. Sep 2013, 16:19
by JeremyZ
How did you rename the directory? I am trying to rename the directory and I keep getting the error: "mv: cannot stat ‘/home/jeremy/.VirtualBox’: No such file or directory".

I know the directory is there:
root@Ubuntu:~# locate /.VirtualBox
/home/jeremy/.VirtualBox
/root/.VirtualBox
/root/.VirtualBox/VBoxGuestAdditions_4.2.10.iso
/root/.VirtualBox/VBoxSVC.log
/root/.VirtualBox/VBoxSVC.log.1
/root/.VirtualBox/VBoxSVC.log.10
/root/.VirtualBox/VBoxSVC.log.2
/root/.VirtualBox/VBoxSVC.log.3
/root/.VirtualBox/VBoxSVC.log.4
/root/.VirtualBox/VBoxSVC.log.5
/root/.VirtualBox/VBoxSVC.log.6
/root/.VirtualBox/VBoxSVC.log.7
/root/.VirtualBox/VBoxSVC.log.8
/root/.VirtualBox/VBoxSVC.log.9
/root/.VirtualBox/VirtualBox.xml
/root/.VirtualBox/VirtualBox.xml-prev
/root/.VirtualBox/compreg.dat
/root/.VirtualBox/selectorwindow.log
/root/.VirtualBox/selectorwindow.log.1
/root/.VirtualBox/xpti.dat

Also when I "ls -lh .* I get:
.VirtualBox:
total 36K
-rw------- 1 root root 1.2K Sep 17 09:10 compreg.dat
-rw------- 1 root root 3.5K Sep 17 09:39 VirtualBox.xml
-rw------- 1 root root 3.3K Sep 17 09:39 VirtualBox.xml-prev
-rw------- 1 root root 21K Sep 17 09:10 xpti.dat

However it does not list the .log's, why?

Jeremy

Re: How to Move a Directory of VB Virtual Machines (Ubuntu H

Posted: 17. Sep 2013, 17:10
by mpack
You are commenting on a 5 year old thread, and furthermore the discussion above is obsolete: the VirtualBox folder structure changed significantly in v4.0, and the best method of moving VMs changed as well.

Also, you should be very wary of renaming or moving files or folders used by VirtualBox.

Locking this obsolete discussion. See the HOWTO area for how to move VMs in VirtualBox v4.x and later.