Question about file systems
This is really a Linux question, but since it is specifically about embedded systems, I'm hoping this group is a good place to ask.
My application is based on an Atom, with a small USB flash drive (SLC) for its storage. I'm trying to decide what file system to use. The application doesn't do a lot of file accesses, and of course I'll mount the partition(s) with "noatime" since I don't care about recording access times. But I'm concerned that if someone yanks the plug, rather than pushing the button for an orderly shutdown, the next boot will do a long "fsck", and the user will think the system is broken.
So I guess the questions are these: Are ext2, ext3 and ext4 all equally likely to need to do an "fsck" after a disorderly shutdown? Do they typically take different amounts of time to do an "fsck"? Or is the journaling of ext3 and ext4 something that should be avoided on a flash drive at all costs, even though my app won't be doing much file access?
Also, my app stores its own data in a directory tree of typically a few hundred small files. Would it be a win or a lose to break this off into a separate small partition? I was actually thinking of making this a FAT32 partition, so that I could yank the drive and access those files in any other machine.
Any insights would be appreciated.
Signature · 2 lines
Ciao, Paul D. DeRocco Paul mailto:[email protected]
Quoted 23 lines · Paul D. DeRocco
This is really a Linux question, but since it is specifically about embedded systems, I'm hoping this group is a good place to ask.
My application is based on an Atom, with a small USB flash drive (SLC) for its storage. I'm trying to decide what file system to use. The application doesn't do a lot of file accesses, and of course I'll mount the partition(s) with "noatime" since I don't care about recording access times. But I'm concerned that if someone yanks the plug, rather than pushing the button for an orderly shutdown, the next boot will do a long "fsck", and the user will think the system is broken.
So I guess the questions are these: Are ext2, ext3 and ext4 all equally likely to need to do an "fsck" after a disorderly shutdown? Do they typically take different amounts of time to do an "fsck"? Or is the journaling of ext3 and ext4 something that should be avoided on a flash drive at all costs, even though my app won't be doing much file access?
Also, my app stores its own data in a directory tree of typically a few hundred small files. Would it be a win or a lose to break this off into a separate small partition? I was actually thinking of making this a FAT32 partition, so that I could yank the drive and access those files in any other machine.
Quoted 7 lines
Any insights would be appreciated.
--
Ciao, Paul D. DeRocco
Paul mailto:[email protected]
We have a somewhat similar situation here. We have a device which is not battery backed. And to top it off, the SOP to power off the machine is to yank its power cable.
Here is what I have come up with and it seems to be working for us for our requirements. All partitions are ext4.
We have one root partition that is always mounted read-only (except when we are upgrading). /var and /tmp (amongst a few others) are tmpfs
We have a separate apps partition that is mounted read-only (again except when we are upgrading). In addition to apps, we also store configuration like calibration etc in this partition.
We have another scratch partition which is mounted with "rw,sync,barrier=1" options where we store temporary files that need to survive a reboot - log files for example. However, if/when we detect filesystem corruption, we just format the partition during normal boot. In this case the files will of course not survive and that is acceptable.
The acceptable risk is that while we are upgrading apps or the OS image, the device should not be powered down. If it is - then we have a way to re-image the device in the field. But that is a separate discussion.
When we want to upgrade, we show a message that upgrade is underway on the UI. Remount the partition with "rw,barrier=1" (no need for sync), perform the upgrade, then remount with "ro" options.
The difference between root and apps partition is that while upgrades to apps will be frequent - multiple times a week - the upgrades to root will be rare - once in 2 years or even less - it is a very high bar to call for an OS upgrade. And we have built in stuff in our meta layers to recover from bad app partitions and bad scratch partitions. We did not want to club apps and root together and risk bricking the device during normal app upgrades.
We do not (using automation) try to recover data from partition, we (as a rule) format the partition and repopulate it. That works for us :-)
By no means am I an expert - this is based on help from a lot of folks over at the ext4 mailing list and of course here on the Yocto-Project's mailing list and IRC channel. We have invested some time in testing and making sure that we have a solution that works for us and does not surprise us.
I hope this helps. Please let me know if you want me to elaborate on something specific.
Autif
Quoted 5 lines · Paul D. DeRocco
So I guess the questions are these: Are ext2, ext3 and ext4 all equally likely to need to do an "fsck" after a disorderly shutdown? Do they typically take different amounts of time to do an "fsck"? Or is the journaling of ext3 and ext4 something that should be avoided on a flash drive at all costs, even though my app won't be doing much file access?
With the embedded project I work on, I had started (roughly 7 years ago) by using ext2 on our flash drive. I too found that my users always "yanked the cable" instead of trying to perform any sort of orderly shutdown. Technically this device is meant to run 24/7, but I found that several of our field reps were convinced they had to power-cycle after every configuration change (which I still don't understand... do they do that on their own computers?).
Anyway, with ext2 we would get irrecoverable disk corruption, or at least enough corruption that the bootup would halt, waiting (forever) for the user to "run fsck manually" (our device has a total of 4 LEDs on the front panel as the only feedback, and they don't "come alive" until user-space starts). So I switched to ext3 around (roughly) 5 years ago and have not once seen an incident of a failed bootup due to disk corruption/fsck problems.
Yes, it does make the duration of the bootup non-deterministic, but for our product bootup time is not a priority.
I can't say as to whether ext4 should be used instead of ext3 or which is better or faster. All I can say is if your users are "yanking the cable" you may want to stay away from ext2. Also some sort of fsck is always run on the next bootup when power is cut off unexpectedly.
There is a major difference between ext3 and ext4 which is called "delayed (block) allocation." Delayed allocation of blocks increases the risk of data loss in certain circumstances. While ext3 typically syncs cache to disk every 5s, it can take 2min with ext4.
Quoted 36 lines · Trevor Woerner
Quoted 5 lines · Paul D. DeRocco
So I guess the questions are these: Are ext2, ext3 and ext4 all equally likely to need to do an "fsck" after a disorderly shutdown? Do they typically take different amounts of time to do an "fsck"? Or is the journaling of ext3 and ext4 something that should be avoided on a flash drive at all costs, even though my app won't be doing much file access?
With the embedded project I work on, I had started (roughly 7 years ago) by using ext2 on our flash drive. I too found that my users always "yanked the cable" instead of trying to perform any sort of orderly shutdown. Technically this device is meant to run 24/7, but I found that several of our field reps were convinced they had to power-cycle after every configuration change (which I still don't understand... do they do that on their own computers?).
Anyway, with ext2 we would get irrecoverable disk corruption, or at least enough corruption that the bootup would halt, waiting (forever) for the user to "run fsck manually" (our device has a total of 4 LEDs on the front panel as the only feedback, and they don't "come alive" until user-space starts). So I switched to ext3 around (roughly) 5 years ago and have not once seen an incident of a failed bootup due to disk corruption/fsck problems.
Yes, it does make the duration of the bootup non-deterministic, but for our product bootup time is not a priority.
I can't say as to whether ext4 should be used instead of ext3 or which is better or faster. All I can say is if your users are "yanking the cable" you may want to stay away from ext2. Also some sort of fsck is always run on the next bootup when power is cut off unexpectedly.
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto
Signature · 12 lines
-- *Rudolf J. Streif* Director of Embedded Solutions The Linux Foundation [email protected] Phone: +1.619.631.5383 Skype: rudolfstreif PGP: RSA 2048/2048 D6E7D28B Linux Foundation Events Schedule: events.linuxfoundation.org Linux Foundation Training Schedule: training.linuxfoundation.org
Quoted 5 lines · Paul D. DeRocco
So I guess the questions are these: Are ext2, ext3 and ext4 all equally likely to need to do an "fsck" after a disorderly shutdown? Do they typically take different amounts of time to do an "fsck"? Or is the journaling of ext3 and ext4 something that should be avoided on a flash drive at all costs, even though my app won't be doing much file access?
While ext2 will need a fsck after a disorderly shutdown, ext3 and ext4 should not. They are journalling file systems and an unclean shutdown shouldn't affect them... *if* they can trust the underlying "disk".
However, you are using SSD-type storage, so that basically means you *can't* trust the underlying disk. If you pull power from a device like that when it isn't entirely quiescent, then you run the risk of the *whole* device going wrong. It's got a kind of filesystem of its own *internally*, which uses the flash and makes it *pretend* to have atomically-overwritable 512-byte sectors like a disk. Oh, and it'll do its own garbage collection in the background even when you're not talking to it. So you can't *know* when it's quiescent.
Those internal file systems, or "flash translation layers", are almost universally poorly implemented, and *will* lose data if you apply random power failures to them. Asking about the file system that you use on *top* of that "disk", be it fat/ext2/ext3/btrfs or whatever, is entirely irrelevant. If you care about data integrity in an environment where power is unsafe, then you really need to let the Linux system have direct access to real flash chips and use a proper flash file system like ubifs, *not* this misguided "pretend-to-be-spinning-rust" approach. That was sensible in the DOS days where the only way we could provide additional storage for the system was to implement an INT 13h DISK BIOS handler, but it's completely unnecessary now.
If you try really hard and do extensive testing, and you pay over the odds for your devices, you *might* manage to find one which (at least for the batch you're testing until they change the innards again without changing the model number) will pass your powerfail testing. Best of luck with that. You'll need it.
If you're really stuck with this model of storage and can't fix it, then I recommend you do some serious testing with automated power withdrawal and see if you can live with the results. Forget the file system on top; just test the device itself. On that note, I really ought to push some *code* to http://git.infradead.org/mmctest.git to go with the sternly-worded README.
With few writes, you're probably better off with ext3 rather than ext2. It should avoid the need for a fsck. Until the device corrupts itself.
Signature · 1 line
dwmw2