linux 虚机断电后出现 Entering emergency mode

背景

今天 vmware esxi 有一台虚拟机(Centos 7.9)强制关闭电源,再次打开电源之后直接进入紧急模式,显示界面如下:

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.

:/#

查看日志

从报错信息中看到输入 journalctl 命令就可以查看本次启动的日志,日志最后如下:

:/# journalctl

......
Jan 30 02:11:39 centos7tp systemd[1]: XFS (dm-0): Mount V5 Filesystem
Jan 30 02:11:39 centos7tp systemd[1]: XFS (dm-0): Starting recovery (logdev: internal)
......
Jan 30 02:11:39 centos7tp systemd[1]: sysroot.mount mount process exited, code=exited status=1
Jan 30 02:11:39 centos7tp systemd[1]: Failed to mount /sysroot.
Jan 30 02:11:39 centos7tp systemd[1]: Dependency failed for Initrd Root File System
Jan 30 02:11:39 centos7tp systemd[1]: Dependencu failed for Reload Conf iquration from the Real Root

以上信息说明如下几点:

  • 错误原因是无法挂载到系统,即 Failed to mount /sysroot
  • 文件系统为 xfs,受损的引导分区为 dm-0,而 /dev/dm-0 是 /dev/mapper/centos-root 的软连接

解决办法

首先,确认一下 /etc/fstab 中的挂载点配置没有问题

注:vmware安装的虚拟机如果挂载多个磁盘则会遇到一个问题:重启机器会导致 fdisk -l 识别的设备变掉,比如 /dev/sdb 变成了 /dev/sda,此时若 /etc/fstab 中配置的是 /dev/sdb /data ext4 noatime 1 2,则重启之后就会进入紧急模式。解决办法就是执行 blkid 找到 /dev/sdb 对应的uuid,然后在 fstab 中使用uuid配置挂载,比如 UUID=7cb2374d-76e8-406e-b4e3-1b6b06bdfb21 /data ext4 noatime 1 2

然后,输入 xfs_repair -v -L /dev/dm-0 修复 /dev/dm-0(注:ext对应修复工具为 fsck),并重启系统。

/# ls -l /dev/mapper/centos-root
lrwxrwxrwx 1 root 0 7 Jan 30 06:43 /dev/mapper/centos-root ->../dm-0

:/# xfs_repair -v -L /dev/dm-0
Phase 1 - find and verify superblock...
bad primary superblock - bad magic number !!!

attempting to find secondary superblock...
........................................................................................
........................................................................................
........................................................................................

Phase               Start           End                 Duration
Phase 1:            01/31 10:03:43  01/31 10:03:43
Phase 2:            01/31 10:03:43  01/31 10:03:43
Phase 3:            01/31 10:03:43  01/31 10:04:03      20 seconds
Phase 4:            01/31 10:04:03  01/31 10:04:03
Phase 5:            01/31 10:04:03  01/31 10:04:03
Phase 6:            01/31 10:04:03  01/31 10:04:05      2 seconds
Phase 7:            01/31 10:04:05  01/31 10:04:05

Total run time : 22 seconds
done

:/# reboot

附:xfs_repair 参数解析

  • -v Verbose output.
  • -L Force log zeroing. 强制将日志归零,即使它包含脏数据(元数据更改);

遇到的问题

使用 xfs_rapair 修复 /dev/mapper/centos-root 提示 Device or resource busy,执行 umount 之后仍报此提示,过程如下:

:/# xfs_repair -v -L /dev/mapper/centos-root
xfs_repair: cannot open /dev/mapper/centos-root: Device or resource busy

:/# umount /dev/mapper/centos-root
umount: /dev/mapper/centos-root: not mounted

:/# xfs_repair -v -L /dev/mapper/centos-root
xfs_repair: cannot open /dev/mapper/centos-root: Device or resource busy

解决办法

第1步,将ubuntu桌面版(此版本有引导系统,类似 Windows PE) ubuntu-20.04.5-desktop-amd64.iso 挂载到虚拟机的 CD/DVD驱动器,然后修改引导选项,强制下次引导时进入BIOS设置屏幕(否则无法进入引导系统)。

第2步,从 ubuntu引导系统进入终端(注:centos 7.9的分区不会变),执行 xfs_repair 修复,并重启系统。

xfs_repair -v -L /dev/mapper/centos-root
reboot
Copyright © www.sqlfans.cn 2023 All Right Reserved更新时间: 2023-05-26 17:00:48

results matching ""

    No results matching ""