Sunday, August 28, 2022

Pausing VMs to reduce power consumption

My primary homelab server is the Dell Poweredge R720 rack server. On it, there are three VMs that I keep running all the time: a TrueNAS VM that managed my "cloud" storage, a media server VM running Jellyfin, and a Ubuntu server for services like PiHole and such. At the same time, I also run two other VMs on the R720: a Windows VM for work, and a Linux Mint VM for general purpose (web browsing, YouTube videos, and such).

When all 5 VMs are running, power consumption is about 240+W. When the Windows VM and Linux Mint VM are paused, though, power consumption drops to around 190+W. This saves about 50W of electricity.

So I came up with a set of simple scripts that I run from my HP T630 thin client to pause and resume the VMs before going to sleep and after waking up. Also, when the VMs are paused, I prefer the fans to run at a lower speed, so I disable third-party PCIe fan response, and turn it back on only when I resume the VMs. I use the racadm commands I wrote about here.

pausevm.sh
#!/bin/bash
echo "Pause VM 222"
ssh root@pve720.local "qm suspend 222"
sleep 3
echo "Pause VM 333"
ssh root@pve720.local "qm suspend 333"
sleep 3
ssh root@idrac720.local "racadm set system.thermalsettings.ThirdPartyPCIFanResponse 0"
echo "pausevm.sh complete"


resumevm.sh
#!/bin/bash
ssh root@idrac720.local "racadm set system.thermalsettings.ThirdPartyPCIFanResponse 1"
echo "Resume VM 222"
ssh root@pve720.local "qm resume 222"
sleep 3
echo "Resume VM 333"
ssh root@pve720.local "qm resume 333"
sleep 10
echo "Restarting NTP service on vm333.local"
ssh user@vm333.local "sudo service ntp restart"
echo "resumevm.sh complete"


After pausing the VMs, time "stops" for them, so it is necessary to resync the time. For the Linux Mint VM (VM 333), I can do this by restarting the NTP service. For the Windows VM (VM 222), I usually do it manually after using NoMachine to access the VM, although it sometimes sync by itself before that.
 
A bit about terminology. The webUI of Proxmox uses "Pause" and "Hibernate". "Pause" is to suspend to memory; "Hibernate" is to suspend to disk. It is faster to resume a VM when it has been suspended to memory, which is why that is what I prefer to do.

No comments: