After rebooting my Raspberry Pi 2 (The shairport-sync service wasn't working properly) it checked the whole filesystem on boot, which took about 10 minutes. I had no idea why.

After it had done that, it rebooted again and the screen went black, with a blinking cursor in the top left. After connecting a keyboard and pressing Ctrl+Alt+F1, I could see that it was trying to log in with the user pi automatically. However, that failed for a few times in a row and froze. In a new terminal tab (F2), I was asked for a login name. After entering pi there, I got 'invalid login' as an answer.

There was no way for me to open a terminal so I unplugged it and am currently making an image of the SD card via my Mac.

I have no idea how to restore my working installation nor how I can access my old files. Unfortunately I was dumb enough to not make a backup beforehand.

What are the steps I should follow now? I cannot login, nor can I read the files of the SD card (except for the BOOT and RECOVERY partitions). I am going to try adding init=/bin/bash to the cmdline.txt file on the boot partition, as I've read that somewhere, but I am not sure if that is going to work and where to go after that.

  • You will need third party tools (that support ext4 filesystems) or a linux VM to read the root fs on the card with OSX.
    – goldilocks
    Dec 17, 2016 at 16:41
  • I'm going to try to restore data at least, using a live boot CD. I'd rather have all my stuff still working though, but I'll have to see. Dec 18, 2016 at 0:07

1 Answer 1


It should be possible to recover using your Raspberry Pi in conjunction with another sd card and a USB card reader.

  1. Download and flash the 2nd SD card with your RPi OS flavor of choice.
  2. Boot to the 2nd SD card, and login to the commandline.
  3. Insert the 1st SD card into the USB card reader. Plug the reader into your RPi.
  4. sudo mkdir /media/usb
  5. sudo chmod 755 /media/usb
  6. sudo fdisk -l Your looking for the device location tag, probably /dev/sda1 (small, about 56MB) and /dev/sda2 (the rest of the card)
  7. sudo mount /dev/sda2 /media/usb (or use the larger of the two you found in step 6.)
  8. sudo chroot /media/usb
  9. From here you are acting as the root user of the USB card reader's drive which is your 1st SD card. You have options from here. You can attempt to copy your data off, resetting your root password, or even rebuilding your pi user

This page gives a lot of detail on what the /etc/passwd and /etc/shadow files should have in them. Both of these files can be easily edited with nano. You can add the pi user back and/or permit the pi user to login with a password, to fix your login problem. This could get you back to where you can boot off your 1st SD card and then recover your system. Just be sure to set a new password once your back up and running.

After your done with making changes, you need to exit then sudo umount /media/usb

If you changed your boot parition cmdline.txt you should fix it now. sudo mount -t vfat /dev/sda1 /media/usb then sudo nano cmdline.txt and remove init=/bin/sh from the end of the line, and for good measure make sure there are no extra lines in the file. Ctrl-X and save, then sudo halt and you can put your 1st SD card back in the RPi.

BONUS ADVICE: Using a tool like ApplePiBaker makes it really easy to create backup images of your RPi SD cards and even restore them.

  • Thanks for the detailed answer! I had already decided to start off again and indeed create a back up, but these steps are really helpful. I did have some permission issues while trying to access my files from a Linux live disc (which I figured out after a while)! Also, I will be sure to check out that tool. It sounds quite helpful! Feb 1, 2017 at 13:24
  • @MaxKorlaar Your welcome, I had just recovered an old RPi myself, only I didn't have the username I created as I had deleted the pi user for security reasons on the project. It was rather annoying chicken&egg problem before I hit on the chroot solution I gave you. Feb 1, 2017 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.