One for the Interns: So you broke your pi…

Liticode provides internships for promising students interested in technology and business. One of the projects we assign involves a Raspberry Pi. Inevitably, things go wrong. Here’s a list of situations and options for the students, for when things go wrong.

You Messed with /etc/fstab

If you’ve recently changed the /etc/fstab file and now you’re getting an error on boot that says “You are in emergency mode.” and it won’t let you log in and just keeps rebooting, you have found a common problem due to your editing /etc/fstab. The pi doesn’t like something you did in the file and we have to undo it to allow it to boot. You’re going to need a computer you can use to edit files on the boot disk of the pi. Follow these instructions and it should be bootable once again:

  1. Power it down and remove the boot disk and connect it into a different computer for editing.
  2. Wherever it mounts the disk on that computer, open the /boot partition and edit the file cmdline.txt using vi or notepad.
  3. At the end of the line (its one line of commands) add a space and then the command: init=/bin/sh
  4. Save the file and exit. Eject the disk and put it back in the pi and power it on.
  5. You should arrive at a command line now, if not, go back over the steps and ensure you didn’t add any odd characters to the cmdline.txt file.
  6. In order to edit fstab, we have to mount the disk. If you are using our standard build, this command should do the trick:
    # mount -o remount,rw /dev/sda1 /
  7. Now that we have the root file system mounted, you need to edit the fstab file:
    # vi /etc/fstab
  8. If you’re not comfortable with vi, this is an excellent opportunity to learn!
  9. Find the line(s) you added to fstab and comment them out with a hash character, just like the other comments in the file. You can fix them now if you know what’s wrong, or for now just comment them out.
  10. Save the file, shut down the pi, pull the disk out, and put it back in your other computer to remove the command from cmdline.txt.
  11. Delete the command we added at the end of the line back in step 3, and nothing more.
  12. Save the file again, eject the disk, put it back in the pi, and it should boot to the gui now.

An excellent capabilities example for your resume would be to create an automatic shellscript process that detects these errors at startup and automatically deals with them.