排查启动错误 - 发生磁盘读取错误Troubleshoot boot error - disk read error occurred

本文提供了解决在 Azure 虚拟机 (VM) 中无法读取磁盘的问题的步骤。This article provides steps to resolve issues where the disk cannot be read in an Azure virtual machine (VM).

症状Symptoms

使用启动诊断查看 VM 的屏幕截图时,你将看到屏幕截图显示以下消息提示:“发生磁盘读取错误。When you use Boot diagnostics to view the screenshot of the VM, you will see that the screenshot displays a prompt with the message "A disk read error occurred. 然后按 Ctrl+Alt+Del 重启”。Press Ctrl+Alt+Del to restart".

错误消息: 发生磁盘读取错误。请按 Ctrl+Alt+Del 重启。

原因Cause

此错误消息指示磁盘结构已损坏且无法读取。This error message indicates that the disk structure is corrupted and unreadable. 如果使用的是第 1 代 VM,则也可能是包含启动配置数据的磁盘分区未设置为“活动”。If you are using a Generation 1 VM, it's also possible that the disk partition containing the boot configuration data isn't set to Active.

解决方案Solution

过程概述Process overview

  1. 创建和访问修复 VM。Create and Access a Repair VM.
  2. 选择解决方案:Select a Solution:
  3. 启用串行控制台和内存转储收集。Enable serial console and memory dump collection.
  4. 重新生成 VM。Rebuild the VM.

备注

遇到此启动错误时,来宾操作系统 (OS) 无法正常运行。When encountering this boot error, the Guest operating system (OS) is not operational. 需要在脱机模式下进行故障排除来解决此问题。You'll be troubleshooting in offline mode to resolve this issue.

创建和访问修复 VMCreate and access a repair VM

  1. 使用 VM 修复命令的步骤 1-3 来准备一个修复 VM。Use steps 1-3 of the VM Repair Commands to prepare a Repair VM.
  2. 使用远程桌面连接来连接到修复 VM。Using Remote Desktop Connection, connect to the Repair VM.

将分区状态设置为活动Set partition status to active

第 1 代 VM 应先验证是否已将 BCD 存储所在的 OS 分区标记为“活动”。Generation 1 VMs should first verify that the OS partition which holds the BCD store is marked as Active. 如果你有第 2 代虚拟机,请跳至修复磁盘分区,因为“状态”标志在下一代中弃用。If you have a Generation 2 VM, skip ahead to Fix the Disk Partition, as the Status flag was deprecated in the later generation.

  1. 打开提升的命令提示符 (cmd.exe)。Open an elevated command prompt (cmd.exe).

  2. 输入“diskpart”以启动“DISKPART”工具。Enter diskpart to launch the DISKPART tool.

  3. 输入“list disk”以列出系统上的磁盘,并确定附加的 OS 虚拟硬盘 (VHD)。Enter list disk to list the disks on the system and identify the attached OS virtual hard disk (VHD).

  4. 在找到附加的 OS VHD 后,输入“sel disk #”以选择相应磁盘。Once the attached OS VHD is located, enter sel disk # to select the disk. 请参阅下图中的示例,其中磁盘 1 是附加的 OS VHD。See the following image for an example of where Disk 1 is the attached OS VHD.

    带有“list disk”命令的输出内容的 diskpart 窗口,其中磁盘 0 和磁盘 1 显示在表中。该窗口还会显示“sel disk 1”命令的输出内容,其中磁盘 1 是所选磁盘

  5. 选择该磁盘后,输入“list partition”以列出所选磁盘的分区。Once the disk is selected, enter list partition to list the partitions of the selected disk.

  6. 确定启动分区后,输入“sel partition #”以选择相应分区。Once the boot partition is identified, enter sel partition # to select the partition. 启动分区的大小通常约为 350 MB。The boot partition is often approximately 350 MB in size. 请参阅下图中的示例,其中分区 1 是启动分区。See the following image for example where Partition 1 is the boot partition.

    带有“list partition”命令的输出内容的 diskpart 窗口,其中分区 1 和分区 2 显示在表中。该窗口还会显示“sel partition 1”命令的输出内容,其中分区 1 是所选磁盘。

  7. 输入“detail partition”以检查分区的状态。Enter detail partition to check the status of the partition. 请参阅以下屏幕截图中的示例,其中分区设置为“活动:否”或“活动:是”。See the following screenshots for examples of the partition being set to Active: No or Active: Yes.

    “活动:否Active: No

    带有“detail partition”命令的输出内容的 diskpart 窗口,其中分区 1 设置为“活动:否”。

    “活动:是Active: Yes

    带有“detail partition”命令的输出内容的 diskpart 窗口,其中分区 1 设置为“活动:是”。

  8. 如果分区未设置为“活动”,请输入“active”以更改“活动”标志。If the partition is not set to Active, enter active to change the Active flag.

  9. 输入“detail partition”以检查状态更改是否已正确完成,并确认输出内容中是否包含“活动:是”。Enter detail partition to check that the status change was completed properly, and verify that the output includes Active: Yes.

  10. 输入“exit”以关闭 DISKPART 工具并保存配置更改。Enter exit to close the DISKPART tool and save your configuration changes.

修复磁盘分区Fix the disk partition

  1. 打开提升的命令提示符 (cmd.exe)。Open an elevated command prompt (cmd.exe).

  2. 使用以下命令对磁盘运行“CHKDSK”,并执行错误修复:Use the following command to run CHKDSK on the disk(s) and perform error fixes:

    chkdsk <DRIVE LETTER>: /f

    添加“/f”命令选项将修复磁盘上的任何错误。Adding the /f command option will fix any errors on the disk. 请确保将“<驱动器号>”替换为附加的 OS VHD 的盘符。Make sure to replace < DRIVE LETTER > with the letter of the attached OS VHD.

启用串行控制台和内存转储收集Enable the serial console and memory dump collection

建议:在重新生成 VM 之前,通过运行以下脚本来启用串行控制台和内存转储收集:Recommended: Before you rebuild the VM, enable the Serial Console and memory dump collection by running the following script:

  1. 以管理员身份打开权限提升的命令提示符会话。Open an elevated command prompt session as an Administrator.

  2. 运行以下命令:Run the following commands:

    启用串行控制台Enable the Serial Console:

    bcdedit /store <VOLUME LETTER WHERE THE BCD FOLDER IS>:\boot\bcd /ems {<BOOT LOADER IDENTIFIER>} ON 
    bcdedit /store <VOLUME LETTER WHERE THE BCD FOLDER IS>:\boot\bcd /emssettings EMSPORT:1 EMSBAUDRATE:115200
    
  3. 验 OS 磁盘上的可用空间是否大于 VM 上的内存大小 (RAM)。Verify that the free space on the OS disk is larger than the memory size (RAM) on the VM.

    如果 OS 磁盘上没有足够的空间,请更改将要创建内存转储文件的位置,并将该位置引用到具有足够可用空间的 VM 上附加的任何数据磁盘。If there's not enough space on the OS disk, change the location where the memory dump file will be created, and refer that location to any data disk attached to the VM that has enough free space. 若要更改位置,请在以下命令中将 %SystemRoot% 替换为数据磁盘的驱动器号(例如,F:)。To change the location, replace %SystemRoot% with the drive letter of the data disk, such as F:, in the following commands.

    用于启用 OS 转储的建议配置:Suggested configuration to enable OS Dump:

    从损坏的 OS 磁盘加载注册表配置单元:Load Registry Hive from the broken OS Disk:

    REG LOAD HKLM\BROKENSYSTEM <VOLUME LETTER OF BROKEN OS DISK>:\windows\system32\config\SYSTEM
    

    在 ControlSet001 上启用:Enable on ControlSet001:

    REG ADD "HKLM\BROKENSYSTEM\ControlSet001\Control\CrashControl" /v CrashDumpEnabled /t REG_DWORD /d 1 /f 
    REG ADD "HKLM\BROKENSYSTEM\ControlSet001\Control\CrashControl" /v DumpFile /t REG_EXPAND_SZ /d "%SystemRoot%\MEMORY.DMP" /f 
    REG ADD "HKLM\BROKENSYSTEM\ControlSet001\Control\CrashControl" /v NMICrashDump /t REG_DWORD /d 1 /f 
    

    在 ControlSet002 上启用:Enable on ControlSet002:

    REG ADD "HKLM\BROKENSYSTEM\ControlSet002\Control\CrashControl" /v CrashDumpEnabled /t REG_DWORD /d 1 /f 
    REG ADD "HKLM\BROKENSYSTEM\ControlSet002\Control\CrashControl" /v DumpFile /t REG_EXPAND_SZ /d "%SystemRoot%\MEMORY.DMP" /f 
    REG ADD "HKLM\BROKENSYSTEM\ControlSet002\Control\CrashControl" /v NMICrashDump /t REG_DWORD /d 1 /f 
    

    卸载损坏的 OS 磁盘:Unload Broken OS Disk:

    REG UNLOAD HKLM\BROKENSYSTEM
    

重新生成 VMRebuild the VM

使用 VM 修复命令的步骤 5 重新生成 VM。Use step 5 of the VM Repair Commands to rebuild the VM.