#!/usr/bin/env bash # Boot check: shows how long the GRUB boot menu waits and which kernel boots by default. # Usage (as root): curl -sL boot.dei.my | bash set -uo pipefail G='\033[1;32m'; R='\033[1;31m'; Y='\033[1;33m'; B='\033[1m'; N='\033[0m' ok() { printf " ${G}OK${N} %b\n" "$*"; } bad() { printf " ${R}FIX${N} %b\n" "$*"; } warn() { printf " ${Y}NOTE${N} %b\n" "$*"; } [ "$(id -u)" = 0 ] || { echo "Run as root: curl -sL boot.dei.my | sudo bash"; exit 1; } CFG=/boot/grub/grub.cfg [ -r "$CFG" ] || { echo "No $CFG found (is this an Ubuntu/GRUB system?)"; exit 1; } # Effective settings = /etc/default/grub, then /etc/default/grub.d/*.cfg (later files win) eval "$( . /etc/default/grub 2>/dev/null; for f in /etc/default/grub.d/*.cfg; do [ -r "$f" ] && . "$f"; done printf 'T=%q S=%q RT=%q D=%q\n' "${GRUB_TIMEOUT:-}" "${GRUB_TIMEOUT_STYLE:-menu}" "${GRUB_RECORDFAIL_TIMEOUT:-}" "${GRUB_DEFAULT:-0}" )" LIVE_T=$(grep -m1 -oE 'set timeout=[-0-9]+' "$CFG" | cut -d= -f2) printf "\n${B}Boot menu${N}\n" need_fix=0 if [ "$S" = hidden ] || [ "${LIVE_T:-0}" -lt 3 ] 2>/dev/null; then bad "Menu waits ${B}${LIVE_T:-?}s${N} (style: $S): too short to pick another kernel"; need_fix=1 else ok "Menu shows for ${B}${LIVE_T}s${N} (style: $S)" fi printf "\n${B}Kernels${N}\n" RUN=$(uname -r) INSTALLED=$(ls /boot/vmlinuz-* 2>/dev/null | sed 's#/boot/vmlinuz-##' | sort -V) FIRST=$(grep -m1 -oE "/vmlinuz-[^ ]+" "$CFG" | sed 's#/vmlinuz-##') for k in $INSTALLED; do tag="" [ "$k" = "$RUN" ] && tag+=" ${G}(running now)${N}" [ "$k" = "$FIRST" ] && tag+=" ${B}<- boots by default${N}" [ -e "/boot/initrd.img-$k" ] || tag+=" ${R}(missing initrd!)${N}" printf " - %s%b\n" "$k" "$tag" done [ "$D" = 0 ] || warn "GRUB_DEFAULT=$D (not the first entry; check 'grub-editenv list')" if [ "$FIRST" = "$RUN" ]; then ok "Next boot uses the kernel that is running now ($RUN)" else bad "Next boot uses ${B}$FIRST${N}, not the running kernel ($RUN)" fi if dpkg-query -W -f='${Status}\n' linux-virtual linux-generic linux-image-virtual linux-image-generic 2>/dev/null | grep -q '^install ok installed'; then warn "A kernel meta-package is installed, so updates can add a newer kernel" else ok "No kernel meta-package: updates won't add a new kernel on their own" fi if [ "$need_fix" = 1 ]; then echo if { exec 3/dev/null; then read -r -u 3 -p "Make the boot menu show for 5 seconds? [Y/n] " a if [ "${a:-Y}" != n ] && [ "${a:-Y}" != N ]; then printf 'GRUB_TIMEOUT_STYLE=menu\nGRUB_TIMEOUT=5\nGRUB_RECORDFAIL_TIMEOUT=5\n' > /etc/default/grub.d/99-boot-menu.cfg update-grub >/dev/null 2>&1 && ok "Done: menu now shows for $(grep -m1 -oE 'set timeout=[-0-9]+' "$CFG" | cut -d= -f2)s" || bad "update-grub failed; run it by hand to see why" fi fi fi echo