Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux grub.conf 损坏丢失修复:救援模式重建配置与重装 GRUB 引导

編輯:關於 Linux

/boot/grub/grub.conf 损坏或丢失会导致启动停留在 grub> 提示符,无法进入系统。使用安装光盘 Linux Rescue 模式 挂载根分区,手工重写 grub.conf 并重装 GRUB 至 MBR 即可恢复启动。

一、进入救援模式

  1. 插入安装光盘,光驱启动。
  2. 启动画面输入 linux rescue 回车。
  3. 选择语言、键盘,系统自动挂载根分区至 /mnt/sysimage,选择 Continue。

二、Chroot 并重建 grub.conf

chroot /mnt/sysimage

# 编写最小 grub.conf
cat > /boot/grub/grub.conf <<'EOF'
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-71.el6.i686)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-71.el6.i686 ro root=/dev/sda3 rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto quiet
    initrd /initramfs-2.6.32-71.el6.i686.img
EOF
# 注意:
# root (hd0,0) 对应 /boot 分区 (/dev/sda1)
# kernel 行 root=/dev/sda3 对应根分区
# 请根据 fdisk -l 实际分区调整

三、重装 GRUB 至 MBR

grub --batch <<'EOF'
root (hd0,0)
setup (hd0)
quit
EOF

四、退出重启验证

exit
exit
reboot

五、预防建议

  • 备份 grub.conf:cp /boot/grub/grub.conf /boot/grub/grub.conf.bak。
  • 内核升级后自动更新 grub.conf(包管理器通常处理),手动编译内核需自行运行 grub-install 与更新配置。
  • UEFI 系统请使用 grub2-install --target=x86_64-efi 与 grub2-mkconfig。

grub 损坏救援模式示意图

救援模式 chroot 重写 grub.conf 并 grub setup (hd0) 重装引导扇区,可快速修复因配置丢失导致的启动失败。养成备份习惯可避免手工重写配置的繁琐。

Copyright © Windows教程網 All Rights Reserved