Liunx 删除 /boot 恢复方法

    用公网的包

(1) 进入救援模式

        将 CentOS 7.9 安装 DVD 插入光驱,设置计算机从 DVD 启动。不同计算机进入 BIOS/UEFI 设置启动顺序的方式不同,常见的有按 Del、F2、F10 等键。
        在启动界面选择 Troubleshooting(故障排查)选项。
      接着选择 Rescue a CentOS system(救援 CentOS 系统)。
      等待系统加载相关文件,加载完成后,按提示选择 Continue,系统会自动将原系统挂载到 /mnt/sysimage。
     执行以下命令切换根目录,使后续操作在原系统环境中进行:
      chroot /mnt/sysimage

    (2)配置网络连接

         在救援模式下,需要先配置网络让系统能够访问外网。以下以配置静态 IP 为例(如果使用 DHCP 可以跳过此步骤,部分系统救援模式可能会自动获取 DHCP 地址)。

        查看网络接口

        ip link show

        通常网络接口名称为 eth0、ens33 等,记住你要使用的接口名称。

        配置静态 IP 

        假设使用的接口为 eth0,以下命令将配置静态 IP 地址、子网掩码、网关和 DNS 服务器:

        ip addr add 192.168.1.88/24 dev eth0 #ip配置

        ip link set eth0 up #打开

        ip route add default via 192.168.1.1 #配置默认网关

        echo "nameserver 8.8.8.8" > /etc/resolv.conf #配置dns  nameserver 后面接地址

       请根据实际网络环境修改上述 IP 地址、子网掩码、网关和 DNS 服务器信息。

       验证网络连接

       ping -c  www.baidu.com

       (3)配置 Yum 源

             wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo    或者

            curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

         清理并生成 Yum 缓存

         yum clean all

         yum makecache

      

      (4)重新安装内核和相关文件

           执行以下命令重新安装内核,该操作会恢复 /boot 目录下的关键文件,如内核镜像 vmlinuz 和初始化内存盘 initramfs:

         yum -y reinstall kernel

         修复引导(根据启动模式选择)
         BIOS 模式(传统启动)
         grub2-install /dev/sda  # 假设系统盘为sda

         grub2-mkconfig -o /boot/grub2/grub.cfg

         UEFI 启动(新服务器常见)
         安装 UEFI 版 GRUB2 和 Shim:

         yum -y reinstall grub2-efi shim

         生成 GRUB 配置文件(指定 EFI 分区,通常为 /dev/sda1):

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

        (5)重启系统

               exit

              reboot

你可能感兴趣的:(linux)