CompTIA Linux+ Certification Guide
上QQ阅读APP看书,第一时间看更新

GRUB2

GRUB2 uses a more programmatic approach in the way the menu is presented. At first glance, GRUB2 may look intimidating, but rest assured that it's not as complicated as it appears to be. The syntax is similar to a programming language, with lots of if...then statements. Here is what /boot/grub/grub.cfg looks like on a CentOS 7 system:

[root@localhost ~]# cat /boot/grub2/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 [ -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

Some of the following output is omitted for the sake of brevity in /boot/grub/grub.cfg:

### BEGIN /etc/grub.d/10_linux ###
menuentry 'CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-16e2de7b-b679-4a12-888e-55081af4dad8' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 40c7c63f-1c93-438a-971a-5331e265419b
else
search --no-floppy --fs-uuid --set=root 40c7c63f-1c93-438a-971a-5331e265419b
fi
linux16 /vmlinuz-3.10.0-693.el7.x86_64 root=UUID=16e2de7b-b679-4a12-888e-55081af4dad8 ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-693.el7.x86_64.img
}
### END /etc/grub.d/10_linux ###

So, to interpret the /boot/grub/grub.cfg file, we look for lines that start with menuentry. These lines start the actual menu entry for an operating system, such as a Linux distribution or a Windows OS.

Entries are enclosed within curly braces {}.