Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

my raspberry pi had been running smoothly for the last few months. i leave it on always as it is my subversion server, among other things. the other day i unplugged the ethernet cable and plugged it back in. it worked after this still, however i noticed some errors when i ssh-ed into it - from memory i think the ~/.xsession file could not be read. i tried rebooting and since then it has not been able to boot up. the red light comes on straight away when i put in the microusb and the green light flickers about 5 times then goes off permanently.

can anyone point me in the direction of a diagnosis? i have a multimeter so i can post more info if required.

more info

  • i bought the sdhc card brand new when i bought the raspberry pi. it is 32gb, class 10.
  • all of my data is stored on an external hard drive
share|improve this question
    
Sounds like filesystem errors, ie. the SD card is going. How old is it, what is the capacity, and how full is it? Also, how much subversion data do you think you transfer everyday? Is that on the SD card or an external drive? Finally, put the card in another computer and run fsck on the 2nd (ext) partition. –  goldilocks Feb 18 '13 at 0:58
    
thanks for the info. i will run fsck and report back –  mulllhausen Feb 18 '13 at 1:17
    
i have run fsck against the ext partition. it did two rounds and altered a lot of inodes and did a lot of fixes. now the ok light comes on green. i will test ssh when i get home later. –  mulllhausen Feb 18 '13 at 5:22
    
its working now :) i can ssh in. any ideas for preventing this in future? –  mulllhausen Feb 18 '13 at 9:22
1  
Yeah. I fleshed that out into an answer ;) –  goldilocks Feb 18 '13 at 18:13

2 Answers 2

up vote 4 down vote accepted

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:

  1. the 2nd one will be instantaneous anyway (it was just checked)
  2. 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.

share|improve this answer
    
i never realized you could simply put a file called "forcefsck" in the root directory and it would cause the machine to run fsck on next boot. very useful, thanks. –  mulllhausen May 27 '13 at 0:50

another thing that worked as a quick fix was to take the sd card out and plug it into a windows machine, then run

chkdsk /X /F G:

(G is the drive letter that windows automatically mounted the sd card at, found via "my computer")

share|improve this answer
    
Windows can only see the boot partition which is formatted as FAT. This won't help with the second ext4-formatted root partition. –  Lekensteyn May 27 '13 at 7:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.