Avoiding filesystem corruption with hibernation and ephemeral root

I was recently hit by a filesystem corruption issue running an ephemeral root FS while using hibernation. During my investigations I found out I was accidentally clearing the filesystem before resuming. Since this is (in my opinion) a pretty subtle and easy-to-make mistake, I’ve posted my findings and a fix here: