系统引导文件 grub 异常、命令修复
/boot/grub2/grub.cfg
isolinux.cfg
- 使用场景:ISOLINUX 是被用作从BIOS 中启动
isolinux/isolinux.cfg
# 必须的,因为使用菜单功能,也必须有 vesamenu.c32 文件
default vesamenu.c32
# 倒计时启动 50s
timeout 50
display boot.msg
# 以下信息都是一些界面图形化设置,一般不做改动
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title HyperServer
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
# search
# 通过文件(-f,——file)、文件系统标签(-l,——label)或文件系统UUID (-u,——fs-uuid)搜索设备
# ——set选项,找到的第一个设备将被设置为环境变量var的值。默认变量是' root '
# ——no-floppy选项防止搜索软盘设备,这可能会很慢
search --no-floppy --set=root -l 'HyperServer'
label HyperServer
# menu label:界面中显示是选项标签名称
menu label Install HyperServer with Custom Kickstart
# menu default:使此选项在默认情况下被选中,即使它不是列表中的第一个选项
menu default
# kernel vmlinuz:加载安装程序内核。在大多数情况下,它不应该被改变
kernel vmlinuz
# append:包含其他内核选项。initrd=和inst.stage2选项是必须的;您可以添加其他,比如 kickstart.ks
append initrd=initrd.img inst.stage2=hd:LABEL=HyperServer inst.ks=hd:LABEL=HyperServer:/ks.cfg nomodeset
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshoot
menu title Troubleshoot and Debug
label HyperServer
menu label Install HyperServer with Original Kickstart
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=HyperServer inst.ks=hd:LABEL=HyperServer:/origin.ks nomodeset console=tty1
menu separator # insert an empty line
label rescue
menu label ^Rescue a HyperServer Linux system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=HyperServer rescue nomodeset
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
grub
- 使用场景:GRUB2 是被用作从 UEFI 中启动
EFI/BOOT/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
if [ -f ${config_directory}/grubenv ]; then
load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi
export menuentry_id_option
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
terminal_output console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=5
fi
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###
### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
fi
### END /etc/grub.d/01_users ###
### BEGIN /etc/grub.d/10_linux ###
menuentry 'ctyunos (6.1.38-8) 23.01' --class hyperserver --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-6.1.38-8-advanced-5bc230d2-ca75-4026-af61-08b46e57e4e9' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod xfs
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 5bc230d2-ca75-4026-af61-08b46e57e4e9
else
search --no-floppy --fs-uuid --set=root 5bc230d2-ca75-4026-af61-08b46e57e4e9
fi
echo 'Loading Linux 6.1.38-8 ...'
linux /boot/vmlinuz-6.1.38-8 root=UUID=5bc230d2-ca75-4026-af61-08b46e57e4e9 ro crashkernel=0M-4G:128M,4G-8G:256M,8G-:512M transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G nomodeset
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-6.1.38-8.img
}
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/10_reset_boot_success ###
# Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry
if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then
set menu_hide_ok=1
else
set menu_hide_ok=0
fi
# Reset boot_indeterminate after a successful boot
if [ "${boot_success}" = "1" ] ; then
set boot_indeterminate=0
# Avoid boot_indeterminate causing the menu to be hidden more than once
elif [ "${boot_indeterminate}" = "1" ]; then
set boot_indeterminate=2
fi
# Reset boot_success for current boot
set boot_success=0
save_env boot_success boot_indeterminate
### END /etc/grub.d/10_reset_boot_success ###
### BEGIN /etc/grub.d/12_menu_auto_hide ###
if [ x$feature_timeout_style = xy ] ; then
if [ "${menu_show_once}" ]; then
unset menu_show_once
save_env menu_show_once
set timeout_style=menu
set timeout=60
elif [ "${menu_auto_hide}" -a "${menu_hide_ok}" = "1" ]; then
set orig_timeout_style=${timeout_style}
set orig_timeout=${timeout}
if [ "${fastboot}" = "1" ]; then
# timeout_style=menu + timeout=0 avoids the countdown code keypress check
set timeout_style=menu
set timeout=0
else
set timeout_style=hidden
set timeout=1
fi
fi
fi
### END /etc/grub.d/12_menu_auto_hide ###
### BEGIN /etc/grub.d/14_menu_show_once ###
if [ x$feature_timeout_style = xy ]; then
if [ "${menu_show_once_timeout}" ]; then
set timeout_style=menu
set timeout="${menu_show_once_timeout}"
unset menu_show_once_timeout
save_env menu_show_once_timeout
fi
fi
### END /etc/grub.d/14_menu_show_once ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/30_uefi-firmware ###
if [ "$grub_platform" = "efi" ]; then
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
fwsetup
}
fi
### END /etc/grub.d/30_uefi-firmware ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f ${config_directory}/custom.cfg ]; then
source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg
fi
### END /etc/grub.d/41_custom ###
下面是最重要的两句,关系到系统引导时候能否成功
linux /boot/vmlinuz-6.1.38-8 root=UUID=5bc230d2-ca75-4026-af61-08b46e57e4e9 ro crashkernel=0M-4G:128M,4G-8G:256M,8G-:512M transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G nomodeset
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-6.1.38-8.img
1、模拟当grub文件丢失或内容错误,导致系统无法正常启动,删除系统中 /boot/grub2/grub.cfg
rm /boot/grub2/grub.cfg
2、开机后,系统无法正常启动,由于丢失 grub 引导文件,相当丢失了地图,grub 无法正常引导 kernel、initramfs 引导镜像
开机过程中 看到grub 界面,按 shift 后,停止读秒,再按 c,进入grub 命令行界面
GNU GRUB version 2.06
Minimal BASH-like line editing is supported. for the first word, TAB lists possible command completions.Anywhere else TAB lists possible device or file completions.
grub>
grub>
3、进入 grub 系统调试模式,手动设置引导文件位置
grub> cat (hd0 使用tab键自动补全提示,此时会出现很多关于 hd0,msdos1 等分区目录的相关信息
Device hd0: No known filesystem detected - Sector size 512B - Total size .......
Partition hd0,msdos1:......
Partition hd0,msdos2:......
Partition hd0,msdos3:......
4、找到系统盘和boot 下引导文件的位置
grub> cat (hd0,msdos1)/ 使用tab键自动补全,此时会出现这个分区目录下文件,如果下面有引导镜像,说明是boot 分区
Possible files are:
lost+found/ efi/ grub2/ config-6.1.38-8 vmlinuz-6.1.38-8 dracut/ initramfs-6.1.38-8.img System.map-6.1.38-8 loader/
grub> cat (hd0,msdos3)/ 使用tab键自动补全,此时会出现这个分区目录下文件,如果下面有系统目录,说明是系统盘 / 分区
Possible files are:
boot/ dev/ proc/ run/ sys/ tmp/ etc/ root/ var/ usr/ usr/ bin sbin lib lib64 afs/ data/ home/ media/ mnt/ opt/ srv/
5、找到系统分区后,查看当前系统分区的 UUID 信息,重点看 /boot 分区 和 / 分区
grub> cat (hd0,msdos3)/etc/fstab
UUID=aaaaaaaaaaaaaaaaaaa /
UUID=bbbbbbbbbbbbbbbbbbb /boot
......
6、grub 中手动设置文件路径
grub> linux (hd0,msdos1)/vmlinuz-6.1.38-8 ro root=UUID=aaaaaaaaaaaaaaaaaaa
grub> initrd (hd0,msdos1)/initramfs-6.1.38-8.img
grub> boot
7、此时系统能顺利进入系统,需要重新生成一下 grub 文件
# grub2-mkconfig -o /boot/grub2/grub.cfg
参考:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/anaconda_customization_guide/sect-boot-menu-customization