Need information about how avoid corruption of filesystem in beaglebone with SD

Hi, I need information about how avoid corruption of filesystem when power off my beaglebone, I know there are several methods:

  • to use a only read filesystem
    I think the way to do that is change the bootargs of uboot with root=/dev/mmcblk0p1 ro instead of rw,

is it rigth?, but if I need change any file, Can I do it ?

  • to use a ramfs or tmpfs, but that way I don’t undertand well, could someone expalin me? and is it possible use with beaglebone, I know that is something like mount a partition over RAM (ramfs → complete filesystem ; tmpfs–>workfolder over RAM) is it rigth?

I prefer use a only read filesystem, what do you think?, what way is the better to avoid the corruption filesystem.

Sorry my poor english.

Thank you.

Antonio Garcia Oteros <oteros2000@gmail.com> [12-09-15 19:04]:

Hi, I need information about how avoid corruption of filesystem when power
off my beaglebone, I know there are several methods:

   - to use a only read filesystem

I think the way to do that is change the bootargs of uboot with *root=/dev/mmcblk0p1
ro* instead of *rw*,
          is it rigth?, but if I need change any file, Can I do it ?

   - to use a ramfs or tmpfs, but that way I don't undertand well, could
   someone expalin me? and is it possible use with beaglebone, I know that is
   something like mount a partition over RAM (ramfs --> complete filesystem ;
   tmpfs-->workfolder over RAM) is it rigth?

I prefer use a only read filesystem, what do you think?, what way is the
better to avoid the corruption filesystem.

Sorry my poor english.

Thank you.

--

Hi Antonio,

I assume you are Linux with your system?!!

Some things in beforehand:
A fully, non crippled system needs some place, where it can write
down informations. Most can be switched off or simply ignored, but
this would lead to a 'not so fully featured' (hrrrmm) system.

Example:
Log in Linux system and at the commandline type 'last<return>' and
get a list of the last logins, system boots and halts.

All these informations came from writing them permantly to the
filesystem so they survive a reboot.

You can writeprotect the filesystem by mounting it ro...but this
would cripple that 'feature' of Linux or any other UNIX system.

More examples would be the history file of you shell or the all the
logfiles below /var/log...

Generally switching off a running UNIX/Linux-system by simply pulling
the plug is a bad idea.

On the other hand: After a 'halt'- or 'shutdown-command it is
completly
save to do so.

Why?
Both commands instruct the system to first send the HUP then the kill
command to any process to ensure that no open files remain. Then the
filesystem will be synced (that is, the caches in RAM will be emptied
to the disk/sd card) and finally the filesystem is remounted read
only. These procedure ensures the consistency of the data.

Simply cutting the power will wipe the caches in RAM and data may be
inconsistence on disk.

When booting again such a system will force a recheck of the
filesystem and fix the inconsistency in the best case.

The worst case will leave you with a system no longer booting and
a filesystem, which may be corrected by manually fixing the
inconsistency...

But...

There are so called 'journaled filesystems" (ext4/reiserfs for
example) which tries to update data in atomic writes to the disk/sd
card, which shortens the time of the existence of inconsistence data
while writing the caches to disk.

This means chances to get a fully functinal system after a power fail
is much more likely, but the newest version of the data may miss
though.

So the best way to ensure a healthy state of your system is to use
'halt/shutdown' in every case. Dont simply pull the plug.

The next step to get a more robust system would be to choose a
journaled filesystem.

Next would be to mount the filesystem in 'sync' mode. That is: Any
write will not be cached in RAM but will go straight to the
disk/sd-card. BUT BEWARE! This will heavily slow down you system
especially when accessing the same files over and over (header files
when compiling for example) again. AND it will dratically increase the
writes cycles to the sd-card, which in turn will wear out much earlier
then. Result: A damaged filesystem due to a damaged sd-card. Better
not...

You may mount parts of the filesystem on tmpfs, which make those
writeable on a read only mounted sd-card.

But this will decrease your system RAM. On a beaglebone with 256MByte
there is not that much space for such...

Just check it out yourself.

From the commandline you can do as root (for example)

  mount tmps /tmp -t tmpfs -o size=64M

which will mount tmpfs (physically your system RAM) over /tmp
(that is writes to /tmp will go into RAM). A size of 64MBytes will be
used for that.

But again: Your system still needs some RAM to breath.

The best way to avoid filesystem corruption is to use 'halt' and
'shutdown' before powering off the system.
To be more secure in case of power failures is to use a journaled
filesystem. But it is be no means a replacement for 'halt' and
'shutdown'.
Mounts of tmpfs on a small system like the beaglebone with 256MByte
RAM should be avoided except for small amounts, which are normally
configured by the linux distro you use...
And a 'synced mount' is theoretically possible but in the real world
this attempt is of academic purpose only... :wink:

Hopefully this may be of help a little...

Have a nice weekend!
Best regards
mcc

Hi, I need information about how avoid corruption of filesystem when power off my beaglebone, I know there are several methods:

  • to use a only read filesystem
    I think the way to do that is change the bootargs of uboot with root=/dev/mmcblk0p1 ro instead of rw,

is it rigth?,

With bootargs=… root=/dev/mmcblk0p1 rootfstype=ext3 rw … u-boot tells the Linux kernel via the kernel command line that it should try to mount from the first partition a root file system of type ext3 and mount it as read/write. In case you make this read only (ro) you need to make sure that there are some mount points in your file system where Linux can write as well e.g. for log files and stuff (but they could be in in RAM).

but if I need change any file, Can I do it ?

To permanently change a file you need to write e.g. with your PC a new root file system to the SD card. If the change does not need to be permanent you can use a RAM disk.

  • to use a ramfs or tmpfs, but that way I don’t undertand well, could someone expalin me? and is it possible use with beaglebone, I know that is something like mount a partition over RAM (ramfs →

You can build a kernel + rootfs (as RAM disk) bundle and also have the kernel and the RAM disk separate from each other. In both cases the rootfs will be running from RAM.

  • complete filesystem ; tmpfs–>workfolder over RAM) is it rigth?

You can have e.g. your root file system partly from an ext3 on your SD card and partly from RAM.
Type mount on your board and you can see what mount point comes from where.

I prefer use a only read filesystem, what do you think?, what way is the better to avoid the corruption filesystem.

The question is: Do you need to save files permanently? If not you might get away with a kernel/rootfs combo and/or a (partially) read only rootfs.

Sorry my poor english.

Thank you.

Regards,

Robert

Hi, I need information about how avoid corruption of filesystem when
power off my beaglebone, I know there are several methods:

What do you mean by "power off my beaglebone?"

Do you mean during normal `shutdown -h now` type power offs or do you
mean "I pull the AC power cord out while doing important things in
software" kind of power off?

   - to use a only read filesystem

I think the way to do that is change the bootargs of uboot with
*root=/dev/mmcblk0p1 ro* instead of *rw*,
          is it rigth?, but if I need change any file, Can I do it ?

Changing the u-boot args given to the kernel only affect the first
mounting of the root file system by the kernel. Once init starts, it'll
usually remount the file systems as specified in /etc/fstab.

Realistically, the kernel only needs the root file system to be read-
only at boot time. I don't understand why a bootarg of rw would ever be
given (if you have a good reason, I'd like to learn, please share).

   - to use a ramfs or tmpfs, but that way I don't undertand well,
could someone expalin me? and is it possible use with beaglebone, I
know that is something like mount a partition over RAM (ramfs -->
complete filesystem ; tmpfs-->workfolder over RAM) is it rigth?

If you don't want to persist between bootups, ie: anything you write
(but you _DO_ have write ability) disappears at next boot, then a ram
disk could be a good choice. There's lots of info online about creating
and booting from ram disks either with the image for the ram disk loaded
via network, flash, or SD card (or any other medium, really).

If you don't want the ability to write at all (not even logs), then a
strictly read-only file system is worth considering. Most likely what
you want is a combination of the two, and leaving some other portions of
the file system rw.

I prefer use a only read filesystem, what do you think?, what way is
the better to avoid the corruption filesystem.

It depends on your use case. If you just have certain files that you
don't care about persisting across reboots but you want to write to them
willy-nilly, then a tmpfs is probably a good choice and simply leave
your root file system as read-write.

Some references to read for you:

http://www.stlinux.com/u-boot/mkimage/ramdisk-images

http://wiki.debian.org/ReadonlyRoot

Hopefully those will help you decide.

-Andrew

Thank at all, for your interest.

After the last weekend a have got some advanced of the final solution.
I created a RAMFS with my custom filesytem (distribution ansgtrom). Because I want keep the original filesystem with any corruption, against switch off of power and other electrical events.

This is my schematic SD:

-first patition : FAT
u-boot.img
MLO
ramfs.bin (custom distribution angstrom)
-second partition
/home → with my aplication and configuration files, in this partition I can read and write, and that changes are saved.

When the system start, mount the kernel and ramfs in RAM, that’s in my beaglebone works well.

The second step is auto-mount /home with my aplication, how can I do that?,

Any idea?

Thank you in advanced.

2012/9/17 Andrew Bradford <andrew@bradfordembedded.com>

/etc/fstab

-Andrew

Yes of course,

I created a RAMFS with this steps:

Make a RamDisk with 64Mbyte size

$ dd if=/dev/zero of=rd-image bs=1k count=65536

$ mkfs.ext2 rd-image

Mount the RamDisk and copy target/* to the root of the RamDisk

$ sudo mkdir /mnt/my_image

$ sudo mount -o loop rd-image /mnt/my_image/

#copy your filesystem

$ sudo cp -R filesystem/* /mnt/my_image/

$ sudo umount /mnt/my_image/

Gzip the RamDisk, then rename it to rd-ext2.bin

$ gzip -9 rd-image

$ cp rd-image.gz rd-ext2.bin

Copy this file rd-ext2.bin in the first partition FAT, with MLO,
u-boot.img and kernel (u-Image).

I have used these arguments to u-boot, I use beaglebone...

setenv bootcmd 'mmc rescan 0; fatload mmc 0 81000000 uImage; fatload
mmc 0 81600000 rd-ext2.bin; bootm 81000000'

setenv bootargs 'console=ttyO0,115200n8 root=/dev/ram0 rw
initrd=0x81600000,32M ramdisk_size=327678 nohz=off'

You must made your RAMFS at depend of the size of your filesystem, I
use a filesystem 80Mb and work well.

That's at all.