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

Corrupt SD card -- guide

Mon Nov 30, 2015 3:05 pm

If there isn't one on this site, there should be. That is, an easy to follow tutorial on how to fix (or attempt to fix) a corrupt SD card that won't boot. And I mean -- do this, now do this and do this, See spot run?

I simply had a power outage and now I'm screwed because the PI won't boot and certainly I'm not the only one who has encountered this. I see no guide on this site for this or even a "troubleshooting" section for that matter. Food for thought?
(Getting a "non blocking pool initialized" and stuck there).

I was told on another forum to "check the card in another linux machine" but when it comes to things like this (I'm worried sick about it) -- the issue shouldn't be so VAGUE.

I have googled here and there and have read way too many paragraphs (with conflicting info) about how to go about fixing a corrupt SD card. Use Fedora instead of Ubuntu because no "password hassle", all sorts of FSCK instructions with conflicting command lines, I've seen a paragraph of instructions and whole pages of shit all saying different things about it.

Is there something on this site (or somewhere) that will GUIDE me through the process?

Seriously -- there should be. -- thank's very much for any help.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 3:53 pm

Reinstall the OS to SD and use any valued data from your backups

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 4:18 pm

fruit-uk wrote:Reinstall the OS to SD and use any valued data from your backups
I understand the OP's frustration when this is the sort of reply they get.
(Yes, I do realize that this is the standard advice given on the board, but it is still annoying)

What I really don't understand is how cavalier Pi people are about "Well, it's gonna break every so often, so you gotten keep everything backed up and be ready to re-install from scratch at the drop of a hat", then I compare this attitude to the situation on things like cell phones, tablets, Kindles, iPads, TV set top boxes, etc. These things are the same general class as the Pi is or is supposed to be. Yet these things don't routinely break. They are appliances, expected to run without any user intervention for years. And, except in very rare cases, they do.

P.S. For what it is worth, I've never had a Pi SD card go bad on me. Knock wood and all that...

P.P.S. In fact, based on my experience, I suspect that most "card corruption" problems are, in fact, "user error" problems. So, the "just re-install" advice is actually not so bad...
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)

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 4:35 pm

Yes -- and maybe backup should be in bold print. Actually, based on previous experience with removable memory I hadn't thought of it as being that important -- after all, removable memory is often "what you backup to". So, I hadn't backed up some very important work (took months) and besides, where on a PI do you backup to? You have one SD slot and usually the USB hubs are being used.

PLEASE -- if someone can take this issue seriously and write a simple tutorial (or point me to one) to see if I've lost my data.

Had some very important files that I need to recover.

If a PI can't handle a power outage that is a real problem if you ask me.

User avatar
RaTTuS
Posts: 10493
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 4:40 pm

if you dont have a linux bot to hand and you have a usb to micro sdcard adapter
then
take a fresh SDcard and burn raspbian on it
boot the system
plug the bad sdcard into the sdcard adapter
then
sudo fdisk -l
does this show the sdcard ?
then mount the relevant drives i.e.
sudo mount /dec/sda4 /mnt
ls -l /mnt
if you don't have an sdcard adapter - got and get them they cost practically nothing
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 4:48 pm

Second link from a google search for..
raspberrypi sd card recovery
https://raymii.org/s/blog/Broken_Corrup ... _Card.html Is that any help?

If it works perhaps you could write a guide here.

Anyone who has valued data needs to think seriously about how to take care of it in case of failure. That applies to PCs with HDDs as well as data on SD

I am surprised that people are not more aware of sudden poweroff isssues re. data storage. It happens on HDDs as well as flash memory. It can happen in cameras, phones, anything that uses it.

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 4:55 pm

mmkw43,

Be prepared for the fact that this might be a lost cause.

Basically I would do as RaTTus suggests.

However I wold take the precaution of mounting your suspect card as read-only. When a drive is mounted it is normally written to, if only to update the mount time. We don't want any writing to happen that may cause more corruption.

So mount the card with the -r option:

$ mount -r /dev/sdx /mnt

Where "x" is whatever the previous fdisk said it was.

Don't worry about fdisk writing to your valuable card. It won't do that unless you tell it to.

If that mount command fails you may be in trouble and perhaps an "fsck" will be required to "fix" it before it can be mounted.

Come back here if that happens. fsck will normally make your file system usable again but may lose some files as it does so.
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 36322
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 5:05 pm

The plan from RaTTuS is my recommendation.

Ideally you should never need to do what RaTTuS suggests if you plan a coherent backup strategy. Again using a £1 USB SDCard reader it's not difficult to backup a running SDCard to a second copy. Use dd and you get a bootable copy. Use rsync and you get a file by file copy, use both and you get best of both worlds. SDCards are cheap. You can also backup to a USB stick. USB sticks are cheap.

Every two months I go round all eight RPis and take a dd backup to my 2TB NAS (it's no a quick process). That NAS hold other critical data (including all the /home directories and /srv/www for my websites) so every month I back it up with rsync to a Drobo. The Drobo backup also includes my dd'd images.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 5:10 pm

When you guys figure it out, let me know.

Now I'm really worried -- months of code written in Python.

Until I have the confidence to try something else, I'll follow ratt instructions. Leaving it till tomorrow -- [Mod edit - language!]

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 5:12 pm

by the way, thanks for the details heater on what ratt proposes

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 5:13 pm

didn't mean to be smartalec -- misread what doug had siad

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

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 10:17 pm

Ok you guys -- fdisk shows the SD card. I have another PI(2) setup and a USB sd reader attached.

I'm afraid to go further without your specific instructions however -- rather confused about the actual command I need to use.

At the end of fdisk here's what it says --

size id
/dev/sda1 800.9m e w95fat16
/dev/sda2 14.1g 85 linux extended
/dev/sda3 32m 83 linux
/dev/sda5 60m c w95fat32
/dev/sda6 14g 83 linux

I'm really out to lunch on this other than knowing these are partitions -- what do I do next?

Is it a good sign the card was recognized ? please say yes

And THANKS very much -- I'm shaking like a leaf because of all this. Nervous as hell.

Milliways
Posts: 465
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 11:17 pm

mmkw43 wrote:Is there something on this site (or somewhere) that will GUIDE me through the process?
The reason there isn't a guide is because there is no simple process. Experienced Linux users know how to try the various recovery options, but usually don't because they backup important data.

The following outlines the procedures I use. http://raspberrypi.stackexchange.com/a/37850/8697

If you don't have a backup, you could try recovering files from the SD Card.

I can suggest a strategy:-
1. Get a new SD card and perform a clean install.
2. Mount the old SD Card (using a USB adaptor).
3. Use `rsync` to copy files from the old card to the new. This can be done selectively if e.g. only user files are to me recovered.

A suggested command line (which will need appropriate paths) is

Code: Select all

 sudo rsync -avH /mnt/PiData/JessieBackup/ /
This will probably give errors is there are corrupt files.

Milliways
Posts: 465
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 11:26 pm

mmkw43 wrote:Ok you guys -- fdisk shows the SD card. I have another PI(2) setup and a USB sd reader attached.

I'm afraid to go further without your specific instructions however -- rather confused about the actual command I need to use.

At the end of fdisk here's what it says --

size id
/dev/sda1 800.9m e w95fat16
/dev/sda2 14.1g 85 linux extended
/dev/sda3 32m 83 linux
/dev/sda5 60m c w95fat32
/dev/sda6 14g 83 linux

I'm really out to lunch on this other than knowing these are partitions -- what do I do next?

Is it a good sign the card was recognized ? please say yes

And THANKS very much -- I'm shaking like a leaf because of all this. Nervous as hell.
This looks like NOOBS disk

Code: Select all

/dev/sda6
looks like your Linux partition, but doing a

Code: Select all

ls -la /dev/sda6
should confirm this.

See my other post. Use

Code: Select all

sudo rsync -avH  /dev/sda6 /
PS IMPORTANT the above is to recover to a clean SD. The worst you can do is corrupt it. Don't try on a working install.

User avatar
DougieLawson
Posts: 36322
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 11:36 pm

Before you start damaging anything just try this, ignore any error messages
for i in a1 a3 a5 a6; do sudo fsck -f -y /dev/sd$i; done
swap the cards back and see if the borked card boots OK.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

gordon77
Posts: 4237
Joined: Sun Aug 05, 2012 3:12 pm

Re: Corrupt SD card -- guide

Mon Nov 30, 2015 11:42 pm

If you are looking for a python py file can you see /home/pi on the old card (in the adapter) using filemanager (from the x gui)?

If so can you copy it to your new card?

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

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 12:03 am

I looked at it in file manager first thing and it just showed --

PI folder with subfolders boot, settings and settings 1

boot folder has subfolder overlays and some non py files (which is what I'm after)

settings and settings 1 both have a folder called lost and found with nothing and some other non py files

?

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

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 12:05 am

thanks doug -- I'll try that in the morning. -- getting late, better start fresh.

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

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 2:28 am

Doug -- Thank you so very much ! ! ! ! ! (and all the other help) -- I did the fsck like you said on all the partitions and then put it back in my original PI and it wanted to boot or at least it didn't stall but went into a blank screen -- waited over an hour and nothing. So I put the card back in the reader on the new PI and the files showed up in file manager ! !

Man was I at a low -- I could kiss you but I'd have to be drunk first. THANKS ! YIPPIE !

You guys are great.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Corrupt SD card -- guide

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.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 4:48 am

ame wrote:
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.
'Print/echo "hello world" ' is a hard important code you need to always have a backup for that.
:twisted:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

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

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 5:39 am

I think mmkw43 will have learned the BACKUP YOUR STUFF lesson from this experience far better than anything we can say now.

Remember folks BACKUP YOUR STUFF !

@mmkw43,

If you have 4 months of coding in any language you might like to think about keeping it in a version control system like github or bitbucket or even just use git on your local machines.

git is not a backup solution by itself but it makes it dead easy to "clone" your code to multiple machines and keep track of all your revisions. It gives me great peace of mind know that it''s almost impossible for me to lose even one line of code even if I delete it from file myself!

Having all my revisions neatly numbered and commented means I can easily go back and see what I was doing and where I might have broken a feature.
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 36322
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 9:16 am

Heater wrote:git is not a backup solution by itself but it makes it dead easy to "clone" your code to multiple machines and keep track of all your revisions. It gives me great peace of mind know that it''s almost impossible for me to lose even one line of code even if I delete it from file myself!
I'm running Gitolite http://gitolite.com/gitolite/index.html and Gitweb https://git.wiki.kernel.org/index.php/Gitweb on one of my Raspberries for exactly that reason.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

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

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 9:49 am

Any particular reason you don't just let github or bitbucket take care of that?
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 36322
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Corrupt SD card -- guide

Tue Dec 01, 2015 10:14 am

Heater wrote:Any particular reason you don't just let github or bitbucket take care of that?
Because it's stuff I don't want to put out on someone else's computer (aka the cloud). My gitolite repo is on my 2TB NAS so gets backed up to my Drobo every month.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “General discussion”