The Regex That Commented Out My Root Filesystem: Six Months of Read-Only Boots
One of my homelab nodes, an old Dell laptop, had a reputation: its SSD "kept locking itself read-only". Twice I diagnosed it, twice I fixed it with fsck and a remount, and twice I wrote down a plausible cause. In November 2026, while turning that laptop into the first control plane of the rebuilt cluster, I finally found the real one: a single regular expression in my own bootstrap playbook had commented out the root filesystem's line in /etc/fstab, six months earlier.
Impact
- Actual: from 2026-05-30, the node booted with
/read-only every time. containerd and the kubelet couldn't write, so the node dropped out of the cluster after every reboot until someone remounted the root by hand. A recovery script made that routine, which hid the pattern. - Misdiagnosis: the June lockout was logged as "a dirty ext4 journal from a hard shutdown". The hardware was suspected throughout.
- Collateral: the same task had commented out
/boot/efion the GPU laptop. That node still booted, but bootloader updates were being written to an empty directory on the root disk instead of the EFI partition. - Blast radius: every node the playbook had run on, on Debian's default fstab layout.
Timeline
- 2026-05-23 to 26 - Real read-only lockouts with
EXT4-fserrors after hard power-offs; repaired withfsck. These predate the bug. - 2026-05-30 10:15 - Playbook
02-bootstrap-debian.yamlruns on the Dell. Its "disable swap in fstab" task edits/etc/fstaband leaves a backup,/etc/fstab.<pid>.2026-05-30@10:15:04~. From the next boot on,/stays read-only. - 2026-06-01 to 02 - Node
NotReadyafter a power-on; containerd fails withread-only file system. Logged as a dirty journal, "fixed" withrecover-node.sh(fsck,mount -o remount,rw /). The fix holds until the next reboot. - 2026-11-22 21:49 -
kubeadm reseton the Dell fails on every file:read-only file system. - 21:50 -
recover-node.shagain:fscksays clean, remount works. - 22:00 - After a reboot
/isroagain. SMART:PASSED, 0 reallocated and 0 uncorrectable sectors. The kernel log of the "previous boot" is from May: nothing had been persisted since. - 22:02 -
cat /etc/fstab: the root entry starts with#. The swap line is gone entirely. - 22:05 - Root line restored,
findmnt --verifyclean, reboot:/comes uprw. The Ansible backup's timestamp dates the edit. - 22:08 - Same check on the GPU laptop:
/fine,/boot/eficommented out. Restored, mounted,grub-installre-run.
Root cause
The regex. The task was meant to comment out swap entries:
- name: Disable swap permanently in /etc/fstab
ansible.builtin.replace:
path: /etc/fstab
regexp: '^(\s*[^#\n]+\s+\S+\s+swap\s+.*)$'
replace: '# \1'
ansible.builtin.replace runs the pattern over the whole file in multiline mode, and \s matches newlines. Debian's installer writes a comment after each entry, so the file read:
UUID=... / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=... none swap sw 0 0
The pattern started on the root line, \s+ crossed the line break, \S+ matched #, and swap matched the comment. The match began on the root line, so the root line got the # . (See In a Regex, the Whitespace Class Also Matches Newlines, So One Pattern Can Span Two Lines.)
Why it looked like a disk. Debian boots with ro on the kernel command line, and systemd-remount-fs later applies the fstab options for /. With no active / entry it had nothing to apply, exited successfully, and left the root read-only. Nothing logged an error; the persistent journal couldn't even be written (see With No Active Root Entry in fstab, systemd Leaves the Root Filesystem Read-Only on Every Boot).
Why it lasted six months. The recovery script ran fsck and remounted read-write, which worked every time. Its own swap step, sed -i '/swap/d' /etc/fstab, then deleted every line containing "swap", including the evidence. And a real ext4 incident a week earlier made "the disk again" the obvious story.
Actions
- Restore the root entry on the Dell and
/boot/efion the GPU laptop; re-rungrub-installthere. - Rewrite the regex with
[ \t]instead of\s, matching only lines whose third field isswap. - Assert after the edit that
/etc/fstabstill has an active entry for/(with theis searchtest: ansible-core 2.19 rejects a conditional that evaluates to a string). -
recover-node.shcomments out active swap entries instead of deleting every line containing "swap". - Add the pattern to the homelab troubleshooting guide, and correct the earlier diagnoses.
- Check the other
replaceandlineinfiletasks for patterns that can cross lines.
Lessons learned
- Read the boot, not the repair. "Read-only after every reboot,
fsckclean, SMART clean" is not a disk fault. A recurring symptom with clean diagnostics points at configuration. - A recovery script can hide a bug.
fsckplus a remount fixed the symptom so reliably that nobody looked at why it came back. - Test text edits on the real file. The regex was right for a single line. The file has comments between the lines.
- Assert the end state. The playbook was green for six months; an assert on "the root still has an entry" would have failed on the first run. It's the same lesson as The Playbook That Said ok, from another angle.
- Keep backups dated. Ansible's
backup: yesfile was the only timestamp linking the incident to its cause.
References
- systemd: systemd-remount-fs.service - how the root gets its fstab options.
- Ansible: ansible.builtin.replace - multiline matching over the whole file.
- With No Active Root Entry in fstab, systemd Leaves the Root Filesystem Read-Only on Every Boot - the mechanism.
- In a Regex, the Whitespace Class Also Matches Newlines, So One Pattern Can Span Two Lines - the regex trap.
- ext4 Remounts Root Read-Only When It Cannot Trust the Disk, and the kubelet Falls with It - the look-alike it was mistaken for.
- An Ansible replace Task That Matches Nothing Reports ok, So Assert the End State - asserting the end state.
- The Read-Only Lockdown - the earlier, genuine ext4 incident.
- Homelab v2 Rebuild - the lab this was found in.