Add autostart vm after reboot virtual box
Ticket 40684 22 September 2021 08:22 AM
Please add autostart for VMs after reboot.
in phpvirtualbox:
Code: Select all
/* Enable startup / shutdown configuration.
* This only works in linux and you must add the vboxinit file to
* your startup scripts list.
*/
var $startStopConfig = true;
But add proper vboxinit file to startup scripts.
/volume1/Web/virtualbox/vboxinit - example for init file.
in /usr/local/AppCentral/virtualbox/CONTROL/start-stop.sh
add this:
start()
{
# Get all autostart machines
MACHINES=$($su_command "VBoxManage list vms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
for UUID in $MACHINES; do
STARTUP=$($su_command "VBoxManage getextradata $UUID 'pvbx/startupMode'" | awk '{ print $NF }')
if [ "${STARTUP}" == "auto" ]; then
VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
echo "$0: starting machine ${VMNAME} ..."
$su_command "VBoxManage startvm $UUID --type headless" >>/var/log/vb.log
fi
done
}
stop()
{
# vms are saved, instead of stopped.
MACHINES=$($su_command "VBoxManage list runningvms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
for UUID in $MACHINES; do
VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
echo "$0: saving machine ${VMNAME} state ..."
$su_command "VBoxManage controlvm $UUID savestate" >>/var/log/vb.log
done
}