User avatar
RDK
Posts: 262
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

SD Card Corruption

Thu Dec 31, 2015 10:52 am

Yes, there are lots of posts out there on this issue. So far I have not had the problem with my 3 Pi's, but I'm trying to think ahead.

Aside from UPS power and surge protection, the other popular idea is the set up some of the filesystem as temporary RAM disks. This is proposed several places https://raymii.org/s/blog/Broken_Corrup ... _Card.html and http://www.ideaheap.com/2013/07/stoppin ... pberry-pi/. However in the latter reference there is a "disclaimer" following some suggested code:
The following two lines should be added to /etc/fstab:

Code: Select all

none        /var/run        tmpfs   size=1M,noatime         00
none        /var/log        tmpfs   size=1M,noatime         00
UPDATE (unverified): I have been told that /var/run is now a symlink to a tmpfs filesystem, anyways, so you may not need to add /var/run anymore, and adding it may cause issues.
Thus my question is should I try this method to minimize writes to the SD card or is it no longer an issue?
And, what about using the noatime option?

Thanks for your time...RDK

jahboater
Posts: 4840
Joined: Wed Feb 04, 2015 6:38 pm

Re: SD Card Corruption

Thu Dec 31, 2015 11:05 am

For Pi2's with their 1GB of memory, I always add the two tmpfs filesystems.
Normally when a file is read its last access time is recorded. This is rarely useful and means that for every "read" there is an additional "write". Adding "noatime" is a common optimisation to avoid this.
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime,size=64m 0 0
Note the "size=" field is just a maximum - the file system takes only as much memory as the files actually use (plus about 100k fixed overhead). It is virtual memory, shared with everything else. If the size= field is omitted then the maximum is half the computers memory size (in this case 512MB).

Obviously memory is much faster than SD card access, so apart from reducing the disk writes, it may speed up some things like compilations.

User avatar
RDK
Posts: 262
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: SD Card Corruption

Thu Dec 31, 2015 1:34 pm

OK, I understand the philosophy of the RAM drives, but my question goes back to the disclaimer in that reference. Should we be doing that if those filesystems are
now a symlink to a tmpfs filesystem
....RDK

jahboater
Posts: 4840
Joined: Wed Feb 04, 2015 6:38 pm

Re: SD Card Corruption

Thu Dec 31, 2015 4:50 pm

If the directory is already a symlink (symbolic link) to an existing tmpfs file system then just leave it - its been done for you.

On my Pi2

Code: Select all

file /var/run
reports that it is a symbolic link to /run as does /var/lock which is a symlink to /run/lock.

As memory gets cheaper its more and more common for distro's to come with some tmpfs directories - usually /tmp. These wont be in /etc/fstab.

User avatar
RDK
Posts: 262
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: SD Card Corruption

Sat Jan 02, 2016 3:33 pm

Thanks. OK, I'll give it a shot ont he unit I working on right now....Rob

Return to “Beginners”