SD cards degrade slowly with use. Apparently, decent cards may use wear leveling to slow this down, so a card with a lot of free space should last much longer than one which is filled closer to capacity. This is probably true, to a much lesser extent, even if the card does not have wear leveling.
If you run the pi headless, regardless of how often you boot it, read Run at boot below carefully.
If you are leaving the pi on 24/7 for a long time and using the SD card often for storage, you should run a proper (-y) fsck on it at least a few times a week. These are usually very fast when done regularly. However, you cannot run fsck while the system is in use. Here's some options:
Run at boot
Linux systems are usually checked while the root fs is mounted RO during boot, which is safe. If your root partition entry in /etc/fstab looks something like this:
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
With a '1' (or anything not 0) in the 6th field (see man fstab), the system should do this automatically; raspbian does by default I think (actually I notice the first partition is set to fsck 2nd, which is silly since it is vfat). However, if fsck has to fix something and you are not sitting there at a monitor to say "yes", nothing will get fixed. With a headless pi, this is sort of pointless, so:
echo "-y" > /forcefsck
This will run
fsck -y (look at the man page about -y) at boot up. It will actually happen twice now, because of the fstab entry, which you can either change or (recommended by me) just leave it, since:
- the 2nd one will be instantaneous anyway (it was just checked)
- the system removes /forcefsck afterward
No. 2 is not a hard issue to resolve (but again, you might as well leave the fstab entry the same). Either remember to create /forcefsck again, or better yet, add that
echo line to
/etc/rc.local. When you reboot with a monitor plugged in, you should see something about "Checking local filesystems..." sandwiched between lines about remounting, that should happen TWICE.
You can also set this with a kernel option at boot, but that will not be a '-y' either.
Do it manually on another computer
Which is pretty simple, you just have to remember to do it regularly.
My recommendation is to set it up for boot as outlined above, remember to do a reboot every couple of days, and once a week or so take the card out and check it on a computer. I'm doing it when I take the card out to rsync the whole thing.