anaTech
Posts: 2
Joined: Tue Dec 04, 2018 9:00 pm

Data Retrieval from corrupted file system raspberry pi SD card

Tue Dec 04, 2018 9:30 pm

I am facing issues regarding data retrieval from raspberry pi 3. We have been using it for stem outreach and due to abruptly shutting down of the pi it's not booting up. However I was able to get into safe mode and check that all the data we need is present on "/home/pi" location. It's not configured for wifi connection so can't connect to it over wifi either.

After that I used a working raspberry pi operating system SD card and tried to access the SD card which is not booting anymore as a external device to the working one. I am using a sd card reader to plug the SD card which is not working to the working raspberry pi. However, i am not sure how to mount and access the data from the SD card through terminal. I observed that the permission shows "brw" on /dev/sda. Could somebody please help me out with how can I access files on raspberrypi zero SD card (which is not booting) at "/home/pi" folder through another raspberrypi operating system.
Attachments
20181204_150916.jpg
20181204_150916.jpg (52.97 KiB) Viewed 115 times
Last edited by anaTech on Thu Dec 06, 2018 8:48 pm, edited 1 time in total.

ghans
Posts: 7819
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Data Retrieval from corrupted file system raspberry pi SD card

Wed Dec 05, 2018 9:04 am

Do not try to upload photos here (heavy filesize restrictions), use imgur.com instead.

What you want to do is following:

1) Make an image backup of the old card with dd (You need enough free space).

Code: Select all

sudo dd if=/dev/sda of=/path/to/imgfile.img bs=4K
If you don't have enough space you can skip to step 4 on your own risk - you can't fsck a card whose internal logic has switched to permanent protective readonly mode (Yes, this really happens).

2) Unplug the old card.
3) Let the devicemapper create loop devices (one per partition) from the image file:

Code: Select all

sudo kpartx -av /path/to/imgfile.img
Note the names of the loop devices.
4) Mount them.

Code: Select all

sudo mkdir /mnt/sdcard
sudo mount /dev/mapper/loop0pXX /mnt/sdcard
XX is the partition number. You want the second (full with Linux and your data).

The real SD card itself is likely to be called /dev/sda. /dev/sda1 is the first partition, /dev/sda2 the second one etc.

You should be able to read everything by now. If the mounting fails, try fsck'ing it first. It needs the name of the loop device/real partition.

Code: Select all

fsck -v /dev/mapper/loop0XX
Cleaning up:

Code: Select all

sudo umount /mnt/sdcard
sudo kpartx -dv /path/to/imgfile.img
You can now delete the image file if you wish.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

anaTech
Posts: 2
Joined: Tue Dec 04, 2018 9:00 pm

Re: Data Retrieval from corrupted file system raspberry pi SD card

Thu Dec 06, 2018 9:03 pm

Thanks for replying to my post.

I tried to run the first command to make image backup of the old card but it is giving me below error:
dd: failed to open '/dev/sda': No medium found

Also, do we need to create the empty ".image" file at the location we want first?

I really appreciate your help. I hope we can retrieve the data soon.

User avatar
Joel_Mckay
Posts: 177
Joined: Mon Nov 12, 2012 10:22 pm
Contact: Website

Re: Data Retrieval from corrupted file system raspberry pi SD card

Fri Dec 07, 2018 12:38 am

Power brown-outs during a write operation can damage some sdcards at the hardware level, and even a surface test may not necessarily show the failed writes. You could use F3 (Fight Flash Fraud) on the pi to flood the drive capacity with pattern files to check for errors ( http://www.micrometer.xyz/cdn/node/78 ).

Either way, personally I found there were several subtle bugs upgrading to Stretch, and would recommend starting with a clean Raspbian image as importing your package selections will be faster than resolving the migration issues. Or if power outages are unavoidable, maybe look into the OverlayFS read-only root + ram drive method like what we use on our club's Raspbian kernel.

Check your card on another desktop:

Code: Select all

sudo umount /dev/sdb1
sudo umount /dev/sdb2

sudo dosfsck -w -r -l -a -v -t /dev/sdb1

sudo e2fsck -y /dev/sdb2
sudo fsck.ext4 -cDfty -C 0 /dev/sdb2
Remove the card, and boot from the card to do a OS binary repo-sig check.

Code: Select all

sudo debsums -sac
We have piles of glitched up cards around, that have proven unreliable even after being "repaired". I noted the defects are usually in high-wear areas like the swap file, journal, and or a busy path like /var/log .
We use the SanDisk cards, and it is mostly because they seem slightly more resilient.

To be honest, I usually replace "weird" behaving hardware as fast as possible ;-)

Cheers,
J

fruitoftheloom
Posts: 17838
Joined: Tue Mar 25, 2014 12:40 pm

Re: Data Retrieval from corrupted file system raspberry pi SD card

Fri Dec 07, 2018 3:11 am

anaTech wrote:
Tue Dec 04, 2018 9:30 pm
I am facing issues regarding data retrieval from raspberry pi 3. We have been using it for stem outreach and due to abruptly shutting down of the pi it's not booting up. However I was able to get into safe mode and check that all the data we need is present on "/home/pi" location. It's not configured for wifi connection so can't connect to it over wifi either.

After that I used a working raspberry pi operating system SD card and tried to access the SD card which is not booting anymore as a external device to the working one. I am using a sd card reader to plug the SD card which is not working to the working raspberry pi. However, i am not sure how to mount and access the data from the SD card through terminal. I observed that the permission shows "brw" on /dev/sda. Could somebody please help me out with how can I access files on raspberrypi zero SD card (which is not booting) at "/home/pi" folder through another raspberrypi operating system.

https://en.wikibooks.org/wiki/Linux_Gui ... mmand_Line
Adieu

ghans
Posts: 7819
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Data Retrieval from corrupted file system raspberry pi SD card

Fri Dec 07, 2018 6:30 am

@anaTech

Why are you working with /dev/mmcblk0pXX ? That is obviously the internal SD card which
is currently in use. The SD card in the reader should be called differently. To make sure, unplug the reader with card and replug it.
Now

Code: Select all

sudo dmesg | tail
should show you the name of the external SD card after it has been autodetected.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “Troubleshooting”