Skip to content

Instantly share code, notes, and snippets.

@jefft
Created August 5, 2020 06:53
Show Gist options
  • Save jefft/76cf6c5f6605eee55df6079223d8ba1c to your computer and use it in GitHub Desktop.
Save jefft/76cf6c5f6605eee55df6079223d8ba1c to your computer and use it in GitHub Desktop.
Checks whether a Debian/Ubuntu system is liable to not boot due to grub-pc bug 1889556
#!/bin/bash
# Script to check whether a Debian/Ubuntu system will experience boot problems from https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1889556 / https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1889509
# https://www.redradishtech.com/display/~jturner/2020/07/30/symbol+%27grub_calloc%27+not+found+--+how+to+fix+on+AWS
pass()
{
echo "All good. $*"
exit
}
fail()
{
echo >&2 "Reboot may fail! $*"
exit 1
}
if [[ -d /sys/firmware/efi ]]; then
pass "System uses EFI, not BIOS, so is not affected"
fi
if zgrep -q "LP: #1889556" /usr/share/doc/grub-pc/changelog.Debian.gz; then
pass "grub version has fixed the bug #1889556"
fi
command -v debconf-get-selections >/dev/null || sudo apt-get install debconf-utils
devices="$(sudo debconf-get-selections | awk '$1=="grub-pc" && $2 == "grub-pc/install_devices" {print $4}')"
if [[ -z $devices ]]; then
pass "Although your grub is vulnerable to the bug, your debconf system has no preset devices to install grub onto. You will be prompted for a device when next running dpkg-reconfigure grub-pc"
fi
for device in $devices; do
[[ -e $device ]] || fail "Your grub version does not fix the bug, and grub is configured to install to nonexistent device $device. Please upgrade grub and/or 'dpkg-reconfigure grub-pc' until you are sure grub is installed on the correct boot device"
done
fail "Your grub version does not fix the bug. Please run 'dpkg-reconfigure grub-pc', select the correct boot device, and verify that grub gets installed on it without error."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment