Vagrant - 为 VirtualBox 设置虚拟硬盘的位置
Vagrant - set the location of the virtual hard drive for VirtualBox
我在目录 D:\vagrant\precise32-lamp\
中执行了以下命令(在 Windows,使用 Git Bash)
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
$ vagrant init precise32
$ vagrant up
注意。我没有更改原始 Vagrantfile。
我认为目录 D:\vagrant\precise32-lamp\
是 VDI 类文件的位置,但事实并非如此。工作目录用作共享文件夹。
我找到了 Vagrant 盒子的位置
C:\Users\USER\.vagrant.d\boxes\precise32[=13=]\virtualbox
根据 Where is Vagrant saving changes to the VM 我在 VirtualBox GUI 中找到了虚拟硬盘驱动器文件的位置。这是
C:\Users\USER\VirtualBox VMs-lamp_default_1458429875795_57100\
我不想将此文件放在系统驱动器 C:\
中,而是放在数据驱动器 D:\
中。
怎么设置这样的vagrant配置?
对于 VirtualBox,您可以通过 GUI 的首选项对话框更改所谓的默认计算机文件夹的位置。
This guide,虽然已经使用了几年,但工作正常,我上周关注了如何将现有的 vagrant/VirtualBox 驱动器移动到新位置。
编辑
我引用了上面的步骤link/guide,为了后人:
Move ~/.vagrant.d
to the external drive. I renamed it vagrant_home
so
I'd be able to see it without ls -a.
Set VAGRANT_HOME
to
/path/to/drive/vagrant_home
in ~/.bash_profile
.
Open the VirtualBox
app, open Preferences, and set its Default Machine Folder to
/path/to/drive/VirtualBox VMs
.
Close VirtualBox.
Move your
VirtualBox VMs
folder to the drive. Reopen VirtualBox. You'll see
your VMs are listed as "inaccessible". Remove them from the list.
For
each VM in your VirtualBox VMs
folder on the external drive, browse
to its folder in Finder and double-click the .vbox
file to restore it
to the VirtualBox Manager. (Is there an easier method than this?)
Finally, move any existing Vagrant directories you've made with
vagrant init
(these are the directories with a Vagrantfile
in each) to
the external drive. Since these directories only store metadata you
could leave them on your main drive, but it's nice to keep everything
together so you could fairly easily plug the whole drive into another
machine and start your VMs from there.
For each VM in your VirtualBox VMs folder on the external drive, browse to its folder in Finder and double-click the .vbox file to restore it to the VirtualBox Manager. (Is there an easier method than this?)
有一个更简单的方法...
进入 VirtualBox Manager GUI 单击 Machine > Add 并找到您要添加回来的 .vbox。
当您总是想在导入过程中更改 Virtualbox 创建 VM 的位置时,也可以通过 CLI 执行此操作(因为 Virtualbox 通常希望将它们放在一个地方而不是跟踪它们在磁盘上的任何位置VMware 的方式)。
请注意,通过 GUI 或 CLI 更改此设置不会移动现有 VM,它只会设置一个新路径以供下一台计算机使用 imported/created。如果您有想要移动的现有机器,您可以关闭并关闭 Virtualbox 的所有实例,然后使用 cmd/shell window 中的 mv /old/path /new/path
或将文件夹剪切并粘贴到新的GUI 中的位置,然后将 machinefolder
更改为该路径并打开 Virtualbox,它应该会检测到所有现有的虚拟机。
如果您有大量用户需要将 VM 路径移出他们的主目录以避免自动备份大文件,则使用 CLI 可以更轻松地 script/automate。 VM 的 "best" 位置在一定程度上取决于您的系统,但 /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
如果您改变主意,可以轻松地将其设置回默认值,但您需要自己将 VM 重新移回。
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
我在目录 D:\vagrant\precise32-lamp\
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
$ vagrant init precise32
$ vagrant up
注意。我没有更改原始 Vagrantfile。
我认为目录 D:\vagrant\precise32-lamp\
是 VDI 类文件的位置,但事实并非如此。工作目录用作共享文件夹。
我找到了 Vagrant 盒子的位置
C:\Users\USER\.vagrant.d\boxes\precise32[=13=]\virtualbox
根据 Where is Vagrant saving changes to the VM 我在 VirtualBox GUI 中找到了虚拟硬盘驱动器文件的位置。这是
C:\Users\USER\VirtualBox VMs-lamp_default_1458429875795_57100\
我不想将此文件放在系统驱动器 C:\
中,而是放在数据驱动器 D:\
中。
怎么设置这样的vagrant配置?
对于 VirtualBox,您可以通过 GUI 的首选项对话框更改所谓的默认计算机文件夹的位置。
This guide,虽然已经使用了几年,但工作正常,我上周关注了如何将现有的 vagrant/VirtualBox 驱动器移动到新位置。
编辑
我引用了上面的步骤link/guide,为了后人:
Move
~/.vagrant.d
to the external drive. I renamed itvagrant_home
so I'd be able to see it without ls -a.Set
VAGRANT_HOME
to/path/to/drive/vagrant_home
in~/.bash_profile
.Open the VirtualBox app, open Preferences, and set its Default Machine Folder to
/path/to/drive/VirtualBox VMs
.Close VirtualBox.
Move your
VirtualBox VMs
folder to the drive. Reopen VirtualBox. You'll see your VMs are listed as "inaccessible". Remove them from the list.For each VM in your
VirtualBox VMs
folder on the external drive, browse to its folder in Finder and double-click the.vbox
file to restore it to the VirtualBox Manager. (Is there an easier method than this?)Finally, move any existing Vagrant directories you've made with
vagrant init
(these are the directories with aVagrantfile
in each) to the external drive. Since these directories only store metadata you could leave them on your main drive, but it's nice to keep everything together so you could fairly easily plug the whole drive into another machine and start your VMs from there.
For each VM in your VirtualBox VMs folder on the external drive, browse to its folder in Finder and double-click the .vbox file to restore it to the VirtualBox Manager. (Is there an easier method than this?)
有一个更简单的方法... 进入 VirtualBox Manager GUI 单击 Machine > Add 并找到您要添加回来的 .vbox。
当您总是想在导入过程中更改 Virtualbox 创建 VM 的位置时,也可以通过 CLI 执行此操作(因为 Virtualbox 通常希望将它们放在一个地方而不是跟踪它们在磁盘上的任何位置VMware 的方式)。
请注意,通过 GUI 或 CLI 更改此设置不会移动现有 VM,它只会设置一个新路径以供下一台计算机使用 imported/created。如果您有想要移动的现有机器,您可以关闭并关闭 Virtualbox 的所有实例,然后使用 cmd/shell window 中的 mv /old/path /new/path
或将文件夹剪切并粘贴到新的GUI 中的位置,然后将 machinefolder
更改为该路径并打开 Virtualbox,它应该会检测到所有现有的虚拟机。
如果您有大量用户需要将 VM 路径移出他们的主目录以避免自动备份大文件,则使用 CLI 可以更轻松地 script/automate。 VM 的 "best" 位置在一定程度上取决于您的系统,但 /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
如果您改变主意,可以轻松地将其设置回默认值,但您需要自己将 VM 重新移回。
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