Message ID | 20160905202931.3013-1-zajec5@gmail.com |
---|---|
State | RFC |
Headers | show |
Hi All, My 2 cents on this topic: I had the same issue on my IMX6 boards. Writing or changing a file, some power cut happens (somebody else doing a remote PoE reset or whatever cause) and the FS could get corrupted or files are lost. (easy to reproduce) It seems a mounted UBIFS volume uses write-back caching by default to gain speed .. but at the risk of data loss. It was possible to call sync after doing manual changes to files .. but it could get ugly if you forget it .. It's also not guaranteed that 3rd party apps properly write to disk. I've now added following to the kernel command line when a UBI rootfs gets mounted: rootflags=sync This ensures changes are auto-flushed to NAND faster. Introduced in: https://github.com/torvalds/linux/commit/8379ea31e991ed2098660954d25f64386adee65c Since using this argument.. I didn't encounter any issues so far.. Pros: - Seems a lot better, not been able to reproduce this in a week now - Covers any write action .. independently of the it's origin Cons: - Write speed will probably be lower (not measured yet) - it's a cannon to kill a fly It is still a non-perfect solution.. but at least it seems to reduce the risk of dataloss/boot failures by a descent margin in the meantime. Feel free to share opinions Koen On 2016-09-05 22:29, Rafał Miłecki wrote: > From: Rafał Miłecki <rafal@milecki.pl> > > It makes booting more reliable in case of power cuts. Up to now some > file system changes done in uci-defaults could be lost due to lack of > flushing. It was easy to spot with scripts creating files: after a power > cut created file was empty and uci-defaults script was deleted. > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> > --- > Hey, > > I'm far from sure if this is a correct solution, you may better treat it > as a problem report. It's trivial for me to reproduce this problem using > BCM47081 evice (with NAND and squashfs+ubifs) and following script: > > #!/bin/sh > echo -n "First booted on " > /etc/foo > date >> /etc/foo > echo "FOO FOO FOO" > /dev/kmsg > echo "FOO FOO FOO" > /dev/kmsg > echo "FOO FOO FOO" > /dev/kmsg > exit 0 > > After seeing "FOO FOO FOO" messages I can wait ~3 seconds, then do: > cat /etc/foo > (see expected output), power off device and see the issue on the next > boot. The created file /etc/foo is empty but /etc/foo is white-outed. > --- > package/base-files/files/etc/init.d/boot | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot > index 904f7db..cad001b 100755 > --- a/package/base-files/files/etc/init.d/boot > +++ b/package/base-files/files/etc/init.d/boot > @@ -12,7 +12,7 @@ uci_apply_defaults() { > [ -z "$files" ] && return 0 > mkdir -p /tmp/.uci > for file in $files; do > - ( . "./$(basename $file)" ) && rm -f "$file" > + ( . "./$(basename $file)" ) && sync && rm -f "$file" > done > uci commit > }
diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index 904f7db..cad001b 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -12,7 +12,7 @@ uci_apply_defaults() { [ -z "$files" ] && return 0 mkdir -p /tmp/.uci for file in $files; do - ( . "./$(basename $file)" ) && rm -f "$file" + ( . "./$(basename $file)" ) && sync && rm -f "$file" done uci commit }