Disable or remove unneeded services and software to help keep your Raspberry Pi online
Part of the Raspberry Pi Reliability series.
On long-running, single-purpose Raspberry Pis, I like to disable and/or remove some scheduled tasks, services, and other software. This may help with a few different reliability concerns:
- Removing or disabling software reduces wear on SD cards
- Running fewer services means fewer things can go wrong
- Removing unneeded software frees space on microSD cards, which are often small
The information in this post is, to the best of my knowledge, current as of November 2023. It should work on Raspberry Pi OS versions bullseye and bookworm, at least, but I make no promises.
These changes are not without risk, and you should only remove or disable something if you understand what removing it will do. (See my Pi Reliability post on risk vs. benefits.)
Disable rebuilding the manual pages index cache
The manual pages index cache (aka mandb
) is typically rebuilt daily and after updating or installing new software. This process is IO-bound and is slow, particularly on a Pi Zero, and it causes SD card wear.
After a Pi is up and running — and importantly, is unlikely to need maintenance for which I need to refer to up-to-date manpages — I disable this feature. To do so:
sudo rm /var/lib/man-db/auto-update
Disable daily software updates
On one occasion, the last log line before one of my Pi Zeros fell offline was Starting Daily apt upgrade and clean activities...
Automatic updates are generally a good thing! But on a long-running system, that’s firewalled off from the Internet, where reliability is a prime concern, you don’t want changes to happen without your involvement. Stability concerns aside, the process also causes some amount of SD card wear.
To disable this:
sudo systemctl mask apt-daily-upgrade
sudo systemctl mask apt-daily
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl disable apt-daily.timer
Disable avahi-daemon
Over the past year I’ve observed several instances of avahi-daemon
using 100% of a CPU on multiple Raspberry Pis and desktop Linux systems.
Luckily, I don’t need to use mDNS .local
domains to access these machines; I use custom local DNS entries configured on my home network’s Pi-Hole DNS server, and Tailscale’s MagicDNS also provides DNS for some of these machines.
If you don’t need a .local
domain for a given Pi, you can disable and remove avahi-daemon
via:
sudo apt remove --purge avahi-daemon
sudo apt autoremove --purge
Disable Bluetooth & ModemManager (if you don’t need them)
If you’re not using any 2G/3G/4G modems, I think it’s safe to remove ModemManager:
sudo apt remove --purge modemmanager
sudo apt autoremove --purge
If you don’t need Bluetooth, you can disable bluetooth.service
and hciuart.service
:
sudo systemctl disable bluetooth.service
sudo systemctl disable hciuart.service
If disabling Bluetooth, also add dtoverlay=disable-bt
to /boot/config.txt
; and you can remove some additional software:
sudo apt remove --purge bluez
sudo apt autoremove --purge
In a similar vein, for systems that only use wired Ethernet networking, you can disable wpa_supplicant.service
.
Find and disable other services you don’t need
You can see what’s running on your Pi via:
sudo systemctl --type=service --state=running
Disable running services you are certain you don’t need, via sudo systemctl disable name-of-service.service
.
Other unneeded software
Several other guides I’ve read on Pi reliability recommend removing the following. Obviously, don’t do this if you aren’t sure you don’t need these packages:
sudo apt remove --purge wolfram-engine triggerhappy xserver-common lightdm
sudo apt autoremove --purge
After upgrading a system from Raspberry Pi OS Stretch to Buster, the following packages are not needed and can be removed:
sudo apt purge timidity lxmusic gnome-disk-utility deluge-gtk evince wicd wicd-gtk clipit usermode gucharmap gnome-system-tools pavucontrol