virtualbox - 如何使用 VirtualBox CLI 重新启动 VM 并等待它再次完全启动?
问题描述
我正在使用VBoxManage unattended install
并希望在安装后运行脚本来自动创建 VM,这让我--post-install-command
选择了。这里的问题是:我的脚本中的下一步需要Guest Additions,所以我--install-additions
在安装中使用了选项。不幸的是,这个选项在安装 Guest Additions 后不会重新启动机器,所以我正在寻找一种解决方法,所以我重新启动 VM(从主机或来宾),然后继续我的主脚本。
解决方案
不幸的是,我没有发现 VBox 在 VM 启动时触发的任何事件,所以我不得不等待它完全启动。
完全启动平均需要 2-3 分钟,所以我使用了 3 分钟的计时器。
$postInstallCommands = 'VBoxControl guestproperty set installation_finished y && (shutdown /s || shutdown -P now)'
########## Initiate unattended installation
VBoxManage unattended install "$vmName" `
--iso="$isoFile" `
--user="$userName" `
--password="$password" `
--full-user-name="$userName" `
--install-additions `
--locale=en_US `
--country=US `
--time-zone=EST `
--image-index=1 `
--post-install-command="$postInstallCommands" *> $null
########## Start VM and wait to finish install
VBoxManage startvm "$vmName" --type headless
Write-Host "Waiting for VM to finish OS installation..."
VBoxManage guestproperty wait "$vmName" installation_finished *> $null
Start-Sleep -s 180
推荐阅读
- java - Java servlet 跟踪 API 命中率
- php - 如何在 Laravel 中将 user_id 添加到登录参数?
- java - 从集合中检索项目
- javascript - 将数组绑定到 Knockout 样式绑定
- javascript - js/ts中模块动态导入的静态代码分析
- oracle - 执行具有来自 BODS 的授权语句的过程
- java - 使用switch case制作计算器
- python - 已有背景图像时如何获取前景蒙版
- powershell - 如何从 powershell 创建 IIS 网站以托管 .net core 2.0 应用程序,错误 0x8007000d
- java - 如何在 Jpa 实体中使用 Java 继承