Raspberry Pi Optimization (Hardware and Software)

Raspberry Pi Optimization (Hardware and Software)

I've seen a lot of optimisation tricks for Raspberry Pi on the internet, and I've done some of my own. I have been using Raspberry Pi since 2017 and I work on it every day.

These settings have been tested for at least a few months, so it's safe to use them.

This article doesn't contain any CPU overloading or MicroSD frequency boost trick. The reason is that I want to use my Raspberry Pi for a long time.

IMPORTANT! Do the following at your own risk, just because it works for me doesn't mean it will work for everyone (but most likely it will :) ). Always make a backup and your documentation to speed up a later installation - I have it too, so the fresh installation is ready in a tenth of the time. Restart Raspberry after each change to make it easier to find out if something has gone wrong. Let's get started!

Useful links:

Raspberry Pi OS (previously called Raspbian)
Install and Configure ruTorrent on Raspberry Pi
Install qBittorrent on Raspberry Pi
Install and Customize RPI-Monitor
Glances monitoring for Raspberry Pi (RPi-Monitor alternative)
Grafana Cloud for Raspberry Pi (RPi-Monitor alternative)
My Raspberry Pi Setup


Hardware Optimization

Raspberry Pi

Buy the latest version (minimal price difference, but the performance upgrade is huge between generations) from eBay or AliExpress.

The recommended memory size is 2GB, except if you want to run Virtual Machines or Docker on your Raspberry Pi.


Power Supply

Use quality power supply with at least 3A. The official version from eBay or AliExpress is perfectly fit for purpose, don't skimp on that. Instability/freezing/random restart can be the cause of a bad/weak power supply. Do not use a quick charger, as the Raspberry Pi is not compatible with it.


MicroSD Card

Do not apply below UHS-I (Class10). Buy greater than necessary, so one 32GB MicroSD from eBay or AliExpress will be fine. Why? On the one hand, because you will have enough free disk space, and on the other hand, the card will also last longer (it can use more space to write blocks). The system with applications takes approx. 3GB.

Do not download torrents or store the SWAP file on this!



Without it, do not use it more seriously. The Armor Case (eBay ; AliExpress) is the recommended cooling solution, especially the fanless version. The reason for this is that even with the version without active cooling, the temperature does not go above 63 degrees (I tested it several times with days of 100% CPU load at room temperature), which is perfectly fine, as the CPU only reduces the performance above 80 degrees (throttling).

Remark: I got some questions regarding the WiFi performance. The good news is this Armor Case doesn't affect to WiFi or Bluetooth range.


MicroUSB / Type C USB Cable

Take quality, for the same reasons as for the power supply. Cheap/doubtful cables may not carry the required current by the Raspberry. Do not buy longer cable than 1,5 meters (5 feet).

Buy on eBay or AliExpress



If you use an external HDD, you will need one (eBay ; AliExpress). USB3.0 cable with UASP support is recommended. Compared to USB2.0, a significant increase in speed (20 MB/s vs. 80 MB/s copy speed) is expected from it, as well as a much lower CPU load.


Software Optimization

Faster external HDD transfer speed

Apply this trick if you store not important data on your drive (I use my external HDD for torrenting - I can download them anytime). Some data may be lost on unexpected shutdown or power outages.

Edit the fstab file:
sudo nano /etc/fstab

Example - Original code:
UUID=f73e7c93-6ccd-d201-503e-7c736ccad201 /mnt/Torrent ext4 defaults 0 2

New code:
UUID=f73e7c93-6ccd-d201-503e-7c736ccad201 /mnt/Torrent ext4 defaults,noatime,nofail,data=writeback,commit=120 0 2

Increase VGA memory

Sometimes video playback fails (black screen/no sound). The common problem that the VGA memory is too small. You can change it by editing the config.txt file:

sudo nano /boot/config.txt

And set the "gpu_mem" value to 320. If it doesn't exist yet, add it to the end of file.



Do not turn on the TV when the Raspberry Pi restarting

Edit the "config.txt" file:

sudo nano /boot/config.txt

And set the "hdmi_ignore_cec_init" value to 1. If it doesn't exist yet, add it to the end of file.



Update eeprom

It can speed up the Raspberry Pi, reach lower temperatures, and get new features. Simply run this command:

sudo apt update ; sudo apt install -y rpi-eeprom


Turn off SWAP

In most cases, it's unnecessary. Turn it off by running this command:

sudo dphys-swapfile swapoff ; sudo dphys-swapfile uninstall ; sudo update-rc.d dphys-swapfile remove ; sudo apt purge dphys-swapfile -y

If you want to use swap, DO NOT use MicroSD card to store it.


Turn off WiFi and Bluetooth

If you don't use WiFi or Bluetooth, turn them off. It will save ~200MB of memory, and the Raspberry will uses less power.

Edit the "config.txt" file:
sudo nano /boot/config.txt

Add these lines to the end of file:

Turn off and remove related redundant services:
systemctl disable wpa_supplicant bluetooth hciuart rpi-display-backlight && apt purge pi-bluetooth wpasupplicant

Okay, now disable the related kernel modules. Edit "raspi-blacklist.conf" file:
sudo nano /etc/modprobe.d/raspi-blacklist.conf

Add these lines to this file:
blacklist bluetooth
blacklist ecdh_generic
blacklist rfcomm
blacklist rfkill
blacklist cfg80211

Reboot your Raspberry Pi to apply these changes.
sudo reboot


Use Ramdisk for /tmp

This trick is helpful to extend the SD Card life. To activate, simply run these below commands:

sudo cp /usr/share/systemd/tmp.mount /etc/systemd/system/tmp.mount
sudo systemctl enable tmp.mount
sudo systemctl start tmp.mount

You can verify it by run df command.


Remove unnecessary files

If you are running out of disk space, run these commands:

echo "" > /home/pi/dead.letter
sudo apt -y autoremove && sudo apt -y clean && apt -y autoclean
sudo rm -f /opt/vc/src/hello_pi/hello_video/test.h264


Disable unnecessary services

There are some useless services in Raspbian by default. They are generating a lot of log lines, and use resource without any benefit. Let's disable and remove them.

sudo apt-get autoremove --purge sysstat

systemctl disable avahi-daemon triggerhappy rng-tools packagekit
systemctl stop avahi-daemon triggerhappy rng-tools packagekit
apt purge avahi-daemon triggerhappy rng-tools packagekit

sudo systemctl disable apt-daily.service
sudo systemctl disable apt-daily.timer
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl disable apt-daily-upgrade.service


Disable IPv6

If you're not using it, it's unnecessary to have it on. Disable IPv6 with the following commands:

echo -e ‘noipv6rs\nnoipv6’ > /etc/dhcpcd.conf
systemctl restart dhcpcd


Get 5% extra space when using LVM

I have already written an article on this, in more detail here



The installation guide is available here

Disable unnecessary logs:
sudo a2disconf other-vhosts-access-log && sudo systemctl reload apache2

Disable unnecessary modules:
sudo a2dismod proxy_http && sudo a2dismod proxy && sudo a2dismod status && sudo systemctl restart apache2

Fix cpuload graph by edit init.js file:
sudo nano -c /var/www/rutorrent/plugins/cpuload/init.js

Replace "min: 0" to "max: 100" near to "yaxis" - Found in 56th line at this moment.

Force delete folder if the .torrent file has been removed:

Add this below line to ".rtorrent.rc" file:
method.set_key = event.download.erased,delete_erased,"execute=rm,-rf,--,$d.base_path="

If you did it, disable the "erasedata" plugin, it's useless anymore.

Restart the rTorrent and Apache if you changed anything:
sudo systemctl restart rtorrent apache2

Remove torrent files (if you are running out of disk space):
sudo rm -rf /var/www/rutorrent/share/users/torrent/torrents/*.torrent


If you have a question, leave a comment below.