Skip to content

Instantly share code, notes, and snippets.

@ekarad1um
Last active October 30, 2019 05:23
Show Gist options
  • Select an option

  • Save ekarad1um/bfe2b197300b526cb1d3129bdf79671a to your computer and use it in GitHub Desktop.

Select an option

Save ekarad1um/bfe2b197300b526cb1d3129bdf79671a to your computer and use it in GitHub Desktop.
Update Ubuntu kernel

For Ubuntu users who wandering to support newer versions of hardware or getting new features, it's recommaned to update Ubuntu kernel. We could do it by sudo gedit updatekernel.sh && chmod -x updatekernel.sh && bash updatekernel.sh to create a bash script named updatekernel.sh in current folder and paste the code below before saved. Then it automatically set executable permission and run to update your Ubuntu kernel to the newest version.

KERNELVER="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/ | awk -F'\"v' '/v[4-9]./{print $2}' | cut -d/ -f1 | grep -v -  | sort -V | tail -1)"
SYSTYPE="$(dpkg --print-architecture)"
[ "$SYSTYPE" = "amd64" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/amd64.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "i386" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/i386.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "armhf" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/armhf.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "arm64" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/arm64.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "ppc64el" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/ppc64el.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "s390x" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/s390x.deb/{print $2}' | cut -d'<' -f1 | head -1)"
wget -t 3 -T 30 -nv -O "$KERNEL" "http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/${KERNEL}"
dpkg -i $KERNEL
rm -f $KERNEL
update-grub
apt-get autoremove -y

By default we use wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/ | awk -F'\"v' '/v[4-9]./{print $2}' | cut -d/ -f1 | grep -v - | sort -V | tail -1 to find the newest compiled kernel by Ubuntu official. The architecture supported by Ubuntu kernel official compiled are amd64, i386, armhf, arm64, ppc64el and s390x. For some specially use such as lowlatency required image or audio processing, replace the grep "generic" with grep "lowlatency".

Pay attention to the last line apt-get autoremove -y which means remove old or not used kernel, comment it with # at first character if you're not sure your system is bootable with the new kernel.

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