1. Are you ready for the Galaxy S20? Here is everything we know so far!

Read/Copy the contents of nandroid backups

Discussion in 'Android Devices' started by akazabam, Apr 17, 2011.

  1. akazabam

    akazabam Android Expert
    Thread Starter

    I've seen a lot of people ask if it's possible to find out what ROM a nandroid backup is of, or how to get apps out of a backup without restoring it (as is the case if you forget to backup with TB, first). In this thread, I explained how to do this from Windows. What I failed to mention is that this is natively supported in Linux. The method in that thread involves copying img files from a backup to a Windows computer, and using unyaffs with cygwin. Since Android is Linux, you can do this directly from your phone. Yes, it takes a bit longer (just a couple minutes) because you're reading/writing to the sdcard. It still takes much less time than it does to restore a backup, get what you need, then restore back to whatever you had before. So, to make this process easy, I've written a script that can be executed from the terminal directly on the phone. The process is completely automated. Here is how it works:

    1) Flash unandroid-signed.zip from recovery. Reboot. (You only have to do this step once)
    2) Open the terminal emulator.
    3) Run this command:


    4) You will be given a list of existing Clockwork and/or Amon RA nandroid backups. For example:

    5) Select the number of the backup you want to extract. For example, just type "1" without quotes to extract backup1.
    6) The script will determine if the backup includes a system.img, a data.img, or both. You will be prompted to extract either one or both by pressing "s" for system.img, "d" for data.img, or "sd" for both (all without quotes).
    7) That is all the user input it needs. Once that is done, the backup will be extracted to /sdcard/nandroid_tmp/nameofbackup/ with a directory named system.img for the system.img and/or a directory named data.img for the data.img.
    8) Use any file browser you like to navigate to those directories. You will find all of the files you would normally find in /system or /data if you were to actually restore that backup.

    Note that you only have the option for system.img and/or data.img. This method is not useful for any other image file in a nandroid backup. That being said, system.img and data.img are the only ones you'll need 99% of the time.

    Note also that it will take approximately 2-3 minutes per image (data.img and/or system.img) depending on how big it is. It might look like the script is hanging, but it's not. Unless you get errors, just let it run. If you do cancel it, though, just remove the directory that gets created in /sdcard/nandroid_tmp and start over. Basically, this process is the same as restoring a nandroid the backup. The difference is that you're copying the files to a temporary location for ease of access rather than replacing your entire system (a waste of time for extracting a few files here and there).

    Potential uses for this script:

    1) If you forgot to rename a backup, and have no idea what it is, follow the above procedure for the system.img of that backup. Once it is done, use a file browser to navigate to the directory. In the top level of the system.img directory, you will find a file named build.prop. It is a text file with a list of properties for the ROM that was backed up. Open it, and find ro.build.description. That will tell you what ROM it is. You can also do this from the command line (terminal) by typing:

    grep ro.build.description /sdcard/nandroid_tmp/nameofbackup/system.img/build.properties

    2) If you forgot to backup an app and no longer have access to the apk (or you simply forgot what all you had installed), follow the above procedure for the data.img of the backup. Do the same as above, but navigate to the created data.img directory. In the app directory, you will find all the apps that were installed in that backup. You can copy the apks out of there and install them, or build a list, depending on what you wanted to do. Note that if you use a2sd, and moved apps to the sdcard, they will not be saved here. If you backed up the ext partition, it will be in a separate file named ext.tar. A tar file is different than the normal img files that are created in a backup. A tar file is basically a collection of files made into a "tarball" so that it can be easily stored, compressed, etc. in one file. If this is the case, and you want your apks, you don't need this script for that. You can untar the file by opening a terminal, and typing these commands:

    cd /sdcard
    mkdir ext_apps
    cd ext_apps
    tar xvf /sdcard/path/to/backup/ext.tar

    Off that rabbit trail, there are still plenty of uses for extracting the data.img, such as:

    3) if you need app data, you will find it in /data/data, normally, so if you follow the above procedure for the data.img, you will find it in data.img/data/. One such example could be if you forgot to backup your bookmarks. Most settings/history type things for the browser are stored in /data/data/com.android.browser/databases/browser.db, which is a sqlite file. It's a database, basically. So, if you extract your data.img from a nandroid backup, you *could* just copy this file out of there and replace your existing one with it. If you go that route, I would highly recommend you backup first. You could easily cause issues if you do this, especially if going between aosp and sense, and vice versa. That being said, it's easy to see what bookmarks you had set in the backed up ROM by typing this (rather lengthy) command from the command line:

    sqlite3 /sdcard/nandroid_tmp/nameofbackup/data.img/data/com.android.browser/databases/browser.db "select * from bookmarks where bookmark = '1'"

    That will return a list of bookmarks you had in the backed up ROM. This is just one such example. If you search for db files, you'll even find your SMS messages. This means if you forgot to backup your text messages, you don't need to restore a backup just get them. Go through this procedure, and you can get them.


    I did my best to test this in a short amount of time. I tested it on CM7 and Mikfroyo 4.4, both of which had a2sd installed. All backups I tested were made with Amon RA. In theory, this should work with any ROM, whether a2sd is installed or not. All you need is the script itself, bash (normally installed with a2sd), and unyaffs, all of which are provided in the flashable zip in the event that you don't already have them. If you have CM7, you should already have unyaffs.

    Also, this should work fine with both Clockwork and Amon RA nandroid backups. I don't use CW, so I only tested with RA. I know for a fact that the method used to make the backups is the same, but that doesn't change the fact that I didn't test it. If anyone using CW uses this and gets any errors, or simply isn't given a list of any backups, please let me know, along with the directory your backups are in, and I'll fix it.

    One last thing - when I ran this, I got an I/O error, and a message that mkdir failed a couple of times. It only happened a few times, and always ran fine if I just reran the script. I'm tracking the issue down now, but just be warned.

    If I forgot anything, I'll update this section. Otherwise, if you run into any errors or if this just doesn't work as advertised, please let me know, and provide the following details:

    1) Error messages, if any
    2) Current ROM
    3) ROM of the backup (if you know)
    4) Using bash or sh (if you don't know the answer to this, it's sh). This shouldn't matter, as the script will use bash, but still...
    5) The recovery/version used to make the backup



    Instructions for flashing:

    1) Download the above file
    2) Copy it to the root (top level) of your sdcard (or where ever you like to put your flashable zips)
    3) Reboot into recovery
    4) Select the option to flash a zip. You do not need to wipe cache/dalvik
    5) Reboot once it's done flashing


    argedion has modified unandroid to support nandroid backups that include an ext backup in the form of a yaffs2 img. So, if you are using a recovery such as Amon Ra Style (which I'm told no longer packs the sd-ext image in a tar file, but in an ext.img file) you can now extract it with unandroid. Here is the new version:


    Follow the same steps to flash it. It will replace the existing version of unandroid if you have already flashed it.


    Fenix23, dkl1, argedion and 12 others like this.
  2. evomattnc

    evomattnc Android Expert

    Thanks bud. Downloading now. This will actually help me a lot since my sd card crapped. I lost themed apps I had ripped out of roms. Now instead of endlessly searching the forums and finding them or restoring all my backups and ripping them again I can just use this. Great explanation as usual. I'll let you know how it goes when I get a chance to use it. Also great since I started doing my own themeing recently.
  3. akazabam

    akazabam Android Expert
    Thread Starter

    Great :). Let me know how it goes, or if you run into any problems. I'd love to hear how this is being used.
  4. 9to5cynic

    9to5cynic Android Expert

    Great, can't wait to try it out.

    I do, however, have a question. How would you go about checking the version from a linux desktop? Would it be just grepping the file build.prop after extracting the system.img like the tut you posted for windows?

    I think I'll try that to see if I can get it. (Bookmarking this thread)
  5. akazabam

    akazabam Android Expert
    Thread Starter

    Right, if you're using Linux, follow the steps for Windows, but skip the whole cywin thing. That's only necessary for running a Linux environment in Windows. You'll just need unyaffs, which you may or may not already have in your Linux distribution. Just create a directory to extract the contents to, cd to it, unyaffs the system.img file, then grep ro.build.description build.properties. That will return with the line that says what ROM it is. Basically, you have several options for how to do this. If you already have all your backups on your computer, it's faster to do it that way. If you don't, this script is faster.
    9to5cynic likes this.
  6. akazabam

    akazabam Android Expert
    Thread Starter

    Oh, and one thing I forgot to mention. Make sure you have at least 500 MB of free space on your sdcard before running this. I haven't put in any checks for that yet. I will later.
  7. Mr. Ed

    Mr. Ed Extreme Android User

    Complete badassery that you did this within work and the move to your new place ....top notch
  8. 9to5cynic

    9to5cynic Android Expert

    Thanks a lot! Works great.
    I was wonder though, if you happen to know the syntax for unyaffs? I can't find a help file or anything on it, it seems that it will extract it to your current location right?

    Kind of a
    Code (Text):
    1. cd /home/user/extractHere
    Code (Text):
    1. /bin/unyaffs /home/user/evo/ROM1/system.img

    Can't wait to download that script tomorrow, it'd be nice to be able to check the few backups on my sdcard.
  9. akazabam

    akazabam Android Expert
    Thread Starter

    lol, thanks. It's something I've been wanting to do for a while. I actually had some time this weekend to sit down and piece it together. Work is getting a bit crazier lately, so I won't have much time to post during the week.

    Yep, that's exactly how it works :).
  10. iniblue

    iniblue Lurker

  11. Why won't it work? Installed the zip, made sure Terminal had superuser... I'm new to this and at a loss.

    HTC Desire CDMA (Bravoc), CyanogenMod 7 nightly125, ClockwordMod.

  12. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    well i think that this was written for the evo. not sure how different the scripting is between the two phones. i know that akazabam wrote this specifically for the evo.
  13. akazabam

    akazabam Android Expert
    Thread Starter

    Well, theoretically, it could be used on other phones, especially considering you're using CM7, which what I mainly tested it on (though it was on the Evo 4g, of course). The error you're getting means that it can't find the command you tried to run. If the zip ran without any errors, then likely it is there. From the terminal, type ls -l /system/bin/unandroid. If it says it can't find it, then it didn't flash successfully. I can't say how it will react on any other phone. If it does show up, then it's possible that you just don't have /system/bin/bash in your $PATH. I don't know if other phones use the same paths, exactly. If it does find it, you can just run the command with the whole path, like this:


    That should work. Assuming you can get it to execute, I still can't say how well it will work on another phone. I would mainly be worried about busybox version differences. It's worth a shot.

    Oh, and sorry I haven't been around much...
    ocnbrze likes this.
  14. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    akazabam is back in the house. we missed ya. glad your alive and well.
  15. evomattnc

    evomattnc Android Expert

    Good to see you my friend. How are things with you? Anything new and note worthy?
  16. Xtremedays

    Xtremedays Android Expert

    Nice to see you pop in Akazabam. Hope everything is good.
  17. It's saying not found :/ sad sad pandas.

    Is there any way to compile unandroid to run on a Desire? Or a way to hook it up to my Linux box, run some sort of unandroid from there?

    My BIG question though, is: why is it not possible to load a Nandroid backup in an emulator, and look through it that way?
  18. 9to5cynic

    9to5cynic Android Expert

    Yup. It'll run from linux.

    I believe the steps are right here, http://androidforums.com/evo-4g-all...py-contents-nandroid-backups.html#post2578747 , and maybe the post below them. (8 and 9 if you'd rather just scroll up.)
    EDIT: Also post 5 goes into it. And I think post five is just re-stating what was said above it...)
  19. hortstu

    hortstu Android Enthusiast

    OK so I'm not familiar with these programs or this process so I'm going to ask some questions that might seem obvious to others...

    I'm trying to perform this process from my linux ubuntu computer.

    1. I don't need the "unandroid zip"

    So I moved the latest nandroid file to my computer. I opened it up and see 4 files.

    Do I need a program to view the contents of these? Which one will have everything I'm looking for?

    app data
    contacts that hadn't been synced with google lately.

  20. Rxpert83

    Rxpert83 Dr. Feelgood

    This process in this thread is all done from the phone.

    You flash the unandroid zip and then Enter the commands listed in the op to extract the contents of the nandroid to your sd card. You will want to do both data for sure and probably system as well.

    After that you can look through the nandroid on the computer to find what you need.
  21. ocnbrze

    ocnbrze DON'T PANIC!!!!!!!!!

    ok bookmarks i'm not sure about but that will depend on the browser you use. but all of the apps and its data will be in the data.img. akazabam goes into detail about where all of it is in the potential use section.

    your contacts should be under the system.img.

    edit:correct rxpert the unandroid script is done on the phone, but i believe that you can open up a nandroid backup with a linux machine from what i understand of it.
    Rxpert83 likes this.
  22. akazabam

    akazabam Android Expert
    Thread Starter

    The tool used here is called unyaffs. It's used to extract files out of yaffs images. The flashable zip here is just bash (since only some ROMs have it, and otherwise you'd have to use sh), the unyaffs binary, and a script (written in bash) to use unyaffs to extract the files from the images. The script part just makes in easier. Bash and the binary are all you'd need. Most Linux distributions are already going to have these.

    1) If you pop open the zip file, you'll find the unandroid script. That script has some hard coded paths in it (bad me), so it won't work out of the box from your computer. That being said, the commands I used will work just fine. Put the img file of your choice in some directory. cd to that directory, then run unyaffs on it. It will extract the files there. That's all the script does.

    2) Here's how you do it in Windows, if you care:


    3) Contacts and bookmarks are in database files. I've listed them in some thread(s) somewhere. If you can't find them, I can look for them later.
  23. Mikestony

    Mikestony ~30% Carbon Black ±

    Holy freaking moses, batman. All of that went into orbit, over my little head!
    But I thanked your post anyway because it will be useful to hortstu.
    I'm sure glad this forum has people like you and many others who know this stuff and can share this with others. I really have ALOT to learn!:)
    ocnbrze and dustwun77 like this.
  24. 9to5cynic

    9to5cynic Android Expert

    Check out my post here: http://androidforums.com/evo-4g-all...py-contents-nandroid-backups.html#post2578747

    Akaza confirmed that is how to do it w/o the script.

    I just did the the other day (okay, like a month ago) when I was looking for a specific file, and it works great. If you are like me and are only after a couple of things, I find it best to extract it to /tmp, but I'm always using /tmp so maybe it's just me. ;) :p

    AND it's great to see akaza poking his head around here again! :D
  25. akazabam

    akazabam Android Expert
    Thread Starter

    argedion was kind enough to inform me that certain recoveries (such as Amon RA Style) are no longer putting the contents of the sd-ext partition in a tar file as a part of a nandroid backup, but are now packaging them in a yaffs2 img file, just like data and system. Not only that, but argedion has also modified unandroid to allow all three images to be extracted (data, system, and ext). He has packaged it in a flashable zip which you can grab in the original thread above.
    dustwun77, ocnbrze and argedion like this.

HTC EVO 4G Forum

The HTC EVO 4G release date was June 2010. Features and Specs include a 4.3" inch screen, 8MP camera, 512GB RAM, Snapdragon S1 processor, and 1500mAh battery.

June 2010
Release Date

Share This Page