Imran Khan
← Back to blog
Raspberry Pi OS Trixie: OverlayFS with Persistent USB Storage
raspberry-pilinuxoverlayfsstorageself-hosting

Raspberry Pi OS Trixie: OverlayFS with Persistent USB Storage

By ··15m read

Untested reference configuration for Raspberry Pi OS Trixie OverlayFS with persistent USB storage, boot protection, mount checks and recovery steps.

Raspberry Pi OS Trixie can use OverlayFS to reduce writes to the operating system while keeping application data on a separately mounted USB drive. Protect the root and boot filesystems, put temporary changes in RAM, and deliberately keep the external data mount writable.

Status: untested reference configuration. I reviewed the Trixie source and documentation on 16 November 2026, but have not run the complete setup on a Raspberry Pi. Ordinary reboots, missing-drive behavior, writable maintenance and power-cut recovery all remain to be tested on hardware. The checks below define what to verify before relying on this configuration.

The useful separation is between recovering the OS and retaining the application’s records. The external drive still experiences the power cut, so making the OS read-only does not guarantee that the latest saved reading survives.

There is also a less obvious trap: Trixie’s default overlayroot configuration can make writes to an external ext4 filesystem listed in /etc/fstab temporary too. A logger can report a successful save and still lose that file after reboot. Avoiding that behavior is the reason for the root-only overlay setting in this reference.

How OverlayFS makes the root filesystem disposable

OverlayFS combines a lower filesystem with an upper filesystem and presents a merged view. In this Raspberry Pi configuration, the original ext4 root is mounted read-only and a tmpfs upper layer holds changes. Applications still see a writable /, but writes to that overlay disappear when it is recreated at boot. OverlayFS itself also supports other arrangements; volatility comes from choosing a RAM-backed upper layer. See the Linux kernel’s OverlayFS documentation.

For an appliance, split storage by what must survive:

StorageRoleRequired behavior
OS root on the microSD cardPackages and baseline configurationRead-only lower filesystem
RAM overlayDisposable runtime changesWritable, discarded at reboot
Boot partitionFirmware, kernel and boot configurationRead-only during normal operation
External ext4 filesystem at /srv/dataApplication records and selected stateWritable, persistent across reboot
A storage appliance separates its protected OS cassette, temporary working tray and persistent external data cartridge.
A conceptual appliance: the sealed cassette holds the OS baseline, the working tray represents temporary writes, and the separate cartridge holds persistent data.

Boot protection needs its own setting. Raspberry Pi documents the root overlay and write-protected boot partition as two separate controls. Enabling only the root overlay leaves an important part of the boot path outside that protection.

Before enabling OverlayFS in Raspberry Pi OS

Start while the machine is running its ordinary, writable root filesystem. Finish application installation, networking, SSH access and storage configuration before making that baseline disposable.

This walkthrough assumes:

  • Raspberry Pi OS Trixie with /boot/firmware, the default cmdline.txt command-line file, and a separately prepared ext4 data partition.
  • An already installed, systemd-managed application, with a known service account and a tested backup/restore procedure.
  • Application-specific instructions for selecting its data directory. This article configures storage and startup dependencies; it does not install a logger or migrate a database for you.

The example name pi-logger.service stands for that existing service. Substitute your actual unit name throughout. Before enabling the overlay, its persistent state must already be configured under /srv/data, and its service account must be able to use that directory.

Run the commands in Bash on the Raspberry Pi. Record the actual system:

cat /etc/os-release
uname -r
dpkg-query -W raspi-config
lsblk -o NAME,TRAN,FSTYPE,UUID,SIZE,MOUNTPOINTS
findmnt --mountpoint / --output TARGET,SOURCE,FSTYPE,OPTIONS
swapon --show

Debian Trixie supplies overlayroot 0.18.debian14; record the version actually installed on your Pi after enabling it. Older Raspberry Pi OS images can use a different overlay implementation, so do not transplant boot arguments into them without checking.

Back up the existing system and application data, and retain a way to edit the boot partition from another computer if the device stops booting. Formatting a drive is outside this walkthrough: use an identified, backed-up ext4 data partition rather than guessing which /dev/sdX device is safe to erase.

Also inspect swap. tmpfs pages can be swapped to storage, so a RAM overlay does not by itself establish that the microSD card receives no writes. Resolve disk-backed swap on the protected medium before relying on that property. RAM capacity must accommodate the application and its temporary writes; a large download or growing cache can exhaust the overlay’s available space. Raspberry Pi discusses these limits in its filesystem resilience whitepaper.

Mount the external drive by UUID

Use a stable mount point and filesystem UUID. Device names such as /dev/sda1 can change when another USB storage device is connected.

sudo mkdir -p /srv/data
sudo nano /etc/fstab

Add an entry like this, replacing REPLACE_WITH_EXT4_UUID with the data partition’s actual filesystem UUID from lsblk:

UUID=REPLACE_WITH_EXT4_UUID /srv/data ext4 defaults,nofail,x-systemd.device-timeout=10s 0 2

Here, nofail allows the OS to continue booting if this drive is absent, and the device timeout bounds how long its device is awaited. That makes sense only when applications also refuse to run without their storage. These options are documented in the Trixie systemd mount manual.

Load the updated configuration, mount this filesystem and inspect it:

sudo systemctl daemon-reload
sudo mount /srv/data
findmnt --mountpoint /srv/data --output TARGET,SOURCE,FSTYPE,OPTIONS
lsblk -o NAME,FSTYPE,UUID,MOUNTPOINTS

Confirm that /srv/data is the intended external partition, its type is ext4, and its options include rw. Match its source device to the UUID you selected.

Use findmnt --mountpoint for this check. findmnt --target /srv/data can return the filesystem containing the directory even when no drive is mounted there. Seeing the root filesystem would explain where fallback writes go, but would not prove the external mount exists. The distinction is explicit in the findmnt manual.

Put the application’s actual state on the drive

Stop the application before migrating its data. For example, a logger could keep its measurements database and associated recovery files in /srv/data/logger. Create that subdirectory on the mounted drive with ownership and permissions appropriate to the logger’s existing service account, then follow the application’s supported migration procedure.

Restart the service while the root is still writable. Save a synthetic reading, restart the service again, and check that it reads the same record from the external drive. If that fails, resolve the application’s data-path or permission problem before adding OverlayFS.

Moving an export file is insufficient if the real database remains under /var/lib. Keep persistent records on the data drive and install the application’s baseline settings on the OS root during provisioning. An edit to a configuration file in /etc while the overlay is active will disappear after reboot; save permanent changes during a writable maintenance boot.

If the application runs in Docker

A named volume survives container replacement, but its host filesystem still matters. Inspect application bind mounts and Docker’s storage locations before protecting the host root.

Fresh Docker Engine 29.0+ installations default to the containerd image store: image contents and container snapshots normally live under /var/lib/containerd, while volumes and other daemon data remain under /var/lib/docker. Changing Docker’s data-root does not move containerd storage. Upgraded installations can retain the classic backend. Check the daemon data-directory documentation against your installation.

Prevent the service from starting without its data mount

An empty /srv/data directory still exists when its external drive is missing. An application that starts anyway can create a fresh database there, appear healthy, and lose those changes on the next reboot.

Add a drop-in to the application’s existing systemd service:

sudo systemctl edit pi-logger.service

Use this drop-in for the ext4 layout above:

[Unit]
RequiresMountsFor=/srv/data
AssertPathIsMountPoint=/srv/data

[Service]
ExecStartPre=/usr/bin/findmnt --noheadings --mountpoint /srv/data --types ext4 --options rw --output TARGET

RequiresMountsFor= adds the mount requirement and ordering. The assertion rejects a plain directory, and the pre-start command requires a writable ext4 mount, rejecting a temporary overlay filesystem at that location. These are documented systemd unit dependencies and assertions combined with findmnt filters.

This is a startup guard. It does not monitor disk health, guarantee application durability or implement recovery after a live USB disconnection. The UUID-based mount configuration selects the device; the pre-start filter checks its mount type and write status. Adapt it if you intentionally choose a filesystem other than ext4.

For Docker workloads, ensure the mount requirement covers the mechanism that actually starts the containers: Docker restart policies can start them independently of a systemd unit used to launch Compose.

sudo systemctl daemon-reload
sudo systemctl restart pi-logger.service
systemctl status pi-logger.service

Do this before protecting the root so the service configuration becomes part of the persistent baseline.

Enable OverlayFS without making external storage temporary

The Raspberry Pi configuration tool’s Trixie implementation enables the Debian overlayroot package with the boot argument overlayroot=tmpfs.

The important default is recursion. With recurse=1, Trixie’s overlayroot rewrites eligible mounts in /etc/fstab, including the external ext4 mount in this example. It does not automatically overlay every drive attached later; FAT and certain virtual filesystem entries are excluded. See the versioned mount-handling implementation.

recurse=0 restricts the overlay to the root. Kernel command-line settings take precedence over configuration files, so changing only /etc/overlayroot.conf can leave the boot argument in control. See the overlayroot configuration reference.

For this design, the intended single argument is:

overlayroot=tmpfs:recurse=0

Other separately mounted filesystems now need their own intentional policy. The data mount should remain writable; the boot mount should be protected explicitly.

Initial setup

  1. Run sudo raspi-config on the still-writable system.
  2. Open Performance Options → Overlay File System. Use the option names rather than assuming menu numbers match another release.
  3. Enable the overlay and write-protect the boot partition.
  4. Finish, but decline the immediate reboot so you can adjust the boot argument first.

Make the boot partition writable if needed and open its command line:

sudo mount -o remount,rw /boot/firmware
sudo nano /boot/firmware/cmdline.txt

Replace the existing overlayroot=tmpfs argument with overlayroot=tmpfs:recurse=0. Keep every other argument intact, preserve the file as one line, and leave exactly one overlayroot= argument. The snippet above is one argument, not a replacement for the whole file.

sync
sudo mount -o remount,ro /boot/firmware
sudo reboot

After this customization, use the maintenance procedure below to switch modes. Do not assume the configuration tool will remove a parameter you have extended manually.

Verify the real mounts and reboot persistence

After reboot, inspect the kernel arguments and each storage role:

cat /proc/cmdline
dpkg-query -W raspi-config overlayroot
findmnt --mountpoint / --output TARGET,SOURCE,FSTYPE,OPTIONS
findmnt --mountpoint /media/root-ro --output TARGET,SOURCE,FSTYPE,OPTIONS
findmnt --mountpoint /media/root-rw --output TARGET,SOURCE,FSTYPE,OPTIONS
findmnt --mountpoint /boot/firmware --output TARGET,SOURCE,FSTYPE,OPTIONS
findmnt --mountpoint /srv/data --output TARGET,SOURCE,FSTYPE,OPTIONS

For the documented overlayroot layout, check these properties rather than expecting a particular device name:

MountAcceptance condition
/Writable overlay view
/media/root-roOriginal ext4 root, read-only
/media/root-rwtmpfs backing the temporary upper layer
/boot/firmwareBoot filesystem, read-only
/srv/dataIntended external ext4 filesystem, writable

The /media/root-* paths and runtime mount handling come from the overlayroot implementation. If your installed layout differs, resolve that difference before treating these checks as satisfied.

Check persistence with an orderly reboot

Use a new run ID for every test, including after maintenance. The ID appears in both marker filenames and their contents, so an old file on the underlying drive cannot satisfy a later test. Linux’s random UUID interface generates a new UUID when read.

Prepare both markers. This block stops on either failed write and checks their contents before reporting success:

(
  set -euo pipefail
  run_id=$(cat /proc/sys/kernel/random/uuid)
  root_marker="/etc/overlayfs-proof-${run_id}.txt"
  data_marker="/srv/data/overlayfs-proof-${run_id}.txt"

  if [ -e "$root_marker" ] || [ -e "$data_marker" ]; then
    printf 'FAIL: marker already exists; start a new run.\n' >&2
    exit 1
  fi
  if ! printf '%s\n' "$run_id" | sudo tee "$root_marker" >/dev/null; then
    printf 'FAIL: root marker write failed; do not reboot.\n' >&2
    exit 1
  fi
  if ! printf '%s\n' "$run_id" | sudo tee "$data_marker" >/dev/null; then
    printf 'FAIL: external marker write failed; do not reboot.\n' >&2
    exit 1
  fi
  if ! root_value=$(sudo cat "$root_marker") ||
     ! data_value=$(sudo cat "$data_marker"); then
    printf 'FAIL: marker read failed; do not reboot.\n' >&2
    exit 1
  fi
  if [ "$root_value" != "$run_id" ] || [ "$data_value" != "$run_id" ]; then
    printf 'FAIL: marker readback failed; do not reboot.\n' >&2
    exit 1
  fi
  sync
  printf 'READY: both markers were written and checked.\n'
  printf 'Run ID: %s\nRoot marker: %s\nData marker: %s\nExpected content: %s\n' \
    "$run_id" "$root_marker" "$data_marker" "$run_id"
)

Save the printed run ID, paths and expected content outside the Pi before rebooting: for example, in a saved SSH terminal transcript on your other computer, or on paper. A copy stored only in the root overlay or the data filesystem under test is insufficient. If preparation fails or no READY line appears, stop here and resolve the error.

After saving that record:

sudo reboot

After reconnecting, replace the placeholder below with the same saved run ID. Do not generate a new ID for verification:

(
  set -euo pipefail
  run_id='PASTE_SAVED_RUN_ID_HERE'
  if ! [[ "$run_id" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]]; then
    printf 'FAIL: paste the run ID saved before reboot.\n' >&2
    exit 1
  fi
  root_marker="/etc/overlayfs-proof-${run_id}.txt"
  data_marker="/srv/data/overlayfs-proof-${run_id}.txt"
  result=0

  if [ ! -e "$root_marker" ]; then
    printf 'PASS: current root marker was discarded\n'
  else
    printf 'FAIL: current root marker survived reboot\n'
    result=1
  fi
  if data_value=$(sudo cat "$data_marker" 2>/dev/null) && [ "$data_value" = "$run_id" ]; then
    printf 'PASS: current external marker retained its content\n'
  else
    printf 'FAIL: current external marker is missing or changed\n'
    result=1
  fi
  exit "$result"
)

Expect two PASS lines for the recorded run. A FAIL means you should inspect the mounts and recursion setting before storing real data. Repeat the complete preparation and recording process with a fresh ID each time. Because this uses sync and an orderly reboot, it checks persistence rather than durability during an interrupted write.

Next, shut down cleanly, disconnect the data drive and boot again. The intended behavior is that the OS remains accessible while the application fails to start. Inspect its status and journal. Reconnect the drive with the machine shut down, boot, and verify normal application recovery.

Recover if the Pi stops booting

If the problem begins after changing the overlay setup:

  1. Power off the Pi and connect its OS storage to another computer.
  2. Open the FAT boot partition and identify the active command-line file: cmdline.txt by default, or the filename selected by a custom cmdline= setting in config.txt. Back up that file. The default file is at the root of the mounted partition on the other computer; /boot/firmware is its mount location on the Pi.
  3. In that file, replace the single overlayroot=… argument with overlayroot=disabled. Preserve every other argument, especially root=, and keep the command line on one line.
  4. Save, safely eject the storage, return it to the Pi and boot. Verify that / is writable ext4 before repairing the configuration or trying the overlay again.

This bypasses the overlay on the next boot. For damaged media or an unrelated boot fault, use your known-good system backup. Raspberry Pi explains the kernel command-line file and boot configuration settings; disabled is documented in the overlayroot configuration.

Update Raspberry Pi OS without losing the changes

Package installation can appear to succeed inside the writable overlay and then vanish at reboot. An update must run against the real writable root.

There is a version-specific reason to manage the boot argument deliberately: the reviewed raspi-config revision’s disable function removes the plain overlayroot=tmpfs token followed by a space. It does not match the customized overlayroot=tmpfs:recurse=0 value. Appending a second, conflicting argument makes the mode harder to reason about. See the pinned enable and disable functions.

Use this maintenance cycle:

  1. Stop the application cleanly and take an application-consistent backup of its persistent data.
  2. Remount boot writable and edit cmdline.txt as before.
  3. Replace the one overlay argument with overlayroot=disabled; preserve the rest of the line.
  4. Run sync, remount boot read-only, and reboot.
  5. Inspect / with findmnt. Continue only when it is the ordinary ext4 root mounted writable, rather than an overlay.

At that point, temporarily remount boot writable for package and kernel changes:

sudo mount -o remount,rw /boot/firmware
sudo apt update
sudo apt full-upgrade

Keep the overlay disabled through required reboots and validation. The boot partition’s persistent fstab policy can remain read-only, so remount it writable again when a later maintenance step needs it.

Once the updated system and application work, restore the single argument to overlayroot=tmpfs:recurse=0, synchronize, remount boot read-only and reboot. Repeat the mount and persistence checks. Do not rerun the initial enable toggle while leaving a competing overlayroot=disabled argument in place.

For permanent changes to /etc/fstab, service definitions or OS configuration, use this writable maintenance boot. Editing the active root overlay is not a persistent provisioning method.

What an external SSD still needs after a power outage

Separating OS and data narrows the recovery problem, but the external filesystem is deliberately writable. Its filesystem journal helps structural recovery; application records still need an appropriate write and transaction strategy. A USB connection does not imply power-loss protection.

For a database, preserve its recovery files and use supported backup procedures. SQLite, for example, documents both automatic recovery from interrupted transactions and failure modes involving storage that does not honor synchronization requests. When migrating or backing up a live database, account for any required journal or WAL state rather than copying only the main file. See SQLite’s corruption and recovery guidance and its explanation of the WAL file as part of database state.

If the logger reports that a reading was saved, must that reading survive a power cut? Or can you afford to lose the last few readings? That decision determines which database durability settings and storage behavior you need to verify. Keep a restorable backup on another device or system. If you need a graceful shutdown, use a UPS with working shutdown integration.

Test the failure you actually expect

Use spare media and synthetic records for any deliberate power interruption. Record the Pi model, OS image, kernel, package versions, drive, adapter and power setup. Check OS bootability separately from external filesystem health and application-record integrity.

A useful test matrix includes an idle power cut, an interruption during sustained application writes, and booting with the data drive absent. Define what counts as a committed record before the test, and compare that boundary with recovered records. Use database-specific integrity checks where applicable; a mounted filesystem and a running process are insufficient evidence of correct data.

A successful run would describe that hardware combination and workload, rather than establish a universal failure rate.

When this design is a good fit

I would choose this pattern for an appliance whose OS changes occasionally and whose data has a clear home: a kiosk, a small logger or a narrowly scoped home service.

The tradeoffs are deliberate maintenance boots, a RAM budget for temporary writes, and less persistent diagnostic history unless you provide it elsewhere. A frequently modified development workstation may benefit more from ordinary writable storage, reliable power and tested backups.

Before relying on it, I would want to see four things on the actual Pi: the expected mounts, a retained application record after reboot, a service that refuses to start without its drive, and a successful return from writable maintenance mode. Those observations are the next evidence this reference needs.