Created
January 17, 2018 22:57
-
-
Save ZuZuD/66decbe330ec560ac8e57e87150891b8 to your computer and use it in GitHub Desktop.
Parse /boot/grub/grub.cfg to help set GRUB_DEFAULT opts in /etc/default/grub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export GRUB_CONFIG=`sudo find /boot -name "grub.cfg"` | |
awk 'BEGIN {submenu=0;menu=0};$1 ~ /submenu/ {submenu+=1;menu=0;sub(/\$.*$/,"");print submenu" " $0};/menuentry / && /Linux/ {gsub(/menuentry/,"");gsub(/--class.*$/,"");gsub(/\047/,"");print " "submenu">"menu " " $0;menu+=1}' $GRUB_CONFIG | |
# 1 submenu 'Advanced options for Ubuntu 3.19' | |
# 1>0 Ubuntu, with Linux 3.19.0-75-generic | |
# 1>1 Ubuntu, with Linux 3.19.0-75-generic (recovery mode) | |
# 1>2 Ubuntu, with Linux 3.13.0-139-generic | |
# 1>3 Ubuntu, with Linux 3.13.0-139-generic (recovery mode) | |
# 2 submenu 'Advanced options for Ubuntu 4.2' | |
# 2>0 Ubuntu, with Linux 4.2.0-30-generic | |
# 2>1 Ubuntu, with Linux 4.2.0-30-generic (recovery mode) | |
# cat /etc/default/grub |grep GRUB_DEFAULT | |
# GRUB_DEFAULT="2>0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for posting this awk which is just what I needed to incorporate as part of a GRUB.sh that I've created to work with EFI multi-boot Ubuntu which was problematic trying to boot different kernels. Regards, Pete J