Loading

Debian12迁移后无法启动排查

SEO

重建UEFI引导
重新安装Grub
引导写入NVRAM
更换硬盘无法启动

背景

服务器升级配置,不想重新安装系统配置环境,将原装有Debian的系统盘直接装进新机器,无法启动找不到可引导磁盘。

排查

使用外置USB引导启动正常,进入Ubuntu Live模式查看系统盘EFI分区正常。
参看The EFI Boot Process资料指出:

The EFI boot process doesn't refer to code in the MBR, and it normally doesn't use code in the boot sector of a partition, either. Instead, the EFI loads the boot loader specified by the EFI's built-in boot manager. This boot manager maintains a list of boot options in NVRAM, along with an order in which to try them.

可见EFI启动列表是存储在主板的NVRAM非启动磁盘上,对于新机器并没有在安装系统过程中写入NVRAM因此启动选项看不到Debian
因此,只要手动重建EFI引导,将启动项写入NVRAM即可完成修复。修复过程参考GrubEFIReinstall - Debian Wiki文档进行,启动Live模式切换root用户。

# 确保当前启动模式为uefi若下述目录不存在手动挂载,存在可跳过
mount -t efivarfs none /sys/firmware/efi/efivars
# 挂载rootfs与efi分区
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot/efi
# 绑定虚拟文件系统
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do mount -B $i /mnt/$i; done
# 进入无法启动的系统
chroot /mnt
# 安装并升级grub
grub-install /dev/sda
update-grub
# 使用^D退出chroot并重启

延伸

为什么Ventoy类似的U盘引导能够正常进行?
Ventoy的EFI分区比Debian的EFI分区多出额外BOOT目录,继续阅读The EFI Boot Process

The fallback boot loader mentioned earlier (EFI/BOOT/bootx64.efi, or variants of that, depending on the architecture) is something of a special case. This filename was originally intended for use only on removable media, so that they could be booted to install an OS. (If not for that fixed filename, a factory-fresh computer wouldn't be able to boot anything!)

对于系统安装盘等移动设备,默认读取EFI/BOOT/bootx64.efi用于保底,可通过grub-install --removable实现。

参考

Managing EFI Boot Loaders for Linux: Basic Principles
GrubEFIReinstall - Debian Wiki

posted @ 2025-05-19 12:14  azureology  阅读(107)  评论(0)    收藏  举报