Page 1 of 1

data corruption & Raspberry Pi

Posted: Fri Feb 13, 2015 10:59 am
by per-SM
Hi everyone,

I use my pi to play music 24x7. It connects to internet every day to download new songs if its playlist has been updated. After a couple of months struggling with my pi freezing (ACT green solid) I realised that sometimes the new songs contained one or more corrupted blocks and once there are no backup blocks for corrupt blocks the drive is considered to be "falling"...

I tried to implement a fix to detect such cases, and remove corrupted files before they can cause any problem. This is how:

- All songs are in a second partition /dev/mmcblk0p3
- At boot, before the partition with the songs is mounted I run the following script.

Code: Select all

//  loops each song file and $line will contain the name of the i-th song
debugfs -R "ls -p /var/www/music" /dev/mmcblk0p3 | cut -d /  -f 6 | while read line 

// returns start and end block for $line song file
blocks = $(debugfs -R "ls /var/www/music/$line" /dev/mmcblk0p3 | sed -n 13p | grep -Po '(?<=:).*')  

block_start=${blocks%%-*}
block_end=${blocks##*-}

badblocks -b 4096 -nsv  /dev/mmcblk0p3 $block_end $block_start

if [ $? -ne 0 ] ; then 
   //remove song
fi

done
well, the code works just fine, but the problem is that even checking the filesystem on boot, before it is mounted will cause the system to crash, and I haven't been able to find any work around.

Any suggestions??

Re: data corruption & Raspberry Pi

Posted: Fri Feb 13, 2015 11:08 am
by RaTTuS
is the SD card failing ?
can you try with a complete new one

Re: data corruption & Raspberry Pi

Posted: Mon Feb 16, 2015 8:33 am
by per-SM
the SD card is fine. If i re-flash it, it works fine again, the problem is that there is always a chance of a corrupted bad block appearing whilst downloading a song, so unless I manage to implement a fix, this is a problem that can always appear and mess with my Pi.

Re: data corruption & Raspberry Pi

Posted: Mon Mar 02, 2015 3:17 pm
by per-SM
fyi: this is not a solution, but it'll save many the need to move to the RP to reboot it manually when it crashes due data corruption.

rebooter.sh

Code: Select all

#!/bin/bash

while [ 1 ]; do

	sleep 30

	/bin/pwd

	if [ $? -ne 0 ]; then
		echo 1 > /proc/sys/kernel/sysrq
		echo b > /proc/sysrq-trigger
	fi

done
then, you just need to add it to your root crontab:
@reboot /directory/rebooter.sh

hope it helps someone! it took me a while to figure this out :D

/per