Recover Raspberry Pi boot partition after rpi-update

Every now and then, rpi-update will crash halfway through and completely hose up the boot partition on my Raspberry Pi’s sdcard. To fix it, I have to mount the sdcard on my Mac, repair the volume, and download the firmware bits from rpi-firmware. Here’s that process in a nutshell.

  1. Mount your rpi’s sdcard on a Mac and open up a Terminal.
  2. Run diskutil list to identify the boot volume on the sdcard. Here’s what mine looks like; yours will most likely look different:
    $ diskutil list
    /dev/disk0 (internal, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        *251.0 GB   disk0
    1:                        EFI EFI                     209.7 MB   disk0s1
    2:          Apple_CoreStorage Macintosh HD            250.1 GB   disk0s2
    3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
    /dev/disk1 (internal, virtual):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:                  Apple_HFS Macintosh HD           +249.8 GB   disk1
    Logical Volume on disk0s2
    5B72371B-C6C7-4D65-92E2-C9656BE51701
    Unencrypted
    /dev/disk2 (internal, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *15.7 GB    disk2
    1:                 DOS_FAT_16 NO NAME                 50.0 MB    disk2s1
    2:                      Linux                         15.7 GB    disk2s2
  3. Identify the DOS_FAT_16 partition on the disk matching the size of your sdcard. If you get this wrong, you could potentially severely hose something up, so make sure you get it right! Follow these instructions at your own risk. Mine is device /dev/disk2s1 mounted at /Volumes/NO\ NAME, and I’ll use these values for the examples in the steps that follow.
  4. Run the following command (substituting your own device name as found in step 3):
    diskutil repairVolume /dev/disk2s1

    (You will see a lot of error messages that files were truncated, this is expected and normal.)

  5. cd to /Volumes/NO\ NAME (substitute your own mount path as found in step 3).
  6. Run the following command to re-download all the corrupted files from the rpi-firmware Git repository:
    find . -size 0 | while read file ; do 
      curl -o $file https://raw.githubusercontent.com/Hexxeh/rpi-firmware/master/$file
    done
    1. If you get the error find: .: Invalid argument, just run it again.
    2. If you get one or more errors similar to Warning: Failed to create the file ./overlays/spi-bcm2708-overlay.dtb: Invalid, take note of the filename(s) (in this case,  ./overlays/spi-bcm2708-overlay.dtb), and run the following command for each filename (substituting the identified filename for <filename>):
      curl -o <filename> https://raw.githubusercontent.com/Hexxeh/rpi-firmware/master/<filename>
  7. Run the following command:
    rm .firmware_revision
  8. cd out of the Volumes directory, e.g. just run the command cd with no arguments to take you back to your home directory.
  9. Run the following command (same as step 4):
    diskutil repairVolume /dev/disk2s1
  10. Open Finder and eject the sdcard.
  11. Put the sdcard back in your rpi and boot it up.
  12. SSH into your now-working rpi and run rpi-update to finish the upgrade and checkpoint the firmware version.

I hope this helps someone! I wish I could figure out how to prevent it from happening, but for now this recovery process will have to do. Let me know in the comments if you have any questions—or if I missed anything.

Leave a Reply

Your email address will not be published. Required fields are marked *