排查 Linux VM 上的休眠问题

休眠虚拟机让你可将 VM 状态持久保存到 OS 磁盘。 本文介绍如何排查 Linux 上的休眠功能问题、创建已启用休眠的 Linux VM 的问题以及 Linux VM 休眠问题。

若要查看休眠的常规故障排除指南,请查看 Azure 中的休眠疑难解答

无法休眠 Linux 虚拟机

如果无法休眠 VM,请先 检查是否在 VM 上启用休眠

如果在 VM 上启用了休眠,请检查是否在来宾 OS 中成功启用了休眠。 如果您使用扩展在虚拟机的操作系统中启用休眠状态,则可以检查扩展状态。

Linux VM 预配已成功的状态和状态消息报告的屏幕截图。

来宾 Linux 虚拟机无法休眠

如果使用扩展在来宾 OS 中启用休眠状态,则可以检查扩展状态。

Linux VM 上预配已成功的状态和状态消息报告的屏幕截图。

如果使用hibernate-setup-tool来配置来宾休眠设置,可以通过此命令检查该工具是否已成功执行。

systemctl status hibernation-setup-tool 

成功状态应返回“非活动(死)”,日志消息应显示“已成功设置 VM 休眠的交换文件”

示例:

azureuser@:~$ systemctl status hibernation-setup-tool
● hibernation-setup-tool.service - Hibernation Setup Tool
   Loaded: loaded (/lib/systemd/system/hibernation-setup-tool.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2021-08-25 22:44:29 UTC; 17min ago
  Process: 1131 ExecStart=/usr/sbin/hibernation-setup-tool (code=exited, status=0/SUCCESS)
 Main PID: 1131 (code=exited, status=0/SUCCESS)

linuxhib2 hibernation-setup-tool[1131]: INFO: update-grub2 finished successfully.
linuxhib2 hibernation-setup-tool[1131]: INFO: udev rule to hibernate with systemd set up in /etc/udev/rules.d/99-vm-hibernation.rules.  Telling udev about it.
...
...
linuxhib2 hibernation-setup-tool[1131]: INFO: systemctl finished successfully.
linuxhib2 hibernation-setup-tool[1131]: INFO: Swap file for VM hibernation set up successfully

如果未为客户操作系统配置休眠,请采取适当的措施来解决该问题。 例如,如果来宾由于空间不足而无法配置休眠,请调整 OS 磁盘的大小以解决该问题。

Debian 映像中的 Azure 扩展已禁用

当前,Azure 扩展在 Debian 映像中默认被禁用(有关更多详细信息,请见此处:https://lists.debian.org/debian-cloud/2023/07/msg00037.html)。 如果要通过 LinuxHibernationExtension 为基于 Debian 的 VM 启用休眠,则可以通过 cloud-init 自定义数据重新启用对 VM 扩展的支持:

#!/bin/sh
sed -i -e 's/^Extensions\.Enabled =.* $/Extensions.Enabled=y/" /etc/waagent.conf

新 Linux VM 的云初始化输入字段的屏幕截图。

或者,可以通过在 Linux VM 上安装休眠设置工具来启用来宾的休眠功能。