我刚接触 Vagrant,正在尝试为我创建的虚拟机添加第二个磁盘。我已经学会了在首次启动虚拟机时附加磁盘,但是当我关闭虚拟机并再次启动(使用“vagrant up --provision”确保提供者运行)时,对磁盘所做的更改都会丢失。
我两次都运行了日志记录,并且第二次运行(在机器最初配置后重新启动)的日志输出显示正在执行 storageattach 命令,但我在 "/dev/shm" 下创建的每个文件(这似乎是第二个磁盘的挂载点)都消失了。
失败模式是:
vagrant up ...
任何建议都将不胜感激。
我的Vagrantfile如下:
...
我两次都运行了日志记录,并且第二次运行(在机器最初配置后重新启动)的日志输出显示正在执行 storageattach 命令,但我在 "/dev/shm" 下创建的每个文件(这似乎是第二个磁盘的挂载点)都消失了。
失败模式是:
vagrant up ...
touch /dev/shm/some.file
ls /dev/shm/some.file # see output here...
停止vagrant虚拟机:
运行vagrant虚拟机并重新进行配置:
ls /dev/shm/some.file # no such file or directory.. where did it go ?
任何建议都将不胜感激。
我的Vagrantfile如下:
...
Vagrant.require_version ">= 1.4.3"
VAGRANTFILE_API_VERSION = "2"
disk = './secondDisk.vdi'
BOX_NAME="test"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master do |master|
master.vm.box = "centos65"
master.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
master.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "4196"]
v.name = BOX_NAME
end
master.vm.network :private_network, ip: "192.168.33.10"
master.vm.hostname = BOX_NAME
end
config.vm.synced_folder(".", "/vagrant",
:owner => "vagrant",
:group => "vagrant",
:mount_options => ['dmode=777','fmode=777']
)
config.vm.provider "virtualbox" do |vb|
unless File.exist?(disk)
vb.customize ['createhd', '--filename', disk, '--variant', 'Fixed', '--size', 1 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
end
end
以下是第二次执行 'vagrant up --provision' 的日志输出结果。[ 我使用 --provision 来确保每次 vagrant up 都完成所有配置步骤 ]:
INFO sanedefaults: Automatically figuring out whether to enable/disable NAT DNS proxy...
INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "modifyvm", "ea5c09 e7-11e7-4630-a7ca-ec66461b9eb6", "--natdnsproxy1", "on"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
INFO warden: Calling IN action: #<VagrantPlugins::ProviderVirtualBox::Action::Customize:0x3dc9818>
INFO interface: info: Running 'pre-boot' VM customizations...
INFO interface: info: ==> master: Running 'pre-boot' VM customizations...
==> master: Running 'pre-boot' VM customizations...
INFO subprocess: Starting process: ["C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe", "storageattach", "e a5c09e7-11e7-4630-a7ca-ec66461b9eb6", "--storagectl", "SATA", "--port", "1", "--device", "0", "--type", "hdd", "- -medium", "./secondDisk.vdi"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0