The Tallest Dwarf

RSSEmailTwitterGitHubDribbbleLinkedInFacebookInstagramYouTubePinterestReddit icon

Auto suspend and resume KVM Virtual Machine with the host

Posted at — Aug 21, 2021 by Abishek Muthian

When the host machine is suspended while the KVM through QEMU is running lead to issues like display unable to wake up when resuming suspend.

Suspending and resuming the Virtual Machine when the host machine is suspended using hooks in systemd and resumed fixes this issue.

/etc/systemd/system/root-suspend.service
[Unit]
Description=Local system suspend actions
Before=sleep.target

[Service]
Type=simple
ExecStart=-virsh suspend ubuntu20.04

[Install]
WantedBy=sleep.target
/etc/systemd/system/root-resume.service
[Unit]
Description=Local system resume actions
After=suspend.target

[Service]
Type=simple
ExecStart=-virsh resume ubuntu20.04

[Install]
WantedBy=suspend.target
sudo systemctl enable root-resume
sudo systemctl enable root-suspend

I also enabled,

ON_SHUTDOWN=suspend

in

/etc/conf.d/libvirt-guests

to shutdown the VM along with the host.

Need help? Give help

Out of respect for your attention and concern for your privacy I don't have advertisements.

Let's have an obligation free discussion on this content or other common interests over email while supporting The Tallest Dwarf to continue writing.