So the kids have cannibalised their Raspberry Pi's to get the USB cables to charge Kindles and goodness knows where the original Kindle charging cables are. This was some weeks ago and I only just got around to buying a replacement cable for them each.
(we seam to have suspicious lack of USB A to USB B micro cables but a large jar full of USB wall warts).
Plugged in the Pi and ... solid power and solid drive activity LED. Indicates the SD card is bad. Check the seating and other cables just in case but no, it is not happy.
Maybe a corrupt SD card, so I will just take it out and ... hmmm, it will not come out and it looks funny.
The micro SD cards normally have a little lip at the back so you can pull them out of devices, it is not there.
No, I mean it the whole 1mm of card where the lip is, is missing and there is bare metal peaking out of the plastic in its place.
Right the other Pi is fine so lets just get another SD card and clone it. Would be what I could do if, the working card was the same size as the new one. But that would be too easy. The old card is 16GB and the new one is 8GB. And, I know for a fact that the card has only used 4GB.
Hmmm (again). The Raspbian partitions are set up as a FAT boot partition and the main Linux
one. So I should be able to clone the boot partition as byte for byte as it's tiny, just 60M. The other one is just a collection of files. I should be able to build it empty and then just copy the files.
Lets try that.
is the SD card on my Linux box when attached with an USB SD card reader(it will almost certainly be different on yours, so be careful).
Delete the existing single partition and create a new primary
partition of 60M
. Set bootable
and the type to
c W95 FAT32 (LBA)
Then another primary
partition but allow it to use all remaining space. This one is set to type
Write the partition table and quit.
and with the source card found at /dev/sdd
copy the bytes/sectors of the boot partition from one card to the other.
dd bs=4M if=/dev/sdd1 of=/dev/sde1
are the first partitions on the two SD cards on my Linux box when attached with USB SD card readers(it will almost certainly be different on yours, so be careful).
Time to make the second partition ready for files
is the second partition on the SD card on my Linux box when attached with an USB SD card reader(it will almost certainly be different on yours, so be careful).
That done I need copy the raw files for the Linux partition.
Mount the two second partitions
(I have my /etc/fstab
set up to allow this)
and (as root)
cp -ax /mnt/sdd2/* /mnt/sde2/
are the second partitions on the two SD cards on my Linux box when attached with USB SD card readers(it will almost certainly be different on yours, so be careful).
is all properties and -x
is stay on a single file system, in case there was symlink to another)
Files are copied(took ages)
Plugged in Pi.
Power : CHECK
Activity LED : CHECK
Scrolling text : CHECK
This is going well. So I note how we got here and start putting the Pi in its case. The screen turns black as if the X desktop is about to come up and ...
1 minute passes and still a black/blank screen, uh oh. The screen starts to fill with EXT4 block errors. Groan, does this mean the transfer did not work?
Switch to console one CTRL+ALT+F1
and every command including shutdown
*face ---- no not yet
The bloddy/blimin/*@?X%! SD card has ejected while I was putting the case on!!
Re-seating it and re-powering the Pi and we have ... SUCCESS
The alternatives I read about involved running Gpartd
to shrinking the original source SD card and the dd'ing
the new shrunk card as we did for the boot partition.
Might have been easier but would have endangered to working SD card and to be useful would have required re-sizing after everything was working again.