Score:0

How can I artificially induce corrupt ext4 filesystem without data loss?

cn flag

I am trying to deal with a very rare corner case where my system has a minor corruption in the ext4 filesystem. This trigger systemd's emergency.service and I am trying to alter the behavior of it to automatically fix the fs.

Anyhow, is there any way to slightly alter the partition/filesystem to induce this state with minimal chance of dataloss? I just need fsck to return that something is wrong.

Score:2
cn flag

If emergency.service runs, the initrd switch root or the fsck has already been attempted and failed. systemd-fsck-root.service can be told to always repair (fsck -y) with the kernel command line parameter fsck.repair=yes

fsck will be skipped for any file system with passno value of 0 in /etc/fstab (6th field). Possibly a bad idea in a system with a history of corruption, but if the file system mounts allows continued operation.

File systems can be made not required for local-fs.target with a nofail option in fstab. However this does not work for root fs. Consider creating a new file system at the mount point you suspect contains problem files, for example /var/lib/whatever. With nofail option, even if it fails to mount, will not be dropped into an emergency shell.

Backups are the last line of defense to avoid losing important data. Do not rely on repair to always fix things, even on mature file systems.

Some corrupted file systems exist in the e2fsprogs test suite. Tricky to use for real, espcially as a root fs. Image your block device with it, extend it larger, and restore your data from backup.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.