当您总是想在导入期间更改 Virtualbox 创建 VM 的位置时,也可以通过 CLI 执行此操作(因为 Virtualbox 通常希望将它们放在一个位置,而不是像 VMware 那样跟踪它们在磁盘上的任何位置这样做)。
请注意,通过 GUI 或 CLI 更改此设置不会移动现有虚拟机,它只会设置一个新路径以供下一台导入/创建的机器使用。如果您有想要移动的现有机器,您可以关闭并关闭 Virtualbox 的所有实例,然后从 cmd/shell 窗口使用mv /old/path /new/path 或将文件夹剪切并粘贴到 GUI 中的新位置,然后更改machinefolder 到该路径并打开 Virtualbox,它应该会检测到所有现有的虚拟机。
如果您有大量用户需要将虚拟机路径移出其主目录以避免自动备份大型文件,则使用 CLI 可以更轻松地编写脚本/自动化。虚拟机的“最佳”位置在一定程度上取决于您的系统,但/usr/local/ 可能是在 macOS 或 Linux 上创建新文件夹的好位置。
# Look at the current path
vboxmanage list systemproperties | grep machine
# Output (commented for easier copying and pasting of commands)
# Default machine folder: /Users/<YourUser>/VirtualBox VMs
# Set it to a different folder in your home aka ~
# If you user has access to the path and can create files/folders, then
# the folder doesn't need to exist beforehand, Virtualbox will create it
vboxmanage setproperty machinefolder ~/VirtualMachines
# No output produced
vboxmanage list systemproperties | grep machine
# Output (commented for easier copying and pasting of commands)
# Default machine folder: /Users/<YourUser>/VirtualMachines
您也可以将其设置为家庭以外的文件夹,但这通常需要创建文件夹并在 Virtualbox 可以使用之前修复权限。
# [Optional] Only needed if moving out of the home directory to
# a place the user doesn't have permission to access by default
sudo mkdir -p /usr/local/VirtualMachines && \
sudo chown -R ${USER} /usr/local/VirtualMachines
# If you add : like this `${USER}:` to the above, instead of
# setting the group to admin or wheel it will use the user's default group
# which can be seen by running `id -g`
vboxmanage setproperty machinefolder /usr/local/VirtualMachines
# No output produced
vboxmanage list systemproperties | grep machine
# Output (commented for easier copying and pasting of commands)
# Default machine folder: /usr/local/VirtualMachines
如果您改变主意,可以轻松将其设置回默认值,但您需要自己将虚拟机重新移回。
vboxmanage setproperty machinefolder default
vboxmanage list systemproperties | grep machine
# Output (commented for easier copying and pasting of commands)
# Default machine folder: /Users/<YourUser>/VirtualBox VMs