Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
33 lines
2.2 KiB
Bash
33 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
# rnr5090: simulate a stalled root disk for N seconds (default 600) to prove that the RAM-only rescue sshd (port 2222)
|
|
# still lets you in. Owner-run (root). It FREEZES the filesystems (fsfreeze): every write to / and /data blocks,
|
|
# reads of already cached files continue. That is the same user-visible effect as the NVMe controller stalling:
|
|
# the normal sshd (port 22) blocks when it writes wtmp/lastlog/journal, journald and any logger block, new logins hang.
|
|
#
|
|
# sudo bash test-rescue-sshd.sh # freeze for 600 s
|
|
# sudo bash test-rescue-sshd.sh 300 # freeze for 300 s
|
|
#
|
|
# Safety net: BEFORE freezing, a transient systemd timer is created in /run (RAM) that runs `fsfreeze -u` on both
|
|
# filesystems after N seconds, whatever happens to your session. You can also thaw by hand from the rescue shell:
|
|
# ssh -p 2222 root@192.168.1.196 then fsfreeze -u /data; fsfreeze -u /
|
|
# Do not run it while a model run or a copy is in progress (writers block for the whole time).
|
|
set -euo pipefail
|
|
S=${1:-600}
|
|
if [ "$(id -u)" -ne 0 ]; then echo "run as root (sudo)" >&2; exit 1; fi
|
|
case "$S" in ''|*[!0-9]*) echo "seconds must be a number" >&2; exit 2;; esac
|
|
[ "$S" -ge 60 ] && [ "$S" -le 1800 ] || { echo "seconds must be 60..1800" >&2; exit 2; }
|
|
pgrep -f "sshd_config -E /[r]escue.log" >/dev/null || { echo "rescue sshd is not running: run rescue-sshd.sh --build first" >&2; exit 1; }
|
|
command -v fsfreeze >/dev/null || { echo "fsfreeze not found" >&2; exit 1; }
|
|
cp "$(command -v fsfreeze)" /run/rescue/bin/fsfreeze 2>/dev/null || true # so the rescue shell can thaw by hand (its libs are already there for most libc-only tools)
|
|
for m in /data /; do
|
|
systemd-run --quiet --on-active="${S}s" --unit="leleka-thaw$(echo "$m" | tr / _)" /usr/sbin/fsfreeze -u "$m"
|
|
done
|
|
systemctl list-timers --no-pager 'leleka-thaw*' || true
|
|
echo "$(date -u +%FT%TZ) freezing / and /data for ${S}s; automatic thaw is scheduled"
|
|
sync
|
|
fsfreeze -f /data
|
|
fsfreeze -f /
|
|
echo "frozen (this line was printed from memory). Test from the laptop now:"
|
|
echo " ssh -o ConnectTimeout=20 -p 22 para@192.168.1.196 true # expected to hang or fail"
|
|
echo " ssh -p 2222 root@192.168.1.196 'cat /proc/pressure/io; echo alive'"
|