The key phrase there is "when the loop device is mounted". You can run fsck
on an unmounted loopback device.
In other words, you can run losetup
to create the loopback block device and attach it the the relevant file, then run fsck
on it, then mount
it.
This, of course, can be scripted. You could even do it in /etc/rc.local
or similar if the loopback mounts were flagged noauto
in /etc/fstab
- then do the losetup/fsck/mount for each loopback fs in /etc/fstab
.
Note that is kind of an abuse of the noauto
flag because the loopback filesystem(s) will end up being automatically mounted. Comment out any loopback filesystems that you don't want auto-mounted.
Alternatively, you could modify whatever code runs mount -a
on your system (systemd, sysvinit shell script, or whatever) so that it runs mount -a -tnoloop
instead, so that loopback filesystems are never automounted like other filesystems. The script that does the losetup/fsck/mount could then be written to honour the noauto
flag if present.
/etc/fstab
you thought would work. It should work if the mount line includes the file system type, and the fsck pass is greater than the file system containing the loop-backed partition