排查 Azure Linux 虚拟机中的 UEFI 启动失败问题
注意
本文中引用的 CentOS 是 Linux 发行版, (EOL) 将达到生命周期结束。 相应地考虑使用和计划。 有关详细信息,请参阅 CentOS 生命周期终止指南。
Azure 市场 中的 Linux 合作伙伴映像已标记并配置为 BIOS 第 1 代启动和统一可扩展固件接口 (UEFI) 第 2 代启动。
在 Azure 中) 部署第 2 代 Linux 虚拟机 (VM 时,可能会遇到 UEFI 启动失败。 本文讨论发生 UEFI 启动失败的一些方案,并提供解决方案。
症状
在 Azure 中部署第 2 代 Linux VM 时,启动失败,并且服务器不可访问。
识别 UEFI 启动错误
使用 Azure 启动诊断检查 VM 的当前状态。
启动诊断屏幕截图显示以下错误消息:
错误 1
虚拟机启动摘要
- 未知设备
启动加载程序未加载操作系统。 - SCSI 磁盘 (0,0)
启动加载程序未加载操作系统。 - SCSI 磁盘 (0,1)
启动加载程序未加载操作系统。 - 网络适配器 (000D3A4DD64D)
找不到启动映像。
未加载任何操作系统。 虚拟机配置可能不正确。 退出并重新配置 VM,或单击“重启”再次重试当前启动序列。
- 未知设备
错误 2
通过 IPv4 启动 PXE
排查问题之前
若要执行方案 1:启动映像中的 UEFI 分区缺失和方案 2:启动映像中的 UEFI 分区损坏所需的脱机 VM 修复,请确保有权访问 Azure CLI 或 Azure Cloud Shell。
方案 1:启动映像中缺少 UEFI 分区
如果缺少或删除 UEFI 启动加载程序分区,则第 2 代 Linux VM 将无法启动。
若要解决此问题,请按照下列步骤操作:
使用 az vm repair create 命令创建修复 VM。 修复 VM 将附加非正常运行 VM 的 OS 磁盘副本。 有关详细信息,请参阅 使用 Azure 虚拟机修复命令修复 Linux VM。
使用以下命令重新创建分区:
root@repair-centos7:~# gdisk /dev/sdc GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/sdc: 134217728 sectors, 64.0 GiB Model: Virtual Disk Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): <Disk GUID> Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 134217694 Partitions will be aligned on 2048-sector boundaries Total free space is 1019837 sectors (498.0 MiB) Number Start (sector) End (sector) Size Code Name 1 1026048 3123199 1024.0 MiB 0700 2 3123200 134215679 62.5 GiB 8E00 14 2048 10239 4.0 MiB EF02 Command (? for help): n Partition number (3-128, default 3): First sector (34-134217694, default = 10240) or {+-}size{KMGTP}: 10240 Last sector (10240-1026047, default = 1026047) or {+-}size{KMGTP}: 1026047 Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): ef00 Changed type of partition to 'EFI System' Command (? for help): p Disk /dev/sdc: 134217728 sectors, 64.0 GiB Model: Virtual Disk Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): <Disk GUID> Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 134217694 Partitions will be aligned on 2048-sector boundaries Total free space is 4029 sectors (2.0 MiB) Number Start (sector) End (sector) Size Code Name 1 1026048 3123199 1024.0 MiB 0700 2 3123200 134215679 62.5 GiB 8E00 3 10240 1026047 496.0 MiB EF00 EFI System 14 2048 10239 4.0 MiB EF02 Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/sdc. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
重要
- 将 替换为
/dev/sdc
操作系统 (操作系统) 磁盘设备的相应副本。 - 只要扇区起点和终点正确,分区号选择就无关紧要。 选择正确的扇区起点和终点,因为 OS 能够确定缺少的扇区。
- 确保结束扇区未被磁盘内的任何其他分区占用。 此处选择默认值应已足够。
Azure Linux 合作伙伴映像具有以下分区号、扇区起始点和扇区终结点:
Linux OS 分发版 EFI 分区号 扇区启动 扇区结束 CentOS 7 15 10240 1024000 CentOS 8 15 10240 1024000 Debian 10 15 8192 262143 Debian 11 15 8192 262143 RHEL 7 1 2048 1026047 RHEL 8 15 10240 1024000 Oracle Linux 7 15 10240 1024000 Oracle Linux 8 15 10240 1024000 Ubuntu 18.04 15 10240 227327 Ubuntu 20.04 15 10240 227327 SLES 12 2 6144 1054719 SLES 15 2 6144 1054719 - 将 替换为
重新创建分区后,通过使用 az vm repair restore 命令将修复的 OS 磁盘与 VM 的原始 OS 磁盘交换来还原 VM。 有关详细信息,请参阅 使用 Azure 虚拟机修复命令修复 Linux VM 中的步骤 5。
方案 2:启动映像中的 UEFI 分区已损坏
如果 UEFI 启动分区已损坏,则第 2 代 Linux VM 将无法启动。 若要解决此问题,请按照下列步骤操作:
使用 az vm repair create 命令创建修复 VM。 修复 VM 将附加非正常运行 VM 的 OS 磁盘副本。 有关详细信息,请参阅 使用 Azure 虚拟机修复命令修复 Linux VM。
使用以下命令清理损坏的分区:
root@repair-centos7:~# gdisk -l /dev/sdc GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/sdc: 134217728 sectors, 64.0 GiB Model: Virtual Disk Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): <Disk GUID> Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 134217694 Partitions will be aligned on 2048-sector boundaries Total free space is 4029 sectors (2.0 MiB) Number Start (sector) End (sector) Size Code Name 1 1026048 3123199 1024.0 MiB 0700 2 3123200 134215679 62.5 GiB 8E00 3 10240 1026047 496.0 MiB EF00 EFI System 14 2048 10239 4.0 MiB EF02 root@repair-centos7:~# fsck.vfat -n /dev/sdc3 fsck.fat 4.1 (2017-01-24) 0x25: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt. Automatically removing dirty bit. Leaving filesystem unchanged. /dev/sdc3: 19 files, 1438/63326 clusters root@repair-centos7:~# fsck.vfat /dev/sdc3 fsck.fat 4.1 (2017-01-24) 0x25: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt. 1) Remove dirty bit 2) No action ? 1 Perform changes ? (y/n) y /dev/sdc3: 19 files, 1438/63326 clusters root@repair-centos7:~# fsck.vfat /dev/sdc3 fsck.fat 4.1 (2017-01-24) /dev/sdc3: 19 files, 1438/63326 clusters
重要
- 将 替换为
/dev/sdc
OS 磁盘设备的相应副本。 - 在执行上述文件系统之前,
-n
始终备份 OS 磁盘并使用 选项执行试运行检查。 - 命令
dosfsck
可用于执行 vfat 文件系统检查。 这两个命令相同。 有关详细信息,请参阅 fsck.vfat。
- 将 替换为
清理分区后,通过使用 az vm repair restore 命令将修复的 OS 磁盘与 VM 的原始 OS 磁盘交换来 还原 VM 。 有关详细信息,请参阅 使用 Azure 虚拟机修复命令修复 Linux VM 中的步骤 5。
方案 3:删除整个 /boot 分区内容
如果缺少整个 /boot 分区或其他重要内容并且无法恢复,则从备份还原 VM 是唯一的选项。 有关详细信息,请参阅如何在 Azure 门户 中还原 Azure VM 数据。
联系我们寻求帮助
如果你有任何疑问或需要帮助,请创建支持请求或联系 Azure 社区支持。 还可以向 Azure 反馈社区提交产品反馈。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈