I'm automating VM creation using VBoxManage unattended install
and want to run script after installing which led me to --post-install-command
option.
The problem here is: the next steps in my script require Guest Additions, so I used --install-additions
option in installation. Unfortunately, this option doesn't restart the machine after installing the Guest Additions, So I'm looking for a workaround so I restart the VM(from host or guest) and then continue my main script.
Asked
Active
Viewed 948 times
2

Hassan Azzam
- 31
- 4
-
Did you ever figure out how to restart the VM? Or even get the `--post-install-command` to run, regardless of restart? – user453441 Mar 02 '21 at 07:07
-
Check this https://stackoverflow.com/a/66453139/9380811 – Hassan Azzam Mar 03 '21 at 08:21
1 Answers
1
Unfortunately, I didn't find any event triggered by VBox on VM boot up, so I had to wait for it to fully boot up.
It takes an average of 2-3 mins to fully boot up, so I used a timer of 3 mins.
$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

Hassan Azzam
- 31
- 4