2024-09-09 Moving Virtualbox machines to another directory

(Warning: rant-ish post incoming.)

A few days ago I had a slightly atypical need. For some reason, I needed to move a Virtualbox machine to another directory. (Note to younger readers: I am not, and will not, use the word “folder”. These are directories and I’m not going to use another word for it. Note 2: this is not me yelling at cloud, this post has nothing to do with other people’s computers;-).)

Anyway, the Vagrant documentation is comprehensive but not very easy to dig through. After a few failed attempts I found the correct command, which is VBoxManage movevm (by the way, who decided that using capital letters in a CLI tool’s name is a good idea?).

First we need to learn the name (alternatively, the uuid) of the machine we want to move. This is easy: VBoxManage list vms. Let’s assume that the name of our machine is handles. (Usually, these names are generated to be much longer.) This means that by default it’s located in ~/VirtualBox VMs/handles directory (yes, with a literal space, great idea, really…).

The first time I tried to move my machine I tried to do roughly this:

VBoxManage movevm handles --folder ~/directory

and it worked. Then, just to make sure that my success is repeatable, I issued the reverse command:

VBoxManage movevm handles --folder "~/VirtualBox VMs"

and was met with an unpleasant surprise:

VBoxManage: error: Unable to determine free space at move destination ('/home/mbork/~/VirtualBox VMs/'): VERR_FILE_NOT_FOUND
VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "MoveTo(Bstr(szTargetFolder).raw(), Bstr(pszType).raw(), progress.asOutParam())" at line 512 of file VBoxManageMisc.cpp

What happened here‽ Well, the first line contains a hint: Virtualbox tries to move the machine to /home/mbork/~/VirtualBox VMs/. It’s pretty easy to see what happened. I used quotes so that the space in the directory name would work (as I hinted above and always say, using spaces in directory names is asking for trouble…), but then Bash didn’t expand the tilde (~) into the name of my home directory, either, and VirtualBox isn’t smart enough to do it for itself.

This is (sadly) an excellent example of poor practices – first, using a space in a directory (or file) name, then, not expecting a very typical use case and not doing The Right Thing (or at least not providing an informative error message). (To be fair, it’s debatable if this is more Virtualbox’s fault or Bash’s fault, or, frankly, user error. But I’m pretty sure putting a space into a directory name is a very bad idea.)

So, what is the “correct” (well, at least working) way to move a Virtualbox VM back into its ~/VirtualBox VMs directory? You can either escape the space with a backslash:

VBoxManage movevm handles --folder ~/VirtualBox\ VMs

or put the tilde outside the quotation marks:

VBoxManage movevm handles --folder ~/"VirtualBox VMs"

That’s it for today. I hope I saved someone a headache and half an hour of searching through the internet…

CategoryEnglish, CategoryBlog