# Bake my Pi and eat it too?

Do you ever wake up too early and can’t get back to sleep, so you decide to mess around with your Raspberry Pi, only to find out that the SD card has been baked and the operating system doesn’t load? This seems to happen to me more often than I’d like (both the waking up early and the baked RPi). There must have been something in that instant coffee (didn’t want to wake my wife with the noise of the coffee machine) and Italian Sweet Creme flavored creamer (instant coffee tastes awful without it) because I was able to come up with a reasonably clever solution to my problem this time.

I noticed some odd behavior on my RPi, so I decided to reboot it, at which point I started seeing lots of errors in the boot sequence and fsck was doing much more work than I like to see it do. The system rebooted itself automatically a couple of times until it finally tried to start X, at which point it would hang. Naturally, the last backup I’ve made of this RPi was in October of 2015, and I couldn’t even remember if there was stuff on the RPi that I wanted to keep. So here’s what I did.

Step 1 make a backup. I used the trusty win32diskimager to create an image of the (broken) Raspberry Pi
Step 2 fresh install. Well, not a completely fresh install, since I have purposefully made an image file called kamino base which I use to create clones (get it?) of my RPis.
Step 3 make the image file accessible to my network. I have a cloud drive that is little more than a linux box with some NFS mount points, so I moved rpi-broken.img to an accessible directory. Next came the tricky part. the .img file isn’t easily mountable since it has two partitions (the WIN32 boot partition and the linux partition). Since I want the linux partition, I needed to follow some directions in order to make it work. I didn’t need to make any tweaks to the recommendations and my process looked like this:

# make two temporary directories, one to mount the directory where my .img file is and one to mount to mount the file itself.
mkdir ~/tmp1
mkdir ~/tmp2
# mount the nfs drive
sudo mount <ip>:<dir> ~/tmp1
# now check for the offset of the 2nd partition
fdisk -l <path>/rpi-broken.img
# use the output provided to set the offset
sudo mount -v -o offset=62914560 -t ext4 <path>/rpi-broken.img ~/tmp2

Done! I’m not sure where the problem is with this image, but fortunately, it is not in my home directory and I can grab some of my projects that weren’t backed up. And, as an added bonus, my wife just woke up so I can make a real pot of coffee.