Feature request: Hibernate VMs on PVE host reboot

@Radek Kantor or anyone else it could help, I'm using the following script to automate the process:

Code:
# suspend_and_shutdown.sh
qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done; shutdown -h now

# suspend_and_reboot.sh
qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done; reboot

I'm quite happy with my scripts, although I would still appreciate this being built in.
 
Hi,

Here is my solution to hibernate all VMs at reboot or shutdown !
It works for me. Thanks to @davidand for his script example :)

Go in proxmox shell, you need to be root !

vi /etc/init.d/proxmox

Add this :

Bash:
#!/bin/sh
case "$1" in
start)
   qm list | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm unlock $vm_id; done;
;;
stop)
   qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done;
   sleep 10
;;
esac
exit 0

chmod 755 /etc/init.d/proxmox

ln -s /etc/init.d/proxmox /etc/rc3.d/S99proxmox
ln -s /etc/init.d/proxmox /etc/rc0.d/K99proxmox
ln -s /etc/init.d/proxmox /etc/rc6.d/K99proxmox

systemctl daemon-reload
systemctl start proxmox

Don't forget to add autostart option in proxmox to the VMs that have to boot on start.

Enjoy ! :)

You can reboot or shutown your server from :
- Physical buttons
- Proxmox Gui buttons
- in shell : restart now / shutdow now
 
Hi,

Here is my solution to hibernate all VMs at reboot or shutdown !
It works for me. Thanks to @davidand for his script example :)

Go in proxmox shell, you need to be root !

vi /etc/init.d/proxmox

Add this :

Bash:
#!/bin/sh
case "$1" in
start)
   qm list | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm unlock $vm_id; done;
;;
stop)
   qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done;
   sleep 10
;;
esac
exit 0

chmod 755 /etc/init.d/proxmox

ln -s /etc/init.d/proxmox /etc/rc3.d/S99proxmox
ln -s /etc/init.d/proxmox /etc/rc0.d/K99proxmox
ln -s /etc/init.d/proxmox /etc/rc6.d/K99proxmox

systemctl daemon-reload
systemctl start proxmox

Don't forget to add autostart option in proxmox to the VMs that have to boot on start.

Enjoy ! :)

You can reboot or shutown your server from :
- Physical buttons
- Proxmox Gui buttons
- in shell : restart now / shutdow now
Will this replace the current/standard Proxmox behavior of shutting down the VMs when doing a reboot? Thank you!
 
Hi,

Here is my solution to hibernate all VMs at reboot or shutdown !
It works for me. Thanks to @davidand for his script example :)

Go in proxmox shell, you need to be root !

vi /etc/init.d/proxmox

Add this :

Bash:
#!/bin/sh
case "$1" in
start)
   qm list | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm unlock $vm_id; done;
;;
stop)
   qm list | grep running | awk -F'[^0-9]*' '$0=$2' | while read -r vm_id; do qm suspend $vm_id --todisk 1; done;
   sleep 10
;;
esac
exit 0

chmod 755 /etc/init.d/proxmox

ln -s /etc/init.d/proxmox /etc/rc3.d/S99proxmox
ln -s /etc/init.d/proxmox /etc/rc0.d/K99proxmox
ln -s /etc/init.d/proxmox /etc/rc6.d/K99proxmox

systemctl daemon-reload
systemctl start proxmox

Don't forget to add autostart option in proxmox to the VMs that have to boot on start.

Enjoy ! :)

You can reboot or shutown your server from :
- Physical buttons
- Proxmox Gui buttons
- in shell : restart now / shutdow now
Hi Lion,
i just tried the script of @davidand , and i think in principle it is working - but I have one problem.
The shutdown of the host process still commands the VMs to shut down in parallel to the hibernate command of the script.
So only the first of my 5 VMs actually will hibernate (the shutdown command for this VM is still issued, but comes to late)
while the other 4 VMs begin their shutdown process before their hibernate commands are issued.
Is there a way to prevent the shutdown commands for the VMs when the host shutdown command is issued ??
If so I couldn't find that.
thx for help.