Skip to content

Instantly share code, notes, and snippets.

@suntong
Last active April 3, 2022 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/cafb2fc8eaaeb77871927abae16c54f0 to your computer and use it in GitHub Desktop.
Save suntong/cafb2fc8eaaeb77871927abae16c54f0 to your computer and use it in GitHub Desktop.
# == fundementals
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
set timeout=3
# == loadfont
font=unicode
set locale_dir=$prefix/locale
set lang=en_US
# -- load_video
insmod gettext
insmod gfxterm
insmod all_video
# load common modules
insmod gzio
insmod part_gpt
insmod ext2
## grub2 configuration
source /boot/grub/grub-header.cfg
insmod regexp
for config in /boot/grub/*_default.cfg ; do source "$config" ; done
for config in /boot/grub/*_options.cfg ; do source "$config" ; done
if [ -f /boot/grub/grub-addons.cfg ] ; then
source "/boot/grub/grub-addons.cfg"
fi
source /boot/grub/grub-footer.cfg
source /boot/grub/grub-main.cfg
/^submenu .Advanced options for /,/^}/d
/^menuentry /{ s/^/\n/; s/--\(class\|id\) .*$/{/ }
/load_video\|insmod/d
# remove entire if block
/feature_platform_search_hint/{ N; N; N; N; d; }
s/^\( \|\t\)/ /
sed -En '
1{s/^.*$/OS:/; p}
/^submenu .Advanced options for /,/^}/d
# WinOS
/^menuentry .*Windows/{
s/^menuentry /\n - Name: /
s/ --(class|id) .*$/\n Type: WinOS/
p
}
# LinOS
/^menuentry /{
s/^menuentry /\n - Name: /
s/ --(class|id) .*$/\n Type: LinOS/
p
}
# Root
/set root=/{
s/^\s*set root=/ Root: /
p
}
' "$@"
set iso_root=
export iso_root
source /boot/grub/iso-inc.cfg
set iso_root='(hd0,2)'
export iso_root
source /boot/grub/iso-inc.cfg
set iso_root='(hd0,3)'
export iso_root
source /boot/grub/iso-inc.cfg
submenu "Boot from ISO ... >" {
set menu_color_normal=black/light-gray
set menu_color_highlight=yellow/dark-gray
if [ x$iso_root != x ]; then set root=$iso_root; fi
insmod regexp
for isofile in /iso/*.iso; do
regexp --set=isoname "/iso/(.*)" "$isofile"
#export isoname
bootoptions="noeject noprompt nomce net.ifnames=0"
# more failsafe bootoptions
# memtest noapic noapm nodma nolapic nomodeset nosmp nosplash vga=normal
export bootoptions
submenu "$isoname >" "$isofile" {
set menu_color_normal=black/light-red
set menu_color_highlight=yellow/light-red
iso_path="$2"
loopback loop "$iso_path"
menuentry 'Live (ISO)' {
#echo 'Boot ISO $isoname ...'
echo 'Loading kernel...'
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$iso_path $bootoptions
echo 'Loading initrd...'
initrd (loop)/casper/initrd
# == debian-live
# linux (loop)/live/vmlinuz boot=live findiso=$iso_path components $bootoptions
# initrd (loop)/live/initrd.img
# == grml
# echo 'Loading kernel...'
# linux /boot/grml64full/vmlinuz apm=power-off boot=live findiso=$iso_path ${kernelopts} live-media-path=/live/grml64-full/ $bootoptions bootid=20bcd9c7-ec57-49c4-9f58-2a90493229af
# echo 'Loading initrd...'
# initrd /boot/grml64full/initrd.img
}
}
done
}
menuentry 'Debian GNU/Linux' {
set root='hd0,gpt2'
probe -u $root --set=rootuuid
echo 'Loading Linux ...'
linux /vmlinuz root=UUID=$rootuuid ro text net.ifnames=0
echo 'Loading initial ramdisk ...'
initrd /initrd.img
}
menuentry 'Debian 11 bullseye' {
set root='hd0,gpt2'
probe -u $root --set=rootuuid
echo 'Booting - Debian 11 bullseye'
echo 'Loading Linux Kernel ...'
linux /vmlinuz root=UUID=$rootuuid ro text net.ifnames=0
echo 'Loading initial ramdisk ...'
initrd /initrd.img
}
OS:
- # Name - Name of the boot entry
Name: Debian 11 bullseye
# Type - Type of the boot entry
# Values can be LinOS, WinOS
Type: LinOS
# Root - Partition to set grub root with
Root: hd0,gpt2
# Disk - Optional, Disk label of the partition
Disk:
menuentry 'Ubuntu 20.04 LTS (20.04) (on /dev/sda3)' {
set root='hd0,gpt3'
probe -u $root --set=rootuuid
echo 'Booting - Ubuntu 20.04 LTS (20.04) (on /dev/sda3)'
echo 'Loading Linux Kernel ...'
linux /boot/vmlinuz root=UUID=$rootuuid ro text net.ifnames=0 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=52
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img
}
menuentry 'Ubuntu 19.04 (19.04) (on /dev/sda7)' {
set root='hd0,gpt7'
probe -u $root --set=rootuuid
echo 'Booting - Ubuntu 19.04 (19.04) (on /dev/sda7)'
echo 'Loading Linux Kernel ...'
linux /boot/vmlinuz root=UUID=$rootuuid ro text net.ifnames=0 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=52
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img
}
menuentry 'Ubuntu 18.04 LTS (18.04) (on /dev/sda6)' {
set root='hd0,gpt6'
probe -u $root --set=rootuuid
echo 'Booting - Ubuntu 18.04 LTS (18.04) (on /dev/sda6)'
echo 'Loading Linux Kernel ...'
linux /boot/vmlinuz root=UUID=$rootuuid ro text net.ifnames=0 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=52
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img
}
menuentry 'Ubuntu 17.04 (17.04) (on /dev/sda8)' {
set root='hd0,gpt8'
probe -u $root --set=rootuuid
echo 'Booting - Ubuntu 17.04 (17.04) (on /dev/sda8)'
echo 'Loading Linux Kernel ...'
linux /boot/vmlinuz root=UUID=$rootuuid ro text net.ifnames=0 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=52
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img
}
menuentry 'Windows Boot Manager (on /dev/sda13)' {
set root='hd0,gpt13'
echo 'Booting - Windows Boot Manager (on /dev/sda13)'
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
{{range .OS}}
{{if eq .Type "LinOS" -}}
menuentry '{{.Name}}' {
set root='{{.Root}}'
probe -u $root --set=rootuuid
echo 'Booting - {{.Name}}'
echo 'Loading Linux Kernel ...'
linux /boot/vmlinuz root=UUID=$rootuuid ro text net.ifnames=0 zswap.enabled=1 zswap.compressor=lz4 zswap.zpool=z3fold zswap.max_pool_percent=52
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img
}{{else}}{{if eq .Type "WinOS" -}}
menuentry '{{.Name}}' {
set root='{{.Root}}'
echo 'Booting - {{.Name}}'
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}{{end}}{{end}}
{{end}}
OS:
- Name: 'Ubuntu 20.04 LTS (20.04) (on /dev/sda3)'
Type: LinOS
Root: 'hd0,gpt3'
- Name: 'Ubuntu 19.04 (19.04) (on /dev/sda7)'
Type: LinOS
Root: 'hd0,gpt7'
- Name: 'Ubuntu 18.04 LTS (18.04) (on /dev/sda6)'
Type: LinOS
Root: 'hd0,gpt6'
- Name: 'Ubuntu 17.04 (17.04) (on /dev/sda8)'
Type: LinOS
Root: 'hd0,gpt8'
- Name: 'Windows Boot Manager (on /dev/sda13)'
Type: WinOS
Root: 'hd0,gpt13'
@suntong
Copy link
Author

suntong commented Oct 26, 2021

aa758ee (HEAD -> master, origin/master, origin/HEAD) - [#] finish os2grub.tmpl; add os2grub.gold that generated from it
78e9424 - [#] finish grub2yaml.sh; add os2grub.yaml that generated from it
17db906 Revert "- [#] the ways for perl or tcl"
801aa16 - [#] this way works for tcl but not sed
0853ad6 - [#] this way works for perl but not sed
78f6fc1 - [+] add grub2yaml.sh
aef18c3 - [#] rename os2grub -> os2grub-1
a63b791 - [+] add os2grub easygen support
627e7d5 - [+] add grub.cfg
df22db4 - [-] remove entire if block
586786b - [+] add all .cfg files, and a sample os _default
3fb2866 

@suntong
Copy link
Author

suntong commented Oct 26, 2021

Boot menu image, for blogging
image

Credit here.

@suntong
Copy link
Author

suntong commented Oct 27, 2021

better menu image, for blogging

image

from https://help.ubuntu.com/community/Grub2/Submenus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment