Slimming Raspberry Pi OS for a Pi 1 Model B

I had an original Raspberry Pi Model B in a drawer: 512 MB of RAM, a single 700 MHz ARMv6 core, Ethernet, no Wi-Fi, no Bluetooth. The job I had in mind for it was small: run an RTL-SDR dongle headless, around the clock, and record two radio channels to the SD card. It doesn’t need a desktop, a display, a camera, sound, or anyone typing at a console.

Raspberry Pi OS Lite (32-bit, Debian 13 “trixie”) still boots on it. But one image serves every Pi from the Zero to the 5, so out of the box it carries kernels for four CPU generations, firmware for half a dozen Wi-Fi chips, a camera stack with TensorFlow Lite in it, and a fair few services that wake up to look for hardware this board has never had. On a 700 MHz machine that’s boot time, RAM and SD card writes, and every one of those packages gets downloaded again at each upgrade.

So I slimmed it. The result is a script, run once after the first boot, and it’s in full at the end of this post. The rest is how the list in it was built, and the traps along the way.

A word on the timings. The Pi isn’t the only antique here: the SD card is a 16 GB SanDisk SDHC made in August 2009, and it’s probably as slow as you’d expect. A lot of the boot time, and how long the upgrades and purges took, is the card as much as the CPU. On a newer card your seconds will be different. The ones that come from the CPU (Perl starting up at every boot, NetworkManager’s start-up) should still be worth having.

The numbers

Fresh imageSlimmed
Packages640376
Root filesystem used2.1 GB957 MB
Memory the kernel sees426 MB474 MB
Memory available, idle326 MB376 MB
Kernel modules loaded31*12
Boot time (systemd-analyze)1 min 42 s*55 s

* I didn’t measure these on the fresh image. They’re from after the first pass, with the packages gone but NetworkManager, the swap file and the camera drivers still there.

Don’t guess, look

The tempting approach is a remove line of package names you’re fairly sure you don’t need. I started there, and it was mostly wrong. The better way is to boot the fresh card, ssh in, and ask it.

What’s running, and what will run later:

systemctl list-units --type=service --state=running
systemctl list-unit-files --state=enabled
systemctl list-timers --all
systemctl list-sockets
ps -eo pid,rss,comm --sort=-rss
ss -tulpn

Which package each process belongs to:

dpkg -S "$(readlink -f /proc/<pid>/exe)"

What the image chose to install, and what’s big:

apt-mark showmanual
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n

apt-mark showmanual is the useful one. Everything else on the card is there because something on that list depends on it, so that’s where to look for things to drop.

And then, before removing anything, a dry run of the whole lot:

apt-get -s purge --autoremove <the list>

-s simulates. It needs no root and changes nothing, and it prints every package that would go, including the ones you didn’t name. Read that output. It’s where every trap below showed up.

Let the first boot settle (cloud-init applies the Imager’s settings, then it’s done: cloud-init status says so) and reboot once before you measure anything.

What went

The fresh image ran these, by memory use:

ProcessRSSWhat it’s for here
NetworkManager16.5 MBEthernet with DHCP; replaced, see below
udisksd11.4 MBDesktop disk automounting
polkitd7.0 MBPermissions for udisks and NetworkManager
systemd-timesyncd6.5 MBTime; replaced by chrony
wpa_supplicant5.0 MBWi-Fi, on a board with no Wi-Fi
mpris-proxy2.9 MBBluetooth media controls, from bluez
cron2.6 MBNo jobs
two gettys4.7 MBLogins on HDMI and serial

And the space went on:

  • Wi-Fi and Bluetooth firmware, 244 MB: Atheros 120 MB, MediaTek 63 MB, Realtek 30 MB, Broadcom 20 MB, Libertas 12 MB. All for chips this board hasn’t got.
  • Kernels for other Pis, about 150 MB with the headers. The 32-bit image installs v6, v7 and v8 kernels (the v8 one as arm64, which also means an arm64 package list is downloaded at every update). A Pi 1 runs v6. Check with uname -r before you take any.
  • rpi-eeprom, 31 MB. Firmware updates for the Pi 4 and 5’s boot EEPROM. The Pi 1 has none.
  • rpi-connect-lite, 23 MB. Raspberry Pi’s remote access service.
  • mkvtoolnix, 23 MB, plus 36 MB of ICU for its Qt dependency. A video container tool on a Lite image; I’ve no idea why.
  • cloud-init and its Python libraries, about 30 MB of Babel locale data alone. It’s done its job after the first boot.
  • The camera stack (rpicam-apps, libcamera and TensorFlow Lite), v4l-utils, the GPIO Python libraries, udisks2, NTFS and CIFS support, gdb, and man pages.

The full list is in the script, grouped and commented. Purging it with autoremove takes about 245 packages and frees about 630 MB.

The traps

Each of these was found by the dry run or by the Pi, not by thinking about it.

gnupg has to stay. apt depends on raspbian-archive-keyring, which depends on gnupg. With gnupg on the list, apt refuses the whole removal: “pkgProblemResolver::Resolve generated breaks”. Fair enough.

rsync has to stay. I wanted it gone as a tool I didn’t use. The dry run quietly added raspi-firmware to the purge, which is the package that installs the bootloader files and kernel images. Remove that and the card doesn’t boot. raspi-firmware depends on rsync. To find which name on a long list causes a removal, simulate each one on its own:

for p in <list>; do
apt-get -s purge $p | grep -q '^Purg raspi-firmware' && echo "$p"
done

apt never autoremoves a kernel. Purging the linux-image-rpi-v7 metapackage leaves linux-image-6.18.50+rpt-rpi-v7 installed, deliberately. Then dpkg --remove-architecture arm64 fails, because the versioned v8 kernel is still an arm64 package. The script asks dpkg for every installed kernel, header and kbuild package that isn’t the v6 kernel, at the time it runs, so it keeps working after kernel updates.

The audio packages stay, oddly. I wanted ALSA gone: no sound on a headless recorder. But raspberrypi-sys-mods depends on raspi-config, which depends on alsa-utils. And sys-mods is worth keeping. It’s where Raspberry Pi OS keeps:

  • the journal in RAM rather than on the SD card;
  • the hardware watchdog switched on;
  • its udev rules (vcgencmd access, SD card trim, the CPU governor);
  • its sudo settings.

So ALSA stays, at 9 MB, running nothing, and the sound driver is blacklisted instead.

--no-install-recommends skips more than you’d think. It’s the right flag for a lean install, but it never skips a real dependency (Depends:), only Recommends:. Some of what you need is only recommended:

PackageRecommendsWithout it
cmakegcc, makecmake can’t build anything
gcclibc6-devNo stdio.h; the first #include fails
gitca-certificates, ssh-clienthttps clones fail on certificates; git@ remotes fail outright

build-essential depends on gcc, make and libc6-dev for real, so naming it gets them all. Git LFS downloads over https even from an ssh remote, so if you want LFS files you need ca-certificates too. I didn’t, so neither git-lfs nor ca-certificates is on my list.

Headless, properly

GPU memory. gpu_mem=16 in config.txt gives the ARM 496 MB instead of 448. The firmware then switches to its cut-down build, which has no camera or video codec services. Fine, but their kernel drivers still load and fail at every boot (“failed to open VCHI service”). So they’re blacklisted, and the display, camera and audio lines in config.txt are commented out:

blacklist bcm2835_codec
blacklist bcm2835_isp
blacklist bcm2835_v4l2
blacklist bcm2835_mmal_vchiq
blacklist vc_sm_cma
blacklist snd_bcm2835
blacklist drm

drm is loaded by name by modprobe@drm.service, which a blacklist doesn’t stop, so that unit is masked too.

The DVB-T driver. Linux has its own driver for these dongles, for watching TV, and it grabs the device before librtlsdr can. Blacklisting dvb_usb_rtl28xxu, rtl2832_sdr, rtl2832 and e4000 stops it. The modules are part of the kernel package, so they can’t be uninstalled; a blacklist is the way.

No consoles at all. I’ll never plug in a screen or a serial cable, so the script masks getty@tty1 and serial-getty@ttyAMA0, sets enable_uart=0, and removes the console= entries from cmdline.txt. That’s a commitment. From then on, ssh is the only way in, and if the network won’t come up the fix is to edit the SD card on another machine or re-image it.

Timers

systemctl list-timers on the fresh image, and what I did with each:

TimerWhat it doesVerdict
apt-daily, apt-daily-upgradeRefresh package lists and download updates, dailyMasked: I’ll upgrade when I choose to
man-db, logrotateRebuild the man index; rotate logsGone with their packages
e2scrub_allWeekly ext4 metadata check, LVM onlyMasked: no LVM, so it does nothing
dpkg-db-backupDaily copy of dpkg’s database to /var/backupsKept: it’s the recovery if a power cut spoils the database
fstrimWeekly: tells the SD card which blocks are freeKept: the card supports it, and it helps wear
systemd-tmpfiles-cleanClears out /tmp and friendsKept: part of systemd
rpi-zram-writebackSee swap, belowGone with the swap change

Swap: zram only

Raspberry Pi OS’s swap is cleverer than it looks. The swap device is zram0: a compressed block device in RAM. A page that’s swapped out is compressed with zstd and kept in memory, at about a third of its size. Behind that sits /var/swap, a file attached through a loop device as zram’s writeback device. Once a day a timer marks compressed pages that haven’t been touched and moves them out to the file, which frees the RAM they held.

The cost is at boot. rpi-resize-swap-file sizes the file to match RAM and re-runs mkswap on it every time, whether or not anything changed. It also starts Perl (via ack) to read a number out of /proc/meminfo. On this board that’s 25 seconds of every boot.

A recorder that runs for weeks doesn’t need idle pages paged out to a card it’s also trying not to wear out. So one drop-in file, /etc/rpi/swap.conf.d/50-zram-only.conf:

[Main]
Mechanism=zram

The zram size is still worked out from the RAM at each boot (by rpi-swap‘s generator), so it still follows a change to gpu_mem. There’s no file, no loop device, no writeback timer and no resize. Delete the drop-in and reboot to get the default back.

NetworkManager out, systemd-networkd in

NetworkManager took 32 seconds to start at every boot on this Pi, and it’s the biggest process left. For one Ethernet port on DHCP, systemd-networkd, which is already installed as part of systemd, needs one file, /etc/systemd/network/10-eth0.network:

[Match]
Name=eth0
[Network]
DHCP=yes
[DHCPv4]
ClientIdentifier=mac

ClientIdentifier=mac matters. By default networkd identifies itself to the DHCP server with a DUID, where NetworkManager’s built-in DHCP client uses the MAC address (as far as I can tell), so the router may hand out a different address after the switch. On a headless box with no console, that means hunting for it.

networkd doesn’t write /etc/resolv.conf by itself; that’s systemd-resolved’s job. Rather than run another daemon, the script keeps the DNS servers NetworkManager was given and writes them back as a fixed file once NetworkManager is gone.

The switch is the very last step before the reboot. NetworkManager leaves the interface configured when it stops, so the network (and the ssh session running the script) stays up until the reboot, and networkd takes over at boot. It came straight back at the same address, systemd-networkd started in 4 seconds, and the boot went from 1 min 42 s to 55 s.

One leftover: polkitd was still running, started because networkd asks systemd-hostnamed for the hostname at boot, and hostnamed asks polkit. Nothing depends on polkitd; it’s only there because systemd recommends it. It now goes with NetworkManager, and networkd and hostnamed carry on without it.

Smaller things

No man pages or docs, ever. A file in /etc/dpkg/dpkg.cfg.d/ stops dpkg installing them, for every package from then on, and the script deletes the ones already there (keeping the copyright files):

path-exclude /usr/share/man/*
path-exclude /usr/share/info/*
path-exclude /usr/share/doc/*
path-include /usr/share/doc/*/copyright

Write it before the upgrade, so the upgrade doesn’t put them back.

Order: remove, update, upgrade, install. Remove first, so the upgrade doesn’t download and unpack packages you’re about to delete. That’s a real saving on a 700 MHz CPU. Then update the lists, upgrade, and install last, against the current versions.

DEBIAN_FRONTEND=noninteractive and --force-confold. -y answers apt’s questions but not dpkg’s “keep your modified config file?”, which would stop an unattended upgrade dead.

Old logs and a trim. The script ends by deleting /var/log/*.log and the apt logs, running fstrim -a, and rebooting.

sudo’s cached password is shared. This one confused me. sudo worked over ssh with no password, then later didn’t, and I wrongly blamed the purge. Raspberry Pi OS sets timestamp_type=global (in /etc/sudoers.d/010_global-tty, from sys-mods), so once you’ve typed your password in one session, every session as that user can sudo until it times out. The script was fine. The cached login had simply run out.

Safe to run again

The script uses set -e, so any failure stops it rather than carrying on. It’s written so a second run changes nothing:

  • purging a package that’s already gone only prints a notice, and installing one that’s there does nothing;
  • systemctl mask and enable don’t mind being repeated;
  • the config files are rewritten whole, and the config.txt and cmdline.txt edits only match lines not yet changed;
  • the one step that would fail, removing the arm64 architecture when it’s already gone, is checked first.

The trap for later: a package name that’s no longer in the archive at all stops it with “Unable to locate package”. That’s why the kernel list is worked out when it runs rather than written down.

I ran it four times on the same card while building it, the last three over a Pi that had already been slimmed. It’s a script for a Pi 1 Model B on Ethernet, so check it against your own board before you borrow from it: the kernel names, the firmware and the Wi-Fi removal are all specific to this one.

The script

Run it with sudo bash setup-pi-trixie-v1.sh once the first boot has finished. It reboots at the end.

#!/bin/bash
set -e

if [ $(whoami) != root ] ; then
    echo "Must run using sudo"
    exit 1
fi

# RPi Imager
# Select OS: Raspberry Pi OS (other) ->
#     Raspberry Pi OS Lite (32-bit) Debian Trixie
# Set the hostname (sdr1), the username (sdr) and a password,
# and add your ssh public key.
# This is a RPi v1 Model B with 512MB RAM and 700MHz CPU;
# no WiFi or Bluetooth.
# Always headless: no HDMI, camera or audio. Wired Ethernet with DHCP.
# Run by hand after the first boot has finished
# (cloud-init status: done), with sudo.
# Safe to re-run. It reboots at the end.

export DEBIAN_FRONTEND=noninteractive

echo "---- No man pages or docs from now on ----"
cat > /etc/dpkg/dpkg.cfg.d/01-nodoc <<'EOF'
path-exclude /usr/share/man/*
path-exclude /usr/share/info/*
path-exclude /usr/share/doc/*
path-include /usr/share/doc/*/copyright
EOF

echo "---- Removing unwanted packages ----"
# Survey of the fresh image, 2026-11-21. Purging these with autoremove
# frees about 630 MB.
# Keep: gnupg (raspbian-archive-keyring, and so apt, needs it), rsync
# (raspi-firmware needs it), locales, htop, nano. Keep the audio
# packages (alsa-utils etc., 9 MB, nothing running):
# raspberrypi-sys-mods needs raspi-config, which needs alsa-utils, and
# sys-mods keeps the journal in RAM, enables the watchdog, and holds
# the sudoers and udev settings.
# Radio: no WiFi or Bluetooth on this board
PKG_REMOVE="modemmanager bluez bluez-firmware rfkill"
PKG_REMOVE="$PKG_REMOVE wpasupplicant wireless-tools"
PKG_REMOVE="$PKG_REMOVE firmware-atheros firmware-brcm80211"
PKG_REMOVE="$PKG_REMOVE firmware-libertas firmware-mediatek"
PKG_REMOVE="$PKG_REMOVE firmware-realtek"
# Kernels for other Pi models (this one runs rpi-v6), and kernel
# headers. Named one by one, versioned ones too, because apt never
# autoremoves a kernel.
PKG_REMOVE="$PKG_REMOVE $(dpkg-query -W \
    -f='${db:Status-Abbrev} ${binary:Package}\n' \
    'linux-image-*' 'linux-base-*' 'linux-headers-*' 'linux-kbuild-*' |
    awk '$1 == "ii" &&
         ($2 !~ /rpi-v6$/ || $2 ~ /^linux-(headers|kbuild)-/) {
             print $2
         }')"
# First-boot setup, finished by now
PKG_REMOVE="$PKG_REMOVE cloud-init rpi-cloud-init-mods userconf-pi"
PKG_REMOVE="$PKG_REMOVE libpam-chksshpwd"
# Remote access, file sharing and disks
PKG_REMOVE="$PKG_REMOVE rpi-connect-lite cifs-utils ntfs-3g udisks2"
PKG_REMOVE="$PKG_REMOVE p7zip-full zip unzip"
# Camera, video, display, keyboard and GPIO
PKG_REMOVE="$PKG_REMOVE mkvtoolnix v4l-utils rpicam-apps-lite"
PKG_REMOVE="$PKG_REMOVE kms++-utils fbset console-setup"
PKG_REMOVE="$PKG_REMOVE keyboard-configuration"
PKG_REMOVE="$PKG_REMOVE gpiod python3-gpiozero python3-libgpiod"
PKG_REMOVE="$PKG_REMOVE python3-rpi-lgpio python3-smbus2 python3-spidev"
PKG_REMOVE="$PKG_REMOVE rpi-keyboard-config rpi-keyboard-fw-update"
PKG_REMOVE="$PKG_REMOVE rpi-usb-gadget usb-modeswitch libmtp-runtime"
# Pi 4/5 only
PKG_REMOVE="$PKG_REMOVE rpi-eeprom rpifwcrypto rpi-update"
# Man pages
PKG_REMOVE="$PKG_REMOVE man-db manpages-dev groff-base"
# Tools and services we don't use (NetworkManager does its own DHCP)
PKG_REMOVE="$PKG_REMOVE apt-listchanges debconf-utils dmidecode"
PKG_REMOVE="$PKG_REMOVE pciutils lua5.1 luajit ssh-import-id"
PKG_REMOVE="$PKG_REMOVE isc-dhcp-client isc-dhcp-common logrotate"
PKG_REMOVE="$PKG_REMOVE cron cron-daemon-common gdb"
PKG_REMOVE="$PKG_REMOVE ncdu strace curl bash-completion"
PKG_REMOVE="$PKG_REMOVE vim-tiny vim-common net-tools traceroute"
# Development packages: removed here, and the ones we need are
# installed again below
PKG_REMOVE="$PKG_REMOVE build-essential pkg-config python3-venv"

apt-get -y purge $PKG_REMOVE
apt-get -y autoremove --purge

# The arm64 architecture was only there for the v8 kernel
# (checked, so the script can be re-run)
if dpkg --print-foreign-architectures | grep -qx arm64 ; then
    dpkg --remove-architecture arm64
fi

echo "---- Disabling unwanted timers and services ----"
# apt-daily*: background update downloads.
# e2scrub*: ext4 checks for LVM only.
# getty@tty1, serial-getty@ttyAMA0: logins on HDMI and on the serial
# port; ssh only.
systemctl mask apt-daily.timer apt-daily-upgrade.timer \
    e2scrub_all.timer e2scrub_reap.service
systemctl mask getty@tty1.service serial-getty@ttyAMA0.service

echo "---- Updating packages ----"
apt-get update
apt-get -y -o Dpkg::Options::=--force-confold full-upgrade

echo "---- Adding new packages ----"
# For running NAVTEX and RTL-SDR dongles
# (chrony replaces systemd-timesyncd)
PKG_INSTALL="rtl-sdr chrony"
# For development work
PKG_INSTALL="$PKG_INSTALL build-essential pkgconf cmake"
PKG_INSTALL="$PKG_INSTALL libusb-1.0-0-dev git"

apt-get install --no-install-recommends -y $PKG_INSTALL

echo "---- Removing man pages and docs already installed ----"
find /usr/share/man /usr/share/info -mindepth 1 -delete
find /usr/share/doc -mindepth 1 ! -type d ! -name copyright -delete
find /usr/share/doc -mindepth 1 -type d -empty -delete
apt-get clean

echo "---- Headless boot config ----"
# No display, camera or audio; give the GPU the minimum memory
CONFIG=/boot/firmware/config.txt
sed -i -E \
    -e 's/^(dtparam=audio=on|camera_auto_detect=)/#&/' \
    -e 's/^(display_auto_detect=|dtoverlay=vc4-kms-v3d)/#&/' \
    -e 's/^(max_framebuffers=|disable_fw_kms_setup=)/#&/' \
    $CONFIG
grep -q '^gpu_mem=' $CONFIG ||
    printf '\n[all]\ngpu_mem=16\n' >> $CONFIG
# Camera, video codec and sound drivers: with gpu_mem=16 the firmware
# has none of these services, so they only fail at boot. drm is loaded
# by name, so its loader is masked too.
cat > /etc/modprobe.d/blacklist-headless.conf <<'EOF'
blacklist bcm2835_codec
blacklist bcm2835_isp
blacklist bcm2835_v4l2
blacklist bcm2835_mmal_vchiq
blacklist vc_sm_cma
blacklist snd_bcm2835
blacklist drm
EOF
systemctl mask modprobe@drm.service
# Stop the kernel's DVB-T driver claiming the RTL-SDR dongle, so
# librtlsdr gets it without a detach and re-attach on every start. The
# modules are part of the kernel package, so they can't be uninstalled.
cat > /etc/modprobe.d/rtl-sdr-blacklist.conf <<'EOF'
blacklist dvb_usb_rtl28xxu
blacklist rtl2832_sdr
blacklist rtl2832
blacklist e4000
EOF
# No serial console, so turn the UART off
if grep -q '^enable_uart=' $CONFIG ; then
    sed -i 's/^enable_uart=.*/enable_uart=0/' $CONFIG
else
    printf '[all]\nenable_uart=0\n' >> $CONFIG
fi
# No kernel consoles either (serial or HDMI)
sed -i -E 's/ *console=[^ ]+//g; s/^ +//' /boot/firmware/cmdline.txt

echo "---- Swap in compressed RAM only ----"
# Swap is zram0, compressed swap in RAM. rpi-swap's default (zram+file)
# also attaches /var/swap through a loop device: a timer moves idle
# compressed pages out to it daily, and every boot resizes it and
# re-runs mkswap, about 25 s here. zram alone needs no file; its size
# is still worked out from the RAM at each boot, and nothing swaps to
# the SD card. This file overrides /etc/rpi/swap.conf; delete it and
# reboot to go back to the default, and /var/swap is recreated.
mkdir -p /etc/rpi/swap.conf.d
printf '[Main]\nMechanism=zram\n' \
    > /etc/rpi/swap.conf.d/50-zram-only.conf
# Still in use as zram's backing file until the reboot; the space is
# freed then
rm -f /var/swap

echo "---- Replacing NetworkManager with systemd-networkd ----"
# Done last, just before the reboot: NetworkManager leaves eth0
# configured when it stops, so the network stays up until then.
# networkd is part of systemd.
cat > /etc/systemd/network/10-eth0.network <<'EOF'
[Match]
Name=eth0

[Network]
DHCP=yes

[DHCPv4]
# Identify by MAC address, as NetworkManager did, so the router keeps
# the same address
ClientIdentifier=mac
EOF
systemctl enable systemd-networkd.service
# No resolver daemon: keep the DNS servers NetworkManager was given,
# as a fixed file
RESOLV="$(grep -E '^(search|nameserver)' /etc/resolv.conf || true)"
# polkitd too: kept only because systemd recommends it, and only
# started because networkd's hostname lookup (systemd-hostnamed)
# asks it
apt-get -y purge --autoremove network-manager polkitd
if [ -n "$RESOLV" ] ; then
    rm -f /etc/resolv.conf
    printf '%s\n' "$RESOLV" > /etc/resolv.conf
fi

echo "---- Removing old logs ----"
rm -f /var/log/*.log /var/log/apt/*

echo "---- Trimming the card ----"
sync
fstrim -a -v

echo "---- Done: rebooting ----"
reboot

Leave a Reply