Tuesday, July 2, 2013

After Disaster!

My Raspberry Pi
(if you are new to the site you might want to scroll back a ways)

Lady Bracknell: To lose one parent, Mr. Worthing, may be regarded as a misfortune.
To lose both looks like carelessness.
The Importance of being Ernest,
by Oscar Wilde

Lady B. would have chided me, too. I managed to crash the Linux filesystem on my Pi's SD card. Again! But this time I had a backup image of the entire 16gb card and I have copied individual files back to my iMac, occasionally. But not often enough. My SD image was a month old and the last time I copied files was a week ago.

You might ask, "Why did your Pi's filesystem go bad?" Because I was plugging wires from the GPIO pins to my breadboard while the Pi was powered up. Bad idea! I saw the Pi reboot -- must have grounded a power wire. Afterwards I couldn't talk (via SSH) to the Pi. When I say I "saw" it restart, I mean that the status LEDs went dark and then only the PWR light stayed on. Here's what my LEDs look like, normally:


The REAL info on the Pi's status LEDs:
http://elinux.org/R-Pi_Troubleshooting

Anyway, my SD card backup/restore procedure:

From my Mac's Terminal app (PCers use Putty)--

Backing Up

- Shutdown your Pi
- Pull the SD card and plug it into your USB flash memory reader
- Determine what the device name that has been assigned to your SD using diskutil:
   $ diskutil list  (you should be able to tell by the size in GB)
- Then you have to unmount it:
  $ diskutil unmountDisk /dev/disk2 (yours may not be "disk2")
- Now the copy -- you have to be superuser (be very careful):
 $ sudo dd if=/dev/rdisk2 of=raspberry-pi-backup.img bs=1m

Note I copied from the "raw" device (rdisk2) instead of the "block" device -- it's faster. Also, I used "bs=1m" (block size = 1MB), also faster. When I say faster -- the difference for a 16gb SD versus using "bs=1024" is 6 hours!

Restoring (with care you may never have to)

- Plug the same sized SD card into your flash reader (it's good to have a spare)
- Find the /dev name (diskutil list, as above)
- Also like the above, do the unmount
- Now the copy swapping "if" and "of" (in-file & out-file)
 $ sudo dd of=/dev/rdisk2 if=raspberry-pi-backup.img bs=1m

More about the limitations of copying individual files back to the SSH host: You can't usually copy system updates or things like crontab entries. If you don't know about crontab, you should! Try--
  $ man crontab


No comments:

Post a Comment