Skip to content

Instantly share code, notes, and snippets.

@jikamens
Created August 9, 2021 12:58
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 jikamens/c131faf1ac062b59f3111f7fb553c85f to your computer and use it in GitHub Desktop.
Save jikamens/c131faf1ac062b59f3111f7fb553c85f to your computer and use it in GitHub Desktop.
Script to force Ubuntu 21.04 to use kernel version 5.10
#!/bin/bash -e
# You will probably need to adjust this script if you aren't using
# the generic kernel.
to_install=
to_hold=
pd=/tmp/packages.$$
mkdir $pd
# Get good Kernel packages
while read package arch; do
to_hold="$to_hold $package:$arch"
if dpkg-query --show --showformat '${Package} ${Version} ${Status}\n' \
$package:$arch 2>/dev/null | grep -v deinstall |
grep -q -s '5\.10\.0-14\.15 '
then
continue
fi
deb_name="${package}_5.10.0-14.15_${arch}.deb"
echo Downloading $deb_name
curl --location --silent --output $pd/$deb_name \
"https://launchpad.net/ubuntu/+archive/primary/+files/$deb_name"
to_install="$to_install $pd/$deb_name"
done < <(dpkg-query --show --showformat \
'${Package} ${Architecture} ${Version} ${Source}\n' '*linux*' |
awk '$4 == "linux" || $4 == "linux-signed" {print $1, $2}' |
sed 's/-5\.[0-9.]*-[0-9]*/-5.10.0-14/' | sort -u)
# Get good Kernel meta-packages
while read package arch version; do
to_hold="$to_hold $package:$arch"
if [ "$version" == "5.10.0.14.16" ]; then
continue
fi
deb_name="${package}_5.10.0.14.16_${arch}.deb"
echo Downloading $deb_name
curl --location --silent --output $pd/$deb_name \
"https://launchpad.net/ubuntu/+archive/primary/+files/$deb_name"
to_install="$to_install $pd/$deb_name"
done < <(dpkg-query --show --showformat \
'${Package} ${Architecture} ${Version} ${Source}\n' '*linux*' |
awk '$4 == "linux-meta" {print $1, $2, $3}')
if [ -n "$to_install" ]; then
apt-get install $to_install
fi
if [[ $(uname -r) =~ 5\.11 ]]; then
echo
echo "*** NOTE NOTE NOTE ***"
echo
echo "You need to reboot, select the 5.10 kernel during boot, and"
echo "rerun this script."
echo
echo "Before rebooting, make sure GRUB_TIMEOUT is set to a non-zero value"
echo "and GRUB_TIMEOUT_STYLE is set to 'menu' in /etc/default/grub, and if"
echo "you have to change either of them, run 'sudo update-grub' before"
echo "rebooting. Otherwise, you won't be able to easily select the 5.10"
echo "kernel when you reboot."
echo
echo "*** NOTE NOTE NOTE ***"
echo
exit 1
fi
if [ -n "$to_hold" ]; then
apt-mark hold $to_hold
fi
# Uninstalling the 5.11 kernel
to_remove="$(dpkg-query --show --showformat \
'${Package} ${Architecture} ${Version} ${Source} ${Status}\n' \
'*linux*' | grep -v deinstall |
awk '$4 == "linux" && $3 ~ /^5\.11/ {print $1 ":" $2}')"
if [ -n "$to_remove" ]; then
apt-get remove $to_remove
fi
rm -rf $pd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment