Last active
March 17, 2020 08:37
-
-
Save assafmo/15814a044ddb75c093adf628c51c0d50 to your computer and use it in GitHub Desktop.
Setup a new ubuntu machine for performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
## | |
# CPU scaling_governor=performance | |
## | |
printf 'Setting scaling_governor to performance... ' | |
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor > /dev/null | |
if ! (sudo crontab -l | grep -Fq 'echo performance | tee' > /dev/null) ; then | |
( | |
sudo crontab -l | |
echo '* * * * * /bin/bash -c "echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor"' | |
) | sudo crontab - | |
fi | |
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | awk '$1!="performance"{exit 1}' && echo 'OK.' || echo 'ERROR.' | |
## | |
# Install preload | |
## | |
printf 'Installing preload... ' | |
sudo apt install -y preload &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Install rng-tools & haveged | |
## | |
printf 'Installing rng-tools & haveged... ' | |
sudo apt install -y haveged rng-tools &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Fix gnome-calculator | |
## | |
printf 'Fixing calculator app... ' | |
(sudo snap remove gnome-calculator && sudo apt install -y gnome-calculator) &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Mount root filesystem with noatime | |
## | |
printf 'Setting root filesystem with noatime mount option... ' | |
awk '$2=="/"{if($4~/noatime/){print}else{$4=$4",noatime"; print}} $2!="/"{print}' /etc/fstab > /tmp/fstab | |
sudo mv -f /tmp/fstab /etc/fstab | |
awk '$2=="/"{if(!($4~/noatime/)){exit 1}}' /etc/fstab && echo 'OK.' || echo 'ERROR.' | |
## | |
# Mount /tmp as tmpfs | |
## | |
printf 'Setting /tmp to be a tmpfs filesystem... ' | |
awk 'BEGIN{done=0} $2=="/tmp"{print; done=1} $2!="/tmp"{print} END{if(done==0){print "tmpfs /tmp tmpfs rw,nosuid,nodev 0 0"}}' /etc/fstab > /tmp/fstab | |
sudo mv -f /tmp/fstab /etc/fstab | |
awk '$2=="/tmp"{if(!($1~/tmpfs/)){exit 1}}' /etc/fstab && echo 'OK.' || echo 'ERROR.' | |
## | |
# BBR algorithm for TCP congestion control | |
## | |
printf 'Setting TCP congestion control to BBR... ' | |
if ! (sysctl 'net.core.default_qdisc' | grep -q 'fq' && sysctl 'net.ipv4.tcp_congestion_control' | grep -q 'bbr') ; then | |
echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf > /dev/null | |
echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf > /dev/null | |
sudo sysctl -p > /dev/null | |
fi | |
sysctl 'net.core.default_qdisc' | grep -q 'fq' && sysctl 'net.ipv4.tcp_congestion_control' | grep -q 'bbr' && echo 'OK.' || echo 'ERROR.' | |
## | |
# Lowering swappiness | |
## | |
printf 'Lowering swappiness... ' | |
if ! (sysctl 'vm.swappiness' | grep -q '10') ; then | |
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf > /dev/null | |
sudo sysctl -p > /dev/null | |
fi | |
sysctl 'vm.swappiness' | grep -q '10' && echo 'OK.' || echo 'ERROR.' | |
## | |
# GNOME animations | |
## | |
printf 'Disabling GNOME animations... ' | |
gsettings set org.gnome.desktop.interface enable-animations false | |
gsettings get org.gnome.desktop.interface enable-animations | grep -q false && echo 'OK.' || echo 'ERROR.' | |
## | |
# GNOME external search providors | |
## | |
printf 'Disabling GNOME external search providors... ' | |
gsettings set org.gnome.desktop.search-providers disable-external true | |
gsettings get org.gnome.desktop.search-providers disable-external | grep -q true && echo 'OK.' || echo 'ERROR.' | |
echo | |
echo 'Done. Please reboot for all changes to take effect.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
## | |
# Better power management for laptops | |
## | |
printf 'Installing tlp... ' | |
sudo apt install -y tlp &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Install preload | |
## | |
printf 'Installing preload... ' | |
sudo apt install -y preload &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Install rng-tools & haveged | |
## | |
printf 'Installing rng-tools & haveged... ' | |
sudo apt install -y haveged rng-tools &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Fix gnome-calculator | |
## | |
printf 'Fixing calculator app... ' | |
(sudo snap remove gnome-calculator && sudo apt install -y gnome-calculator) &> /dev/null && echo 'OK.' || echo 'ERROR.' | |
## | |
# Mount root filesystem with noatime | |
## | |
printf 'Setting root filesystem with noatime mount option... ' | |
awk '$2=="/"{if($4~/noatime/){print}else{$4=$4",noatime"; print}} $2!="/"{print}' /etc/fstab > /tmp/fstab | |
sudo mv -f /tmp/fstab /etc/fstab | |
awk '$2=="/"{if(!($4~/noatime/)){exit 1}}' /etc/fstab && echo 'OK.' || echo 'ERROR.' | |
## | |
# Mount /tmp as tmpfs | |
## | |
printf 'Setting /tmp to be a tmpfs filesystem... ' | |
awk 'BEGIN{done=0} $2=="/tmp"{print; done=1} $2!="/tmp"{print} END{if(done==0){print "tmpfs /tmp tmpfs rw,nosuid,nodev 0 0"}}' /etc/fstab > /tmp/fstab | |
sudo mv -f /tmp/fstab /etc/fstab | |
awk '$2=="/tmp"{if(!($1~/tmpfs/)){exit 1}}' /etc/fstab && echo 'OK.' || echo 'ERROR.' | |
## | |
# BBR algorithm for TCP congestion control | |
## | |
printf 'Setting TCP congestion control to BBR... ' | |
if ! (sysctl 'net.core.default_qdisc' | grep -q 'fq' && sysctl 'net.ipv4.tcp_congestion_control' | grep -q 'bbr') ; then | |
echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf > /dev/null | |
echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf > /dev/null | |
sudo sysctl -p > /dev/null | |
fi | |
sysctl 'net.core.default_qdisc' | grep -q 'fq' && sysctl 'net.ipv4.tcp_congestion_control' | grep -q 'bbr' && echo 'OK.' || echo 'ERROR.' | |
## | |
# Lowering swappiness | |
## | |
printf 'Lowering swappiness... ' | |
if ! (sysctl 'vm.swappiness' | grep -q '10') ; then | |
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf > /dev/null | |
sudo sysctl -p > /dev/null | |
fi | |
sysctl 'vm.swappiness' | grep -q '10' && echo 'OK.' || echo 'ERROR.' | |
## | |
# GNOME animations | |
## | |
printf 'Disabling GNOME animations... ' | |
gsettings set org.gnome.desktop.interface enable-animations false | |
gsettings get org.gnome.desktop.interface enable-animations | grep -q false && echo 'OK.' || echo 'ERROR.' | |
## | |
# GNOME external search providors | |
## | |
printf 'Disabling GNOME external search providors... ' | |
gsettings set org.gnome.desktop.search-providers disable-external true | |
gsettings get org.gnome.desktop.search-providers disable-external | grep -q true && echo 'OK.' || echo 'ERROR.' | |
echo | |
echo 'Done. Please reboot for all changes to take effect.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute:
curl -SsL https://gist.githubusercontent.com/assafmo/15814a044ddb75c093adf628c51c0d50/raw/setup.sh | bash
For laptops:
curl -SsL https://gist.githubusercontent.com/assafmo/15814a044ddb75c093adf628c51c0d50/raw/setup_laptop.sh | bash