Bootstrap: Postgres bind-mounts on live boots only.

wrolpi-bootstrap.service applied the /media/wrolpi/config/postgresql
bind-mounts over /var/lib/postgresql and /etc/postgresql at every boot,
including on installed systems.  The binds exist for live boots, where
the root filesystem is an ephemeral overlay; on an installed system they
put the cluster in the path of repair.sh's config chown
(pg_filenode.map permission errors) and, once the user mounts an
NTFS/exFAT primary drive over /media/wrolpi, point Postgres at a
filesystem that cannot host a data directory at all — no clusters,
connection refused, while the umbrella postgresql.service stays green.

Installed systems now keep Postgres at the normal Debian paths on the
root filesystem.  A box that still has a stale bind active from an old
boot gets a log note to reboot; on the first clean boot the existing
pg_createcluster/initialize_api_db logic builds the root-disk cluster
automatically and the database rebuilds from configs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-05 15:33:54 -06:00
parent 2e660cdbb9
commit f500600025
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680

View file

@ -25,9 +25,11 @@
# 4. Installed. No live medium present; partition-creation branch is
# skipped. /media/wrolpi is mounted via /etc/fstab on an external
# drive, or is a plain directory on the root filesystem if the user
# installed without one. The Postgres bind-mounts happen at every
# boot here because /etc/fstab doesn't own them — see Before= in the
# .service unit.
# installed without one. Postgres lives at the normal Debian paths on
# the root filesystem: the bind-mounts are for live boots only, where
# the root filesystem is ephemeral. An installed system's primary
# drive may be NTFS/exFAT, which cannot host a Postgres data
# directory at all.
set -euo pipefail
@ -232,27 +234,42 @@ chown wrolpi:wrolpi /media/wrolpi 2>/dev/null || true
mkdir -p /media/wrolpi/config
chown wrolpi:wrolpi /media/wrolpi/config
mkdir -p /media/wrolpi/config/postgresql/data \
/media/wrolpi/config/postgresql/config
chown postgres:postgres /media/wrolpi/config/postgresql \
/media/wrolpi/config/postgresql/data \
/media/wrolpi/config/postgresql/config
chmod 0700 /media/wrolpi/config/postgresql/data
# --- Postgres bind-mounts (live boots ONLY, idempotent) ------------------
# On live boots the root filesystem is an ephemeral overlay, so the
# cluster must live on the persistence partition: /var/lib/postgresql
# (data) and /etc/postgresql (config) are bind-mounted onto
# subdirectories of /media/wrolpi and travel with the stick.
#
# On INSTALLED systems Postgres stays at the normal Debian paths on the
# root filesystem. The primary drive there may be NTFS/exFAT, which
# cannot host a Postgres data directory (no POSIX ownership/0700), and
# repair.sh chowns /media/wrolpi/config for the wrolpi user.
# --- Postgres bind-mounts (idempotent) ----------------------------------
# /var/lib/postgresql holds the cluster data dir; /etc/postgresql holds
# the per-cluster configuration. Bind-mounting them onto subdirectories
# of /media/wrolpi means the entire Postgres state travels with the WROLPi
# drive.
if [ "$MODE" != "installed" ]; then
mkdir -p /media/wrolpi/config/postgresql/data \
/media/wrolpi/config/postgresql/config
chown postgres:postgres /media/wrolpi/config/postgresql \
/media/wrolpi/config/postgresql/data \
/media/wrolpi/config/postgresql/config
chmod 0700 /media/wrolpi/config/postgresql/data
bind_if_unmounted() {
local src=$1 dest=$2
mkdir -p "$dest"
mountpoint -q "$dest" || mount --bind "$src" "$dest"
}
bind_if_unmounted() {
local src=$1 dest=$2
mkdir -p "$dest"
mountpoint -q "$dest" || mount --bind "$src" "$dest"
}
bind_if_unmounted /media/wrolpi/config/postgresql/data /var/lib/postgresql
bind_if_unmounted /media/wrolpi/config/postgresql/config /etc/postgresql
bind_if_unmounted /media/wrolpi/config/postgresql/data /var/lib/postgresql
bind_if_unmounted /media/wrolpi/config/postgresql/config /etc/postgresql
else
# Installed system that previously ran with the binds (older bootstrap):
# if a stale bind is still active from this boot, leave it alone — the
# cluster logic below would otherwise misdetect. It disappears on the
# next reboot with this version.
if mountpoint -q /var/lib/postgresql; then
log "NOTE: /var/lib/postgresql is still bind-mounted (old layout); reboot to move Postgres to the root filesystem."
fi
fi
# --- Postgres cluster ---------------------------------------------------
# Derive version from the installed Postgres binary so this stays correct