IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    CentOS EFI格式化后恢复

    OenHan发表于 2019-03-13 05:27:51
    love 0

    为了测试docker windows把Windows10重装了,安装之后发现centos不能启动了,还以为在windows下使用ext2fsd把根分区破坏了,进去看访问却是正常的,看了一下windows下的ESP分区(EFI System Partition),实际上也是Linux的EFI挂在的分区,即:

    [oen@han EFI]# df | grep efi
    /dev/nvme0n1p2     98304     47432     50872  49% /boot/efi
    [oen@han EFI]# ls /boot/efi/EFI/
    Boot  centos  Dell  Microsoft
    [oen@han EFI]# ls /boot/efi/EFI/centos/
    BOOT.CSV  BOOTX64.CSV  fonts  fw  fwupia32.efi  fwupx64.efi  grub.cfg
    grubenv  grubx64.efi  mmx64.efi  MokManager.efi  shim.efi
    shimx64-centos.efi  shimx64.efi

    EFI目录下是有centos目录的,且下面是centos的相关引导文件,而当时看是没有centos目录的,才意识到安装windows时手贱把ESP分区格式化了,本文就记录如何恢复Linux引导等类似的问题,以免下次手贱时再折腾。

    首先需要将centos7刻录一个USB启动盘,iso镜像没版本要求

    从USB启动进入到live模式

    确保能执行efibootmgr命令,安装对应的包

    [oen@han EFI]# rpm -qf which efibootmgr 
    efibootmgr-17-2.el7.x86_64

    将根分区和efi分区挂在指定目录:

    mkdir -p /mnt/system
    mount /dev/nvme1n1p1 /mnt/system
    mount /dev/nvme0n1p2 /mnt/system/boot/efi

    挂在sys,proc,dev,然后chroot

    mount --bind /proc /mnt/system/proc
    mount --bind /dev /mnt/system/dev
    mount --bind /sys /mnt/system/sys
    chroot /mnt/system/

    在chroot内重装相关RPM

    [oen@han centos]# pwd
    /boot/efi/EFI/centos
    [oen@han centos]# for i in ls -d *;do rpm -qf $i;done | sort | uniq
    fwupdate-efi-12-5.el7.centos.x86_64
    grub2-efi-x64-2.02-0.76.el7.centos.1.x86_64
    shim-x64-15-2.el7.centos.x86_64

    在chroot内生成grub2.conf:

    grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

    退出chroot。

    添加EFI启动项,注意具体参数配置:

    efibootmgr -c -d /dev/nvme0n1 -p 2 -l '\EFI\centos\shimx64.efi' -L CentOS

    如果启动看不到windows或者CentOS,注意看一下efibootmgr BootOrder的配置。


    CentOS EFI格式化后恢复来自于OenHan

    链接为:https://oenhan.com/centos-grub2-efi-esp-recovery



沪ICP备19023445号-2号
友情链接