Recovering FreeNAS Corrupt Flash Drive

This is rough documentation from when I was recovering a FreeNAS server. I could not access the ZFS filesystem, as per most instructions, because some of the sectors were bad and it wouldn’t load.

Extracting the config file

  • Used DDRescue-GUI to dump an image of the drive
  • Wrote a very quick and dirty script to search for the ASCII string “SQLite format 3” within the image, and then outputted “SQLite format 3” and the following 20MB of data, or up until the next “SQLite format 3”. There should be about 5 files outputted (use extension of .db).
  • Loaded each of the SQLite files into SQLBrowser, which is very tolerant of extraneous data. If it has issues maybe you could use a hex editor like Hex Fiend to try to chop off the tail until it loads, but I did not need to do this.
  • Export the file as SQL, create a New Database, and import the SQL file. The newly created database file will be in a clean format readable by FreeNAS.

Import in the web GUI

  • You need to be running the same version of FreeNAS that the db was made from
  • The version number can be found by running:
    strings -t d recoveryFile.img | grep “FreeNAS-”

    • Note that this returns some incorrect results which are examples in strings, like this:
      192050567     “””Return the full version string, e.g. FreeNAS-8.1-r7794-amd64.”””
    • The correct line will look something like:
      944741376 FreeNAS-9.1.1-RELEASE-x64 (a752d35)