I created a script to save the state of my open VMs and allow me to shut down or reboot my machine nicely. As the state was saved, it then automatically opened quickly where I left off upon re starting the machine via another script.
I recently had a problem with an upgrade from 14:10 to 15:04 which has resulted in an almost complete rebuild, though nothing should have changed for the scripts as they are saved on a separate Home directory. However, I was testing the VM as I noticed it was not working, by using the basic test commands.
to show me running VMs, just to check the name.
To test to saved state
To restore from saved state.
Note the VM is "3cxServer"
It seems to save the state, but when it restores it fails to open the saved machine properly. It says "Aborted". I have to open via the VirtualBox app and then it starts in the Windows "machine didn't shut down properly..." screen.
My shutdown script which is adapted from others, is below, though not ready to use it due to the above errors:
I recently had a problem with an upgrade from 14:10 to 15:04 which has resulted in an almost complete rebuild, though nothing should have changed for the scripts as they are saved on a separate Home directory. However, I was testing the VM as I noticed it was not working, by using the basic test commands.
Code:
VBoxManage -nologo list runningvms
Code:
VBoxManage -nologo controlvm 3cxServer savestate
Code:
VirtualBox --startvm 3cxServer &
Note the VM is "3cxServer"
It seems to save the state, but when it restores it fails to open the saved machine properly. It says "Aborted". I have to open via the VirtualBox app and then it starts in the Windows "machine didn't shut down properly..." screen.
My shutdown script which is adapted from others, is below, though not ready to use it due to the above errors:
HTML Code:
#!/bin/bash
# /shut.vm
################################################## ######################
VBoxManage -nologo controlvm 3cxServer savestate
################################################## ######################
zenity --text="Click YES if you want to Shutdown or Reboot. Click No to resume." --title="Shutdown or Reboot?" --width="320" --height="150" --question
closeorcancel=$?
if [ "${closeorcancel}" == "0" ]
then
echo "You chose to Shutdown or Reboot"
else
echo "You chose No to resume your work"
exit
fi
zenity --text="Click YES if you want to Reboot. Click No to Shutdown." --title="Shutdown or Reboot?" --width="320" --height="150" --question
shutorboot=$?
if [ "${shutorboot}" == "0" ]
then
echo "You chose to Reboot"
if [ ! ${RUNVMLIST[*]}]
then
echo "No VMs open, straight to reboot"
sudo -H -u server /etc/init.d/vboxdrv stop
sudo /etc/init.d/preload stop
sudo /sbin/shutdown -r now
else
echo "All open VMs will be closed to a saved state"
for vm in ${RUNVMLIST[*]}
do
(VBoxManage controlvm $vm savestate) | zenity --progress --pulsate --width="320" --height="150" --title="Please Wait while VMs are Saved" --auto-close
echo "$vm was closed to a saved state"
done
echo "Rebooting now"
sudo -H -u server /etc/init.d/vboxdrv stop
sudo /etc/init.d/preload stop
sudo /sbin/shutdown -r now
fi
else
echo "You chose to Shutdown"
if [ ! ${RUNVMLIST[*]}]
then
echo "No VMs open, straight to shutdown"
sudo -H -u server /etc/init.d/vboxdrv stop
sudo /etc/init.d/preload stop
sudo /sbin/shutdown -r now
else
echo "All open VMs will be closed to a saved state"
for vm in ${RUNVMLIST[*]}
do
(VBoxManage controlvm $vm savestate) | zenity --progress --pulsate --width="320" --height="150" --title="Please Wait while VMs are Saved" --auto-close
echo "$vm was closed to a saved state"
done
echo "Shutting down Now"
sudo -H -u server /etc/init.d/vboxdrv stop
sudo /etc/init.d/preload stop
sudo /sbin/shutdown -h now
fi
fi
exit