mmkw43
Posts: 544
Joined: Tue Dec 24, 2013 6:18 pm

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 2:28 pm

Looking back on this I think the help page or video (whatever) I was looking for initially was what Doug ended up telling me to do. (thanks again Doug).

Obviously, a corrupt SD card CAN be complicated but from what I'm reading more often than not FSCK is probably going to get you out of it? (I see that in many posts). So, whether that will work or not, at least it's a good starting point and it's simple to do.

So why not have a troubleshooting section somewhere on this site or maybe just an obvious section somewhere saying? --

"Pi won't boot ? Corrupt SD card? -- try this"

(1) Make another Raspian SD boot card
(2) Put bad SD card in USB card reader
(3) Boot PI with new card
(4) In terminal, run FDISK -l
(5) Make note of the bad cards partitions ie /dev/SDA1 etc
(6) In terminal run For i in a1 etc etc (the command Doug gave me)
(7) Shut down PI
(8) Put faulty card in PI and attempt to boot
(9) If boot fails (give it plenty of time), shut down PI
(10) Put new SD card back in PI and the faulty card in USB card reader
(11) Boot PI -- go to file manager and cross your fingers

I'm just saying that if that had been listed somewhere, (like I mentioned in the first post) I could have been in and out in 15 minutes.
I'm guessing if the above doesn't work, chances are you're screwed.

Anyway, my next learning curve will be a better understanding of why an SD card can do this to begin with -- my impression has been that electronic memory (non moving part non magnetic) is stable. Once you "Save" you're in good shape. But I'll find out in an electronics design group I follow. I kept blowing off backing up because I had the PI B ports all utilized. Never again obviously.

So weird -- I had literally just done my last bit of code on something probably 5 or 6 pages long and the power went off.

God screwing with me again.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 3:06 pm

Yes, I think that's a good summary. One more point.

If you absolutely know that some particular text is there, but you can't find it any of the files recovered by fsck (or if fsck just doesn't work), then there is one more thing to try. This is specifically when you are looking for one particular block of text - which was the case when I needed to do this.

My situation was that I had been running Raspbian off of a USB flash drive, and the flash drive went bad (while the system was running). After shutting down and doing all the usual things to try to retrieve one particular file, I ended up doing (something like):

# less < /dev/sdb

and just pawing through it (which was long and lots of bad junk - since the flash drive was 8G), but I did eventually find the text I needed.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Heater
Posts: 13656
Joined: Tue Jul 17, 2012 3:02 pm

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 3:51 pm

Oh yeah, trawling though disk blocks trying to find lost data. Fun, fun fun...

Don't forget the "strings" command. Helps to get the textual data out of a lot of binary gunk. For example:

Code: Select all

$ strings /dev/sdb | less
Memory in C++ is a leaky abstraction .

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 3:57 pm

Heater wrote:Oh yeah, trawling though disk blocks trying to find lost data. Fun, fun fun...

Don't forget the "strings" command. Helps to get the textual data out of a lot of binary gunk. For example:

Code: Select all

$ strings /dev/sdb | less
Yeah, I think that is actually what I did (using strings to filter out the obvious garbage). I couldn't quite remember which command I ended up using.

Note, BTW that you do have to run this as root in order to have direct access to the device.
So, your prompt should be "#".
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

vivelibre
Posts: 1
Joined: Thu Aug 03, 2017 2:42 pm

Re: Corrupt SD card -- guide

Thu Aug 03, 2017 2:48 pm

Hello guys I have to work with a lot of raspberryPi and I found something use full for those cases that when SD card can start in Rbpi I just have to plug into my SD card slot for my computer system (Windows operative system) then just open the SD as files and finally remove safely once that I finish this I just insert the SD card into the rbpi again and start working as usual

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

Re: Corrupt SD card -- guide

Thu Aug 03, 2017 3:57 pm

ame wrote:
Tue Dec 01, 2015 2:44 am
mmkw43 wrote:Now I'm really worried -- months of code written in Python.
You only have one copy of months of work?

If it was important you'd have several copies in several different places.
Decades ago, a PHD student came to me with a problem, his thesis which he had spent 3 years working on, was on a computer - and the hard disk failed! No backups, nothing.
ame wrote:
Tue Dec 01, 2015 2:44 am
If it was important you'd have several copies in several different places.
Definitely. Consider the problems if a fire destroyed the building and so on.
The cloud helps with that apart from the obvious privacy issues. A USB drive with the backup on, saved with a friend or relative works too.

Gadgetguy
Posts: 100
Joined: Fri Aug 15, 2014 2:55 am

Re: Corrupt SD card -- guide

Thu Aug 03, 2017 6:36 pm

A very quick gui-based solution for file system corruption that prevents rebooting and which worked for me is to use gparted, which is in the Raspbian repository. After many many months of using a very nice super fast sandisk extreme sd card -during which time I had regularly unplugged my pi whenever it froze( usually too many tabs in web browser) and never had had a problem with it not rebooting( although the boot screen often indicated it was checking and fixing the file system) today I was dismayed to find my pi simply would't reboot. I didn't have too much stuff on it that I hadn't backed up but I did have some. Moreover it was fully up to date.

On one of my windows computers I have a couple of linux file reading utilities that will let me read and copy linux files but this computer was temporarily unavailble to me. So I rebooted the pi with another sd card that was running Raspbian, and stuck the problem sd card into a usb adapter. I was unfotunately unable to read any of the files on the problem sd card's ext4 system which was reported as being corrupt. I then loaded gparted , navigated to the problem device in the drop down menu in the top right corner. I noted the ext4 partition was flagged as corrupt. In the right-click context menu there is a command called check which checks and attempts to repair the file system. I clicked it and applied the command in the edit menu. I ejected the sd card and reloaded it in the pi and voila it rebooted. It is probably a bit of a leap of faith and it would be best to copy beforehand any files off the corrupt sd if this is possible. However this solution worked for me and may prove useful to others.

No doubt this makes me a linux heretic but I prefer if possible to use a gui based solution to problems rather than using the terminal to type in cryptic and dangerously powerful linux commands I may or may not understand.

ranjo2721762
Posts: 1
Joined: Thu Dec 07, 2017 7:40 am

Re: Corrupt SD card -- guide

Thu Dec 07, 2017 7:44 am

If you have a digital camera use it's format sd card feature and it will format it and solves the problem. I did it several times and you don't have to buy a program to fix your sd card.

Heater
Posts: 13656
Joined: Tue Jul 17, 2012 3:02 pm

Re: Corrupt SD card -- guide

Thu Dec 07, 2017 11:24 am

Yes, but that totally obliterates any data you had on the SD card.

It does not fix the file system corruption, at least well enough to boot from the card or salvage some files by mounting it on a running Linux system.

Also note that if your card is working properly, it's only you file system(s) that are scrambled, then it is not necessary to format it before writing a new Raspbian or other image to it. That operation does not care about whatever format is on there beforehand.

Also, I and many others have experienced card failures where they become wholly or partially write protected. At which point no amount of formatting by anything will fix it.
Memory in C++ is a leaky abstraction .

divya.bhargava
Posts: 2
Joined: Fri May 11, 2018 10:03 am

Re: Corrupt SD card -- guide

Tue Jul 24, 2018 10:08 am

Hi All, Lets make it simple, insert your SD card in any linux based os machine with GUI like 7 centos . and you can browse through the folders and copy/ backup your data.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Corrupt SD card -- guide

Tue Jul 24, 2018 10:28 am

Also note that if your card is working properly, it's only you file system(s) that are scrambled, then it is not necessary to format it before writing a new Raspbian or other image to it. That operation does not care about whatever format is on there beforehand.
The "digital camera" advice - or, really, any method of formatting the SD card back to "normal" (aka, "Factory Default") - is generally given in the context of NOOBS (i.e., PINN), where it is important to format the card properly before putting the software (NOOBS/PINN) on it.

If you are using the advanced "raw image" method, then, of course, it isn't necessary.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

Heater
Posts: 13656
Joined: Tue Jul 17, 2012 3:02 pm

Re: Corrupt SD card -- guide

Tue Jul 24, 2018 10:58 am

I always advise against using NOOBS. Judging by the questions that pop up here all the time NOOBS seems to cause more confusion and problems than it fixes.

There is nothing "advanced" about copying an image to SD card. Especially now that we have Etcher.
Memory in C++ is a leaky abstraction .

NDemberger
Posts: 3
Joined: Thu Aug 09, 2018 4:57 pm

Re: Corrupt SD card -- guide

Sun Mar 31, 2019 6:44 pm

Hello Everyone,

My 2 Cents

I was just running into this issue again. It's happened a few times and at first, I didn't realize what caused the issue. But I eventually realized when my Pi's lost power unexpectedly they may not boot back up. I just did this on purpose for testing and found this to be the cause of my Pi's shitting the bed. To correct this I just booted my PC with the latest Ubuntu Desktop(Ubuntu 18.04.2 LTS) install disk, then inserted the "bad/corrupt" Pi's SD card, and browsed around the file structure, and then Ejected it. The SD card was then plugged back into the Pi, and now it works again.

This was tested with two Pi's running OctoPrint, tied to 3D printers.

FIX QUICK STEPS
1. Boot another PC with the Ubuntu 18.04.2 LTS install media (Install not needed)
2. Plugin the Corrupt/Bad SD card (With Pi install)
3. Browse to the SD card.
4. Eject SD card.
5. Plug into PI.


I hope this helps someone in the future.
-Nick

Return to “General discussion”