openmediavault-virtualbox: graceful (ACPI) shutdown or suspend virtual machines on reboot or shutdown OpenMediaVault

    • OMV 1.0
    • Virtualbox's init script saves the state of each vm on shutdown. I suppose you could change this to acpi shutdown.


      Source Code

      1. stop()
      2. {
      3. # vms are saved, instead of stopped.
      4. MACHINES=$($su_command "VBoxManage list runningvms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
      5. for UUID in $MACHINES; do
      6. VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
      7. echo "$0: saving machine ${VMNAME} state ..."
      8. $su_command "VBoxManage controlvm $UUID savestate" >>/var/log/vb.log
      9. done
      10. }
      omv 5.0.10 usul | 64 bit | 5.0 proxmox kernel | omvextrasorg 5.1.1 plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • Hello,

      I also want shut down my VM when the server shuts down. Unfortunately there's no vboxinit under /etc/init.d
      There's a script called "virtualbox".
      How can I shut down of my VM before the server shuts down (via script)?
      Unfortunately under root there is no VM visually. You have to change to user "vbox". See here
      OMV-Server-HW: MoBo Fujitsu D3417-B2 (Intel-LAN), Intel Xeon E3-1245 v6 Kaby Lake (4x3.70GHz), 16GB-Ram ECC UDIMM, 1x512GB SSD Samsung 850 Pro (sda2 - 30GB system, 4GB swap, sda5/rest - for work), 1x 10TB WD Red Pro, 1x 3TB WD Red (both basic setup) - Digibit R1 Sat-IP-Server with SatIP-Axe-Firmware

      OMV-Server-SW: Debian Stretch with backports-Kernel (always up-to-date), OMV v4 (always latest), omv-extras-plugin (always latests), AutoShutdown-Plugin, Virtualbox (with DSM 6.2.x), Docker with PlexMediaServer, TVHeadendServer (unstable release)

      BackupServer: Synology DS1010+ with 4GB Ram, 9TB@SHR (different hdd's), DSM 5.2-5967-2
    • For version OMV 2.1/2.2.14:
      check file /etc/defaults/virtualbox :
      -----text in file: -----------------------------
      # Defaults for VirtualBox.
      # Sourced by vboxweb-service on startup
      in file etc/init.d/vboxinit check 2 fragments,
      edit (# Required-Stop: $all)
      ,all system services will continue work some time after shutdown/reboot, until vboxinit script run)
      add delay 60 seconds ($su_command "sleep 60s")
      and change command from savestate to acpipowerbutton in script,

      --fragment1: -----------------------------------
      # Provides: vboxinit
      # Required-Start: vboxdrv $local_fs
      # Required-Stop: $all
      # Default-Start: 2 3 4 5
      # Default-Stop: 0 1 6
      # Description: Controls VirtualBox sessions
      ### END INIT INFO
      # 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: stopping machine ${VMNAME} ..."
      $su_command "VBoxManage controlvm $UUID acpipowerbutton" >>/var/log/vb.log
      $su_command "sleep 60s"


      check "run premission" for etc/init.d/vboxinit
      run command from shell:
      sudo update-rc.d vboxinit defaults

      5) reboot system , start VM , check host reboot\shutdown,
      shutdown test for Windows Guest VM:
      put test.cmd in "computer" shutdown scenaries in gpedit.msc:
      ping -n 10
      ping -n 3 > c:\log.txt
      (for result need minimum 13 seconds)

      check c:\log.txt file and creation data of file.

      check "windows Reliability Monitor" 10-15 min after host reboot , non graceful windows shutdown-s show warnings in "Reliability Monitor graph".

      for version OMV-4 no solution
      (in default settings "savestate" mode, work only for quick and small VM-s, delay in scripts not work)

      The post was edited 3 times, last by onega120 ().