Raspberry Pi Optimization (Hardware and Software)

Raspberry Pi Optimization (Hardware and Software)

I saw a lot of optimization tricks on the Internet for Raspberry Pi, and I made some by myself as well. I use Raspberry Pi since 2017, and I work on it every day.

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

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

IMPORTANT! Everyone modifies the following at their own risk, just because it works flawlessly for me doesn’t mean everyone does (but most likely yes :) ). 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 and Customize RPI-Monitor
My Raspberry Pi Setup


Hardware Optimization

Raspberry Pi

Buy the latest version (minimal price difference, but the performance upgrade is huge between generations) from Amazon, they offer an original version. The reason is sellers on eBay or Aliexpress can offer a fake Raspberry Pi (not all of them, but possible).

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 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 this 32GB MicroSD 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 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).



If you use an external HDD, you will need one. 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,barrier=0,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 use 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:

sudo systemctl disable wpa_supplicant bluetooth hciuart rpi-display-backlight && sudo apt remove pi-bluetooth

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

Reboot your Raspberry Pi to apply these changes.


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



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 set it, feel free to disable "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.