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...
Hopefully this may be of help a little...
Have a nice weekend!
Best regards
mcc