Kernel Panic: VFS :Unable to mount root fs on unknown-block

From TheBeard Science Project Wiki
Jump to: navigation, search

I've been using a Raspberry Pi 2 with Raspbian on a 16GB SD card as a development platform for my Camera Security web app, and recently it stopped booting, produced a kernel panic with a very long output, and ended with something like:

[    5.392366] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)
[   10.560105] random: nonblocking pool is initialized

You'll notice that the second line came about 5 seconds later.

As many people on the internet suggested (for scenarios similar but not exactly like mine... of course) was that a parameter in the cmdline.txt file in the boot partition needed to be changed. This was not the case for me.

Instead, I discovered that my SD card essentially ran out of writes. I couldn't write anything to either partition. It's a micro SD card, so it doesn't have a physical lock switch. When I put it into an adapter to troubleshoot, I made sure the lock mechanism was unlocked. When that didn't work, I tried a different adapter. I was very confused at first because I could read from the card just fine. Finally, I just copied the entire card to another 16GB card (without making any changes to the boot configurations) and it just booted up immediately.

None of this surprises me now that I've thought about it. My web app writes tons of data to the card because it's capturing and storing camera images. I knew this would be taxing on the SD card, and I indented to use a USB hard drive for writing data, but I got lazy and never got around to it. Luckily, it didn't damage the ability to read the card, or else my laziness would have cost me months of development, but it very well could have. Lessons have been learned.

Here's how I copied the image to another card:

Insert the broken SD card and open a command line:

#find the SD card's device name (mine is /dev/sdb)
sudo blkid

# make sure partitions 1 and 2 are unmounted
sudo umount /dev/sdb{1,2}

#copy the image from /dev/sdb to a file called 'sd.img'
sudo dd if=/dev/sdb of=sd.img bs=4M conv=notrunc,noerror

It takes quite a while to copy. Once it is done, pull out the SD card and insert the new one (same size as the old card):

#copy the image the file to /dev/sdb
#notice if=(input file) is now 'sd.img' and of=(output file) is '/dev/sdb', reversed from before.
sudo dd if=sd.img of=/dev/sdb bs=4M conv=notrunc,noerror

#flush file system buffers (if you're paranoid)
sync

It takes even longer this time because writing to a device is almost always slower than reading, and in this case the SD card is the bottleneck.

Once you pop the SD card into your Raspberry Pi, it should boot just fine.