I've googled this extensively and can't quite come up with an answer.
Overview
I created two image files of a filesystem I'm actively using (/) and it sometimes is ok, and othertimes is not.
What I do
Using the following cmdline, I use dd to copy my / filesystem device (/dev/sda2, ext4) to an image file. It's a 470GB image, so I place it on an external USB HD auto-mounted on /media/me/Elements:
dd if=/dev/sda2 of=/media/me/Elements/test.img bs=1024K status=progress
This yields a roughly half TB test.img file.
When I then mount this as a loop device:
mount -o loop /media/me/Elements/test.img /mnt/iso
It works for some image files but not others. In the cases where it works I can traverse the loop filesystem /mnt/iso easily, and wander around the saved / as expected.
━━━━ /home/me ━━━━ sudo mount -o loop /media/me/Elements/test.img /mnt/iso
━━━━ /home/me ━━━━ ls /mnt/iso
bin/ dev/ games/ lib32/ media/ proc/ sbin/ sys/ var/ vmlinuz@
boot/ devel/ home/ lib64/ mnt/ root/ snap/ tmp/ initrd.img@ vmlinuz.old@
cdrom/ etc/ lib/ lost+found/ opt/ run/ srv/ usr/ initrd.img.old@
For other image files it always fails with the following error message:
━━━━ /home/me ━━━━ sudo mount -o loop /media/me/Elements/210130.stargazer.img /mnt/iso
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
...So I look at the bottom of the syslog (lines ommitted):
━━━━ /home/me ━━━━ dmesg | tail
[661659.208600] EXT4-fs (loop0): warning: mounting fs with errors, running e2fsck is recommended
[661666.570406] EXT4-fs (loop0): mounted filesystem with ordered data mode. Opts: (null)
BUT
I made both filesystems precisely the same way.
I'm investigating if it's partly because of a screensaver or because the filesystem itself might be in flux while saving, but it's difficult because this takes a long time between runs.
Is there a utility that can help me diagnose this? It's suggesting that I run e2fsck, but how can I when I can't even mount the thing in the first place to give it a filesystem to check?