- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Vagrantfile 中,我附加手动创建的 db.vdi
磁盘:
vb.customize [
'storageattach', :id,
'--storagectl', 'SATA Controller',
'--port', 1, '--device', 0,
'--type', 'hdd',
'--medium', 'db.vdi'
]
它工作得很好,但是当我销毁 vagrant box 时,这个文件被删除了。我试图修复 Vagrant 触发器。 before :destroy
before :halt
不起作用,我收到驱动器不可热插拔的错误。 after :halt
根本不起作用:
config.trigger.after :halt do
run "VBoxManage storageattach '#{@machine.id}'" +
" --storagectl 'SATA Controller' --port 1 --device 0 --type hdd --medium none"
end
我想做的是,当我运行vagrant destroy
时,我想优雅地停止机器,取消附加vdi文件,这样vagrant就不会删除它,销毁其他所有内容。
可能吗?
编辑:
看起来可以使用插件钩子(Hook) https://github.com/kusnier/vagrant-persistent-storage/blob/master/lib/vagrant-persistent-storage/plugin.rb 来做到这一点- 请参阅对 Action.detach_storage
的引用,但我不知道如何在 Vagrantfile 中使用它
参见@FrédéricHenri - 分离触发得太快:
==> default: Running triggers before destroy...
==> default: dettach drive
==> !!! TOO SOON !!!
==> default: Executing command "VBoxManage storageattach d0132b78-11ea-41cf-b003-dac15536520c --storagectl SATAController --port 1 --device 0 --type hdd --medium none"...
==> default: Command execution finished.
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> !!! THIS IS WHERE I SHOULD DETACH THE DRIVE !!!
==> default: Destroying VM and associated drives...
最佳答案
我认为您是正确的,就像您查看示例插件一样,它们确实在暂停命令之后和销毁之前进行 Hook 。
问题在于您运行命令 run "VBoxManage storageattach '#{@machine.id}'" ..
的方式将返回一个空 machine.id
; Vagrantfile 脚本中的 vagrant 不知道它正在构建的机器,因此您会收到错误消息,它无法找到具有空 ID/名称的引用虚拟机,并且该命令无法成功执行。
您需要获取 VirtualBox VM Id,以便将其传递给命令;此 ID 保存在文件 .vagrant/machines/<name>/<provider>/id
中,假设您没有为虚拟机设置特定名称,它将是:
config.trigger.before :destroy do
info "dettach drive"
machineId = File.read(".vagrant/machines/default/virtualbox/id")
run "VBoxManage storageattach '#{machineId}'" +
" --storagectl 'SATA Controller' --port 1 --device 0 --type hdd --medium none"
end
对于热插拔模式,您需要确保文件在附加时确实是可热插拔的,以便可以在虚拟机仍在运行时(即销毁之前)将其拔出
您可以在连接硬盘时从 Vagrantfile 进行此配置
vb.customize [
'storageattach', :id,
'--storagectl', 'SATAController',
'--port', 1, '--device', 0,
'--type', 'hdd',
'--medium', 'db.vdi',
'--hotpluggable', 'on'
]
运行 destroy
时该虚拟机的命令,您将得到
fhenri:~/project/vagrant/drive$ vagrant destroy
==> default: Running triggers before destroy...
==> default: dettach drive
==> default: Executing command "VBoxManage storageattach d0132b78-11ea-41cf-b003-dac15536520c --storagectl SATAController --port 1 --device 0 --type hdd --medium none"...
==> default: Command execution finished.
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
这样你就可以清楚地看到命令正确执行并且驱动器已分离,我可以看到驱动器仍然在我的本地硬盘驱动器上,然后我可以回答"is"来销毁虚拟机文件
就我而言,它也可以与 afterhalt 触发钩子(Hook)一起使用:
来自 Vagrantfile
config.trigger.after :halt do
info "dettach drive"
machineId = File.read(".vagrant/machines/default/virtualbox/id")
run "VBoxManage storageattach '#{machineId}'" +
" --storagectl 'SATAController' --port 1 --device 0 --type hdd --medium none"
end
将运行
fhenri:~/project/vagrant/drive$ vagrant halt
==> default: Attempting graceful shutdown of VM...
==> default: Running triggers after halt...
==> default: dettach drive
==> default: Executing command "VBoxManage storageattach 74274ab6-173e-4934-9864-33e09be26214 --storagectl SATAController --port 1 --device 0 --type hdd --medium none"...
==> default: Command execution finished.
您剩下的问题是确保在这种情况下不要调用destroy,因为destroy不会停止虚拟机,它只是销毁它,这样它就不会调用halt命令并绕过halt触发器,您可以使用额外的销毁插件,但这意味着您不想要热插拔的东西
您可以通过检查vboxmanage showvminfo <uuid>
来检查设备上连接的驱动器数量并查找 storagecontrollerportcount0
您可以在销毁前触发器中翻译它
config.trigger.before :destroy do
vm_info = `vboxmanage showvminfo #{@machine.id} --machinereadable | grep storagecontrollerportcount0`
value = Integer(vm_info.split("=")[1].gsub('"','').chomp())
raise Vagrant::Errors::VagrantError.new, "drive attached - cannot be destroyed" if value > 1
end
如果您连接了超过 1 个驱动器,则会引发错误,并且不会继续执行 destroy 命令
关于Vagrant 在销毁之前分离 .vdi 文件或者只是不删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45038248/
我在我的 PC 上使用 VirtualBox( WIN 7 ) 我设法在我的 中查看了一些文件.VDI 文件.. 如何打开或查看我的 的内容.vdi 文件并从那里检索文件? 最佳答案 您可以使用 qe
在 Vagrantfile 中,我附加手动创建的 db.vdi 磁盘: vb.customize [ 'storageattach', :id, '--storagectl', 'SATA C
尝试将 .img 文件转换为 .vdi 文件时出现以下错误。 VBoxManage convertfromraw file.img file.vdi Converting from raw image
我在 D 驱动器中有一个名为“Ubuntu VM1.vhd”的 VHD 文件,我正在尝试将 if 转换为 vdi,我遇到了带有 --format vdi 参数的 clonehd 命令,我不明白为什么它
将本地现有的 VirtualBox .vdi 添加到 vagrant 的语法是什么? 文档中似乎没有替代 URI 方案的示例。 它还可以使用 ssh 和 httpauth 位置吗? 最佳答案 您不能直
如何检查 vdi 或 vmdk 的 uuid? VBoxManage 上应该有一些命令行来显示它。 我知道我在文档的某个地方读过它,但现在由于某种原因我找不到它...... 最佳答案 运行VBoxMa
我已经愉快地使用 Ubuntu 12.04 虚拟机作为网络服务器,并在 Windows 7 计算机上的 VirtualBox 上运行静态 IP 几个月了(从主机计算机、桥接网络连接、从主机通过 SSH
有什么方法可以创建一个 NTFS 格式的 Virtual Box 磁盘镜像 (.vdi) 并将一组文件复制到其中,然后再使用 VBoxManage 将其附加到已配置的实例作为第二个磁盘? 最佳答案 是
今天,我试图在我的 Kali Linux 虚拟机上对我拥有的 VPS 进行基本的漏洞检查。我将我的 Kali Linux 虚拟磁盘镜像 (VDI) 保存在 USB 外部驱动器上,因此我将其插入,启动了
大家好! 背景:我有旧版 ASP.NET MVC 本地应用程序在本地 Windows IIS 上运行。我正在研究将此应用程序与 Azure AD 身份验证集成的方法。据我所知( Windows IIS
我创建了一个具有固定磁盘大小的 .vdi,后来调整了磁盘大小并附加到我的 Linux VM。但我的虚拟机仍然没有使用调整后的磁盘进行更新 最初,我在调整大小期间遇到错误“尚未实现此格式的调整硬盘大小操
我正在使用此脚本的修改版本:https://softlayer.github.io/go/edit_virtual_guest.go/ 脚本是一样的,除了我的 objectTemplate 看起来像:
这是一个令人难以置信的远射,但这里是。我们正在使用 SQLVDI API(虚拟设备接口(interface))制作数据库备份实用程序。单一备份的实现没有问题。但是当我们开始实现 strip 备份(使用
大家好:我正在尝试在 Virtual box 中运行 Cloudera Hadoop VM。 首先,我注意到下载的是一个 .vmdk 文件。当然,这个后缀是针对 VMWare 的,所以有点奇怪。 幸运
我想在 Microsoft Azure VDI 中设置用于 iOS 开发的 Mac OS 环境。 任何人都可以分享步骤或分享有关可行性的详细信息吗? 最佳答案 我认为今天不可能。这是一个类似的问题,似
我想在 Microsoft Azure VDI 中设置用于 iOS 开发的 Mac OS 环境。 任何人都可以分享步骤或分享有关可行性的详细信息吗? 最佳答案 我认为今天不可能。这是一个类似的问题,似
我是一名优秀的程序员,十分优秀!