How to prevent filesystem corruption in embedded Linux?

How to prevent filesystem corruption in embedded Linux?

With an understanding of the NAND flash implementation being used in your embedded system there are several ways to protect against filesystem corruption in embedded Linux. Files that don’t need to be modified should be kept on a partition that is mounted read-only.

How to prevent NAND corruption in embedded Linux?

If local data logging is required a read-write partition can be created on the same medium as the read only partition, but in this case it is understood that in the rare case of NAND corruption due to sudden power loss it is acceptable to lose data. The read/write partition should be created aligned with the allocation group size (typically 4MiB).

Which is less prone to corruption ext3 or ext4?

While journaled filesystems like ext3/ext4 are less prone to corruption, they are far from immune. When a NAND write from the filesystem occurs, it must write a page at a time, and it must be erased before writing.

How does YAFFS2 / JFFS prevent corruption in embedded Linux?

When ECC failures occur, YAFFS2/JFFS permanently retires blocks, but XNAND improves on this by attempting to write corrupted blocks back with correct data from redundant sectors. In many cases this allows a sector to work for many thousands more writes.

Can a file system be corrupted due to power failure?

There is at least one commercial file system that does a tremendous job making sure that the file-system very nearly cannot be corrupted due to power failures and that the only data you risk loosing is data that was being added as the power went out. The down-side is that it is very expensive, on the up-side they offer great support.

Are there filesystems that can circumvent this issue?

If there were a filesystem that could circumvent this issue you would have heard of it. Because of that, a strategy to protect critical data will benefit most from decisions made on a hardware level, eg, by using an uninterruptible power supply. Probably this is not so feasible in your situation.

What should I do if my Linux VM crashes?

You can build the entire kernel and application environment, similar to what you might do with a cross-development environment for an Embedded Linux target. If your VM running Linux crashes, you simply restart the VM.

How is Linux used in an embedded system?

In this respect, using Embedded Linux is not greatly different from using VXworks, WindowCE, or another OS. You need an understanding of how the OS is designed, how to configure the OS, and how to program using its application programming interface (API). A few factors make learning how to program Linux easier than other embedded OSes.