0%

Linux: config Grub2, adding more kernel menu, personality environment

Linux provides a method to let users create personality boot menu.Doing as follows:

Config document location

/boot/grub2/grub.cfg
/etc/default/grub
/etc/grub.d/*

Adding more than one kernel boot to menu

Copy first menu from /boot/grub2/grub.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
menuentry 'CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.10.1.el7.x86_64-advanced-51497437-886c-472c-9c74-8ef2e459214b' {
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' cdbb3f80-2c48-4c5c-bc72-0f40023061b9
else
search --no-floppy --fs-uuid --set=root cdbb3f80-2c48-4c5c-bc72-0f40023061b9
fi
linux16 /vmlinuz-3.10.0-957.10.1.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap ifname=enp0s3:08:00:27:37:8e:ba elevator=deadline elevator=deadline
initrd16 /initramfs-3.10.0-957.10.1.el7.x86_64.img
}

then

1
2
cd /etc/grub.d
vim 40_custom
1
2
3
4
5
6
7
8
9
10
11
12
13
menuentry 'my CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted --id 'mygraphical' {
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' cdbb3f80-2c48-4c5c-bc72-0f40023061b9
else
search --no-floppy --fs-uuid --set=root cdbb3f80-2c48-4c5c-bc72-0f40023061b9
fi
linux16 /vmlinuz-3.10.0-957.5.1.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap ifname=enp0s3:08:00:27:37:8e:ba rhgb elevator=deadline systemd.unit=graphical.target

paste menuentry in 40_custom, then change name to “my centOS” and config it to fit your requirement, creating a new menu.
Don’t forget mkconfig, after doing that, the new menu can be created.

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

The new menu will be created at the bottom of /boot/grub.d/grub.cfg, when booting linux, it will show on the menu.

Change grub timeout

Sometimes, the default timeout is too long, users can change it.

1
cd /etc/default/grub
1
2
3
4
5
6
7
8
GRUB_TIMEOUT=25
GRUB_TIMEOUT_STYLE=menu
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap ifname=enp0s3:08:00:27:37:8e:ba elevator=deadline elevator=deadline"
GRUB_DISABLE_RECOVERY="true"

change to what time you want

1
GRUB_TIMEOUT=5

Showing process during booting

If you want to see the process detail during boot, delete the “rhgb quiet”

1
linux16 /vmlinuz-3.10.0-957.5.1.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap ifname=enp0s3:08:00:27:37:8e:ba rhgb elevator=deadline systemd.unit=graphical.target