Skip to content

Instantly share code, notes, and snippets.

@Jamesits
Last active December 13, 2022 22:27
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save Jamesits/3d6da2d711bd95c53ccd953f99aee748 to your computer and use it in GitHub Desktop.
Save Jamesits/3d6da2d711bd95c53ccd953f99aee748 to your computer and use it in GitHub Desktop.
Ubuntu enable BBR
#!/bin/bash
set -eu
SYSCTL_FILE=/etc/sysctl.d/90-tcp-bbr.conf
# check root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# check OS version
source /etc/lsb-release
KERNEL_VERSION=$(uname -r)
if [ "$DISTRIB_ID" != "Ubuntu" ]; then
echo "This script must be run under Ubuntu"
exit 1
fi
# install newest kernel
if [ "$DISTRIB_RELEASE" == "16.04" ]; then
apt-get update -y
apt-get install -y --install-recommends linux-generic-hwe-16.04
apt-get autoremove -y
elif [ "$DISTRIB_RELEASE" == "18.04" ]; then
echo "Kernel version enough, no need to install anything"
else
# check kernel version
if dpkg --compare-versions "$KERNEL_VERSION" "ge" "4.9"; then
echo "WARNING: Non-LTS versions are not supported. Continuing since you have a compatible kernel."
else
echo "ERROR: Kernel auto install on Non-LTS versions is not supported. Please manually install kernel >= 4.9."
exit 1
fi
fi
if grep -q "tcp_bbr" "/etc/modules-load.d/modules.conf"; then
echo "tcp_bbr" >> /etc/modules-load.d/modules.conf
fi
echo "Current configuration: "
sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control
# apply new config
if ! grep -q "net.core.default_qdisc=fq" "$SYSCTL_FILE"; then
echo "net.core.default_qdisc=fq" >> $SYSCTL_FILE
fi
if ! grep -q "net.ipv4.tcp_congestion_control=bbr" "$SYSCTL_FILE"; then
echo "net.ipv4.tcp_congestion_control=bbr" >> $SYSCTL_FILE
fi
# check if we can apply the config now
if lsmod | grep -q "tcp_bbr"; then
sysctl -p $SYSCTL_FILE
echo "BBR is available now."
elif modprobe tcp_bbr; then
sysctl -p $SYSCTL_FILE
echo "BBR is available now."
else
echo "Please reboot to enable BBR."
fi
@windsting
Copy link

windsting commented Mar 23, 2019

There is a typo character (the Unicode U+FF01-- Fullwidth Exclamation Mark) in line 16:

if [ "$DISTRIB_ID" != "Ubuntu" ]; then

maybe you should fix it.

@Jamesits
Copy link
Author

There is a typo character (the Unicode U+FF01-- Fullwidth Exclamation Mark) in line 16:

if [ "$DISTRIB_ID" != "Ubuntu" ]; then

maybe you should fix it.

Fixed. Thanks for reporting.

@Nottt
Copy link

Nottt commented May 16, 2019

For Ubuntu 14.04, after installing your kernel and rebooting sysctl net.ipv4.tcp_available_congestion_control does not report bbr as available with kernel 4.4.0-148-generic

@Jamesits
Copy link
Author

@Nottt 4.4.0 is not compiled with BBR support, and I guess either the kernel is not installed, or there is something wrong with the bootloader. Can you provide me some information?

  • The output of systemd-detect-virt
  • The output of apt list --installed | grep "linux"
  • What bootloader are you using?

@Nottt
Copy link

Nottt commented May 16, 2019

I don't know, it's a rented server.

systemd-detect-virt = command not found I think Ubuntu 14.04 does not have systemd at all

The other command I think I messed up by trying to install many kernels manually and running into dependencies issues but here it is:

apt list --installed | grep "linux"

libselinux1/trusty-updates,trusty-updates,now 2.2.2-1ubuntu0.1 amd64 [installed]
linux-base/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,now 4.5ubuntu1~14.04.1 all [installed,automatic]
linux-firmware/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,now 1.127.24 all [installed]
linux-generic-lts-xenial/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0.148.130 amd64 [installed]
linux-headers-4.19.43-041943/now 4.19.43-041943.201905141927 all [installed,local]
linux-headers-4.4.0-148/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0-148.174~14.04.1 all [installed,automatic]
linux-headers-4.4.0-148-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0-148.174~14.04.1 amd64 [installed,automatic]
linux-headers-5.1.2-050102/now 5.1.2-050102.201905141830 all [installed,local]
linux-headers-generic-lts-xenial/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0.148.130 amd64 [installed,automatic]
linux-image-4.2.0-42-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,now 4.2.0-42.49~14.04.1 amd64 [installed,automatic]
linux-image-4.4.0-148-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0-148.174~14.04.1 amd64 [installed,automatic]
linux-image-extra-4.2.0-42-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,now 4.2.0-42.49~14.04.1 amd64 [installed,automatic]
linux-image-generic-lts-wily/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,now 4.2.0.42.34 amd64 [installed]
linux-image-generic-lts-xenial/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0.148.130 amd64 [installed,automatic]
linux-libc-dev/now 3.13.0-169.219 amd64 [installed,upgradable to: 3.13.0-170.220]
linux-modules-4.19.43-041943-generic/now 4.19.43-041943.201905141927 amd64 [installed,local]
linux-modules-4.4.0-148-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0-148.174~14.04.1 amd64 [installed,automatic]
linux-modules-5.1.2-050102-generic/now 5.1.2-050102.201905141830 amd64 [installed,local]
linux-modules-extra-4.4.0-148-generic/trusty-updates,trusty-security,trusty-updates,trusty-security,trusty-security,trusty-proposed,now 4.4.0-148.174~14.04.1 amd64 [installed,automatic]
util-linux/trusty-updates,trusty-updates,now 2.20.1-5.1ubuntu20.9 amd64 [installed]

I'm using GRUB as the bootloader. But the kernel apt-get install -y --install-recommends linux-generic-lts-xenial installs is 4.4.0-148-generic

@Jamesits
Copy link
Author

@Nottt I'm sorry, 14.04 have no official supported kernel 4.4+. So there will be no official BBR support too. I've removed 12.04 and 14.04 support in the script.

@Nottt
Copy link

Nottt commented May 17, 2019

No problem! I was just curious if I was doing something wrong, and it seems if you are stuck with 14.04 you are out of luck with BBR since installing the kernel manually is not easy to fix either.

Thanks 👍

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