适用于:✔️ Linux VM
重要
新功能! 请尝试使用 VM 协助解决首要问题。 建议您运行 Windows 的 VM 辅助 或 Linux 的 VM 辅助。 这些基于脚本的诊断工具可帮助你识别影响Azure VM 来宾代理和整体 VM 运行状况的常见问题。
如果在 VM 上遇到性能问题,请先运行这些工具,然后再联系Microsoft 支持部门。
总结
在Azure上运行 Linux 虚拟机(VM)时,Hyper-V驱动程序(也称为 Linux Integration Services (LIS)驱动程序对于适当的 VM 操作至关重要。 这些驱动程序允许 VM 与基础Azure虚拟机监控程序通信。 如果缺少或未正确加载这些驱动程序,VM 可能无法启动。 本文提供了 Azure Linux VM 中 LIS/Hyper-V 驱动程序问题的解决方案。
先决条件
- 访问 Azure Command-Line 接口 (CLI)
- 能够创建修复或救援虚拟机
- 串行控制台访问
- 熟悉 Linux 命令和系统管理
症状
在以下情况之一中,由于缺少或禁用了Hyper-V驱动程序,Linux VM 可能无法启动:
-
将 Linux VM 从本地迁移到Azure后。
将 VM 从其他虚拟机监控程序(如 VMware 或基于内核的虚拟机(KVM))迁移到 Azure 时,可能未安装或未启用必要的 Hyper-V 驱动程序
hv_vmbus、hv_storvsc、hv_netvsc和hv_utils,导致 VM 无法检测到存储和网络设备。 -
禁用Hyper-V驱动程序并重新启动 VM 后。
-
当 initramfs 中不包含Hyper-V驱动程序时。
查看各种 Linux VM(Red Hat、Oracle、SUSE 或 Ubuntu)的串行控制台日志时,通常会发现以下问题:
| 症状 | 说明 |
|---|---|
| VM 卡在 dracut/initramfs | 由于缺少存储驱动程序,VM 无法启动,进入 initramfs shell 或紧急模式。 |
| 启动时内核崩溃 | 由于缺少关键Hyper-V模块,系统在启动期间崩溃。 |
| 未找到磁盘的错误 | 启动进程失败,出现错误,如 cannot find root device 或 unable to mount root filesystem。 |
| 无网络连接 | 即使 VM 启动,也可能无法检测到网络接口,从而阻止安全外壳(SSH)访问。 |
| Grub 启动失败 | 由于缺少Hyper-V存储驱动程序,系统可能无法加载启动加载程序。 |
| 因 ACPI 错误而导致的慢启动 | VM 可能会因为缺少 Hyper-V 支持而导致与高级配置和电源接口(ACPI)相关的警告,进而需要很长时间才能启动。 |
| 无法附加Azure磁盘 | 由于缺少存储驱动程序,Azure托管磁盘可能无法识别或正确装载。 |
| Cloud-Init 或 Waagent 失败 | Azure预配工具(cloud-init或 waagent)可能无法正确配置 VM。 |
下面是日志条目示例:
-
输出 1
[ 201.568597] dracut-initqueue[351]: Warning: dracut-initqueue: starting timeout scripts [ 202.086401] dracut-initqueue[351]: Warning: dracut-initqueue: timeout, still waiting for following initqueue hooks: [ 202.097772] dracut-initqueue[351]: Warning: /lib/dracut/hooks/initqueue/finished/devexists-\x2fdev\x2fmapper\x2frootvg-rootlv.sh: "if ! grep -q After=remote-fs-pre.target /run/systemd/generator/systemd-cryptsetup@*.service 2>/dev/null; then [ 202.128885] dracut-initqueue[351]: [ -e "/dev/mapper/rootvg-rootlv" ] [ 202.138322] dracut-initqueue[351]: fi" [ 202.142466] dracut-initqueue[351]: Warning: dracut-initqueue: starting timeout scripts [ 202.674872] dracut-initqueue[351]: Warning: dracut-initqueue: timeout, still waiting for following initqueue hooks: [ 202.692200] dracut-initqueue[351]: Warning: /lib/dracut/hooks/initqueue/finished/devexists-\x2fdev\x2fmapper\x2frootvg-rootlv.sh: "if ! grep -q After=remote-fs-pre.target /run/systemd/generator/systemd-cryptsetup@*.service 2>/dev/null; then [ 202.724308] dracut-initqueue[351]: [ -e "/dev/mapper/rootvg-rootlv" ] [ 202.731292] dracut-initqueue[351]: fi" [ 202.732288] dracut-initqueue[351]: Warning: dracut-initqueue: starting timeout scripts [ 202.740791] dracut-initqueue[351]: Warning: Could not boot. Starting Dracut Emergency Shell... Warning: /dev/mapper/rootvg-rootlv does not exist Generating "/run/initramfs/rdsosreport.txt" Entering emergency mode. Exit the shell to continue. Type "journalctl" to view system logs. You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot after mounting them and attach it to a bug report. dracut:/# dracut:/# dracut:/# -
输出 2
Gave up waiting for root file system device. Common problems: - Boot args (cat /proc/cmdline) - Check rootdelay= (did the system wait long enough?) - Missing modules (cat /proc/modules; ls /dev) ALERT! UUID=143c811b-9b9c-48f3-b0c8-040f6e65f50aa does not exist. Dropping to a shell! BusyBox v1.27.2 (Ubuntu 1:1.27.2-2ubuntu3.4) built-in shell (ash) Enter 'help' for a list of built-in commands. (initramfs)
如果在 dracut shell 中运行 cat /proc/partitions 不显示任何存储设备,则表示缺少或未加载Hyper-V存储驱动程序hv_storvsc。 如果没有此驱动程序,VM 无法检测到其虚拟磁盘,从而导致启动失败。
dracut:/# cat /proc/partitions
dracut:/#
dracut:/#
原因
如果缺少或未正确加载 LIS/Hyper-V 驱动程序,VM 可能无法启动,原因如下:
-
缺少磁盘和网络驱动程序
Azure VM 依赖于Hyper-V存储和网络驱动程序(例如,
hv_storvsc和hv_netvsc)。 如果没有这些驱动程序,VM 无法检测到其作系统(OS)磁盘,从而导致启动失败。 -
缺乏合成设备支持
Azure VM 使用综合设备(例如存储和网络),这需要Hyper-V驱动程序。 如果没有这些驱动程序,内核可能无法识别关键组件。
-
Hyper-V VMBus 通信失败
hv_vmbus等基本组件处理 VM 与Azure虚拟机监控程序之间的通信。 如果缺少此驱动程序,则 VM 无法正确初始化。 -
内核恐慌或 initramfs 提示
如果没有必要的驱动程序,VM 可能会因无法装载根文件系统而进入 initramfs shell,导致启动失败。
解决方案 1:启用Hyper-V驱动程序
备注
此解决方案适用于禁用Hyper-V驱动程序的方案。
-
使用 VM 修复命令 创建具有附加受影响 VM OS 磁盘副本的修复 VM。
备注
或者,可以使用 Azure 门户手动创建救援 VM。 有关详细信息,请参阅使用 Azure 门户通过将 OS 磁盘附加到恢复 VM 来故障排除 Linux 虚拟机。
-
使用 chroot 在修复 VM 中装载 OS 文件系统的副本。
-
完成 chroot 进程后,转到 /etc/modprobe.d 目录。
-
标识禁用
hv_驱动程序的文件和相应的行号:grep -nr "hv_" /etc/modprobe.d/ -
修改相应的文件并注释掉或删除
hv_条目:vi /etc/modprobe.d/disable.conf备注
- 禁用驱动程序的条目由 Linux OS 而不是Microsoft定义。
- 将
disable.conf替换为禁用hv_驱动程序的相应文件名。
解决方案 2:在 initramfs 中重新生成缺少Hyper-V驱动程序
备注
此解决方案适用于 VM 从本地迁移到Azure后,Hyper-V驱动程序缺少 initramfs 的情况。
-
使用 VM 修复命令 创建具有附加受影响 VM OS 磁盘副本的修复 VM。
备注
或者,可以使用 Azure 门户手动创建救援 VM。 有关详细信息,请参阅使用 Azure 门户通过将 OS 磁盘附加到恢复 VM 来故障排除 Linux 虚拟机。
-
使用 chroot 在修复 VM 中装载 OS 文件系统的副本。
-
完成 chroot 进程后,验证当前内核上是否
hv_缺少驱动程序:-
对于基于 RHEL 的映像:
lsinitrd /boot/initramfs-<kernel-version>.img | grep -i hv_ -
对于基于 SLES 的映像:
lsinitrd /boot/initrd-<versión-del-kernel> | grep -i hv_ -
对于基于 Ubuntu/Debian 的映像:
lsinitrd /boot/initrd.img-$(uname -r) | grep -i hv_
备注
Hyper-V存储驱动程序
hv_storvsc或其他驱动程序可能不会出现在 initramfs 中,因为它有时直接内置到内核中,尤其是在Azure优化内核中。 在这种情况下,系统会在启动时自动加载它,确保存储功能。 如果 VM 启动并正确检测存储,则无需执行任何作。 -
-
根据 Linux 分发版编辑 /etc/dracut.conf 或 /etc/initramfs-tools/modules 文件,并将以下行添加到该文件:
-
对于基于 RHEL/SLES 的映像:
vi /etc/dracut.confadd_drivers+=" hv_vmbus hv_netvsc hv_storvsc " -
对于基于 Ubuntu/Debian 的映像:
vi /etc/initramfs-tools/moduleshv_vmbus hv_netvsc hv_storvsc
-
-
按照手动重新生成缺失的 initramfs中的步骤,为受影响的内核版本重新生成初始 RAM 磁盘映像。
FAQ
如果遇到一些问题(如连接),如何确保网络驱动程序(hv_netvsc)在系统全新启动或重启后按预期工作?
若要确认Hyper-V网络驱动程序(hv_netvsc)处于活动状态且功能正常,请检查系统日志并查找以下条目:
*hv\_vmbus: registering driver hv\_netvsc*
此消息指示驱动程序注册过程已启动。 如果之后未报告进一步的错误,则驱动程序已成功加载并正常运行。 这表示检测到Hyper-V提供的合成网络接口,并且驱动程序正在正确处理网络连接。