Fixing a RaspberryPi raspian SD Card

Recently I ran into an issue with my Rasp­berry Pi. It was not acces­si­ble over the net­work and the HDMI out­put showed no sig­nal, too. The power LED on the RPi was lit, how­ever the green LED show­ing SD card activ­ity was not blink­ing when power was attached.

On my RPi I was run­ning the Debian var­ian Raspian how­ever it failed to boot. So I fired up a Debian PC and looked into the SD card. On the SD card there are two par­ti­tions as shown by fdisk:

Disk /dev/sdg: 15.8 GB, 15811476992 bytes
64 heads, 32 sectors/track, 15078 cylinders, total 30881791 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c7b31
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/sdg2          122880    30881791    15379456   83  Linux

First, a small 8 MB FAT32 par­ti­tion which stores the boot­loader and the ker­nel image and then a larger ext4 par­ti­tion which is expanded on instal­la­tion to fill up the remain­ing space on the SD card (mine was 16 GB large).

Fine, so let us try to mount the sec­ond par­ti­tion to recover some data: mount -t ext4 -o ro /dev/sdg2 /media/sd but with­out luck, this was the output:

mount: wrong fs type, bad option, bad superblock on /dev/sdg2,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

I did was I was told to do and checked the ker­nel logs using dmesg | tail. The last entry showed some­thing interesting:

[  707.493811] EXT4-fs (sdg2): bad geometry: block count 3844864 exceeds size of device (3844863 blocks)

Hmm, some­thing is wrong with the par­ti­tion, so let us run good old fsck /dev/sdg2 but this rose an error, too:

fsck from util-linux 2.20.1
e2fsck 1.42.5 (29-Jul-2012)
/dev/sdg2: recovering journal
The filesystem size (according to the superblock) is 3844864 blocks
The physical size of the device is 3844863 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? yes

So the par­ti­tion is cor­rupt, or at least the super block as it reports the wrong size. So maybe we can resize the par­ti­tion instead using resize2fs /dev/sdg2 which gave the promis­ing output:

resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sdg2 to 3844863 (4k) blocks.
The filesystem on /dev/sdg2 is now 3844863 blocks long.

After this I was able to mount the par­ti­tion using mount -o ro /dev/sdg2 /media/sd. I unmounted it and reran fsck /dev/sdg2 on it which found some orphaned nodes and repaired it. I could then rein­sert the card into my RPi and it booted and worked!

Please note: Your milage may vary as it can­not be made sure that data integrity is still OK. This would be pos­si­ble with check­summed file sys­tems like ZFS or but­trfs. It is always a good idea to have a backup.


New Beefy Storage Home Server — Part 1

The Aim After using my com­put­ing equip­ment for some time my desk got filled with 3 exter­nal hard dri­ves con­tain­ing back­ups and archived data such as videos, pho­tos. Even worse these dri­ves spin down after a while result­ing in a 6 sec­ond lag when open­ing a file open or save panel. Fur­ther­more the use of […]


Simple Samba Configuration for Public Shares

The Aim Some­times it is nec­es­sary to share files from a POSIX oper­at­ing sys­tem (Linux, FreeBSD, etc.) with Win­dows com­put­ers via the net­work. For this task Samba is the pow­er­ful inter­op­er­abil­ity suite which can han­dle this task. To dis­tin­guish between these two sys­tems I will dif­fer­en­ti­ate between POSIX (that is the samba server) and Windows […]


Writing a Parser Is Boring?

When inter­act­ing with dif­fer­ent ser­vices or pro­gram there often comes the point where some sort of file has to be parsed into a data struc­ture, which can be processed later. For stan­dard file for­mats like XML or JSON parsers are avail­able for almost any lan­guage out there. (BTW I love the graph­i­cal rep­re­sen­ta­tion of the […]


Dancing the DHCP Samba

After a hard­ware fail­ure of a Linux com­puter I took the chance to set up a Debian instal­la­tion from scratch. So I saved the data that was impor­tant to a server, burned the Debian DVD and installed it on the com­puter. When it came to net­work­ing it got a lit­tle more com­pli­cated: as the server […]


Deploying a Wireless Network in Your House

The rise of mobile elec­tronic devices, which need inter­net access has changed the demand we have on our home net­works. The days are over where one had a sin­gle com­puter con­nected with a wire to the broad-band inter­net modem. WLANs became very pop­u­lar because net­work client became more mobile. It started with the note­books with […]


Neuer Löwe im Käfig

Seit gestern ist es draussen, das neue Mac OS 10.7 Lion. Das erste Release, dass nur noch online zu beziehen ist. Auf der einen Seite ist das sicher­lich pos­i­tiv, allerd­ings wenn man eine nicht sooo bre­it­bandige Inter­netverbindung hat, kann der Down­load zur Geduld­sprobe wer­den. Ich werde in einer kleinen Serie von Beiträ­gen berichten, wie die […]


Chrome OS — News von der Google I/O 2011

Am zweiten Tag der Google I/O 2011 wur­den in der Keynote einige Neuerun­gen in Googles Chrome Browser und in Chrome OS vorgestellt. Der Unter­schied zwis­chen diesen bei­den besteht darin, daß es sich bei Chrome OS um ein kom­plettes Betrieb­ssys­tem han­delt, in nur eine App­lika­tion läuft: ein Chrome Browser. Um noch einen weit­eren ähn­lichen Namen hinzuzufügen […]


Solarized — A Balanced Color Scheme for Text Editors

Col­ors schemes for text edi­tors is just like the favorite edi­tor itself a con­tro­ver­sially dis­cussed and often very per­sonal mat­ter. Speak­ing about col­ors often the per­sonal taste is the main rea­son for a cus­tom color scheme or why a spe­cial scheme was cho­sen. How­ever the rela­tion between dif­fer­ent col­ors has been stud­ied by artists for […]


Backing up a Server to Amazon S3

Moti­va­tion When deploy­ing a server on the inter­net you always have to deal with secu­rity issues. You harden your server by set­ting up encrypted con­nec­tions, con­fig­ur­ing a tight fire­wall and putting crit­i­cal ser­vices in a chroot jail. How­ever what hap­pens if an intruder hacks into your server and deletes your con­tent? Or if you make […]