Skip to content

Commit 1912831

Browse files
ecdyeclaude
andcommitted
Fix SD mirroring of zram-managed data and first-boot zram failure
Address findings from community test bench report (#2156): - Sync SD (diff mode) rsynced live /var/log and openHAB persistence into /opt/zram/*.bind on the target, but zram-config bind-mounts the target directory over those paths at boot, so the synced data was shadowed and never used. Worse, the main rsync's --one-file-system + --delete emptied the clone's lower /var/log and persistence directories because they are overlay mountpoints on the running system. Rsync now targets the plain lower paths that zram-config uses as overlay lowerdir. - Both raw and diff copies carried over the live system's /usr/local/lib/zram-config/zram-device-list, causing zram-config on the clone's first boot to skip device creation. The state file is now removed from the target in both paths. - Run sync and udevadm settle between dd and set-partuuid to avoid intermittent PARTUUID assignment failures on loaded systems. - Document that raw copies cannot capture data still held in zram. Fixes #2156 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 8fcbd2d commit 1912831

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

docs/openhabian-backup.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ If you can't find the same model, play it safe and buy a model larger than what
4141
We also provide a couple of different options to allow you to backup your system to a local NAS, cloud storage, or a second SD card.
4242
For more information on these options, please see [Storage Preparation](#storage-preparation).
4343

44+
Note that the semiannual raw copy reads the SD card at the block level, so any log and persistence data still held in ZRAM (i.e. written since the last ZRAM sync or reboot) will not be part of the raw copy.
45+
The daily rsync run covers this by copying the live view of those directories, so a mirror card will at most be a day behind on ZRAM-held data.
46+
4447
##### Moving the Root Filesystem
4548

4649
Moving your system root to a USB stick or SSD is unsupported and dangerous.

functions/backup.bash

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ mirror_SD() {
416416
if ! cond_redirect dd if="${src}p1" bs=1M of="${dest}1" status=progress; then echo "FAILED (raw device copy of ${dest}1)"; dirty="yes"; fi
417417
if ! cond_redirect dd if="${src}p2" bs=1M of="${dest}2" status=progress; then echo "FAILED (raw device copy of ${dest}2)"; dirty="yes"; fi
418418
sfdisk -d ${src} | grep -q "^${src}p3" && if ! cond_redirect dd if="${src}p3" bs=1M of="${dest}3" status=progress; then echo "FAILED (raw device copy of ${dest}3)"; dirty="yes"; fi
419+
# flush kernel buffers and let udev settle so blkid/mount see the freshly written partitions
420+
cond_redirect sync
421+
cond_redirect udevadm settle
419422
origPartUUID="$(blkid "${src}p2" | sed -n 's|^.*PARTUUID="\(\S\+\)".*|\1|p' | sed -e 's/-02//g')"
420423
if ! partUUID="$(yes | set-partuuid "${dest}2" random | awk '/^PARTUUID/ { print substr($7,1,length($7) - 3) }')"; then echo "FAILED (set random PARTUUID)"; dirty="yes"; fi
421424
if ! cond_redirect e2fsck -f -y "${dest}2"; then echo "FAILED (e2fsck)"; dirty="yes"; fi
@@ -428,6 +431,8 @@ mirror_SD() {
428431
mount "${dest}2" "$syncMount"
429432
sed -i "s|${origPartUUID}|${partUUID}|g" "$syncMount"/etc/fstab
430433
[[ -f "${syncMount}/etc/systemd/system/${storageDir}".mount ]] && sed -i 's|^What=.*|What=/dev/mmcblk0p3|g' "${syncMount}/etc/systemd/system/${storageDir}".mount
434+
# remove zram state captured from the live system, else zram-config skips device creation on the clone's first boot
435+
rm -f "${syncMount}/usr/local/lib/zram-config/zram-device-list"
431436
umount "$syncMount"
432437
if ! cond_redirect fsck -y -t ext4 "${dest}2"; then echo "OK (dirty bit on fsck ${dest}2 is normal)"; dirty="yes"; fi
433438
if [[ "$dirty" == "no" ]]; then
@@ -453,8 +458,12 @@ mirror_SD() {
453458
mount "$dest" "$syncMount"
454459
if ! (mountpoint -q "$syncMount"); then echo "FAILED (${dest} is not mounted as ${syncMount})"; return 1; fi
455460
cond_redirect rsync --one-file-system --exclude={'/etc/fstab','/etc/systemd/system/*.mount','/opt/zram','/srv/*'} --delete -aKRh "/" "$syncMount"
456-
cond_redirect rsync --one-file-system --delete -aKh "/var/lib/openhab/persistence/" "${syncMount}/opt/zram/persistence.bind"
457-
cond_redirect rsync --one-file-system --delete -aKh "/var/log/" "${syncMount}/opt/zram/log.bind"
461+
# sync the live overlay (merged) view into the clone's lower dirs, i.e. the plain paths zram-config
462+
# uses as lowerdir on boot; the *.bind mountpoints are shadowed by bind mounts and must not be targets
463+
cond_redirect rsync --one-file-system --delete -aKh "/var/lib/openhab/persistence/" "${syncMount}/var/lib/openhab/persistence/"
464+
cond_redirect rsync --one-file-system --delete -aKh "/var/log/" "${syncMount}/var/log/"
465+
# remove zram state captured from the live system, else zram-config skips device creation on the clone's first boot
466+
rm -f "${syncMount}/usr/local/lib/zram-config/zram-device-list"
458467
if ! (umount "$syncMount" &> /dev/null); then
459468
sleep 1
460469
umount -l "$syncMount" &> /dev/null

0 commit comments

Comments
 (0)