本文档包含有关内核崩溃错误所导致的虚拟机无响应的问题排查信息。
准备工作
- 如果您要在 Cloud Logging 中记录串行端口输出,请先了解 Cloud Logging。
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以选择以下任一选项向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
-
内核崩溃
当内核无法正确加载 initramfs
模块,而客户机操作系统启动又需要这些模块时,可能会发生内核崩溃。
在这种情况下,如果内核不知道如何处理特定请求,并通过停止来保护自己,就会发生另一种形式的内核崩溃。运行 RedHat、SUSE、CentOS 或 Ubuntu 的 Compute Engine 虚拟机可能会发生内核 panic。
常见的错误消息
以下是一些可供参考的最常见内核崩溃事件:
Kernel panic - not syncing: hung_task: blocked tasks
Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Kernel panic - not syncing: NMI: Not continuing
Kernel panic - not syncing: out of memory. panic_on_oom is selected
Kernel panic - not syncing: Fatal Machine check
常见原因
内核崩溃错误可能由多种原因导致。常见原因包括:
grub.cfg
文件中不存在与内核对应的initramfs
文件相关的条目。- 在内核安装过程中,系统未在
/boot
目录中生成initramfs
文件。 initramfs
文件仅部分生成或已损坏。
表现
在虚拟机实例上遇到内核崩溃时,一种常见的表现是内核不允许您连接到虚拟机,即使使用串行控制台也是如此。
您应该检查串行控制台日志,以识别客户机操作系统加载的内核,例如:
[ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.10.0-1160.95.1.el7.x86_64 (mockbuild@x86-vm-42.build.eng.bos.redhat.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Thu Aug 10 10:46:21 EDT 2023
以下示例展示了因 initramfs
问题而导致的内核 panic 事件:
[ 1.520840] No filesystem could mount root, tried: [ 1.520840] [ 1.521964] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) [ 1.523495] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 3.10.0-1160.95.1.el7.x86_64 #1 [ 1.524932] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/11/2022 [ 1.526901] Call Trace: [ 1.527421] dump_stack+0x41/0x60 [ 1.527978] panic+0xe7/0x2ac [ 1.528578] mount_block_root+0x2be/0x2e6 [ 1.529693] ? do_early_param+0x95/0x95 [ 1.530441] prepare_namespace+0x135/0x16b [ 1.531237] kernel_init_freeable+0x203/0x22d [ 1.532081] ? rest_init+0xaa/0xaa [ 1.532808] kernel_init+0xa/0x103 [ 1.533395] ret_from_fork+0x35/0x40 [ 1.535229] Kernel Offset: 0x23a00000 from 0xffffffff81000000
解决内核崩溃错误
如需解决内核 panic 错误,请执行以下步骤:
连接到串行控制台,然后通过 Google Cloud 控制台登录虚拟机。
在 Google Cloud 控制台中,点击虚拟机的重置。
GRUB 启动画面显示后,选择之前正常运行的内核或救援内核,然后启动系统。这会导致虚拟机使用所选内核启动。
虚拟机可访问后,您可以发起与虚拟机的 SSH 连接。
确定问题的原因,并相应采取进一步的措施。
例如,如果
initramfs
文件缺失或损坏,请完成以下步骤:使用
dracut
命令生成对应于原始内核的initramfs
文件:dracut -f /boot/initramfs-
KERNEL_VERSION .imgKERNEL_VERSION 将
KERNEL_VERSION
替换为虚拟机的当前内核版本。例如3.10.0-1160.95.1.el7.x86_64
。使用
grub2-mkconfig
命令更新grub2.cfg
文件,例如:grub2-mkconfig -o /boot/grub2/grub.cfg
生成
initramfs
文件后,您可以重启虚拟机,未出现任何错误。