Tutorial How to Upgrade MIUI on an Encrypted Phone

Discussion in 'Question & Answers' started by Vertana, Jul 14, 2012.

Thread Status:
Not open for further replies.
  1. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    I have done this many times successfully and without any errors. I have only tested this with a GNex and MIUIAndroid and MIUI.us. This method will NOT work with MIUI.us. The install script in MIUI.us needs to do something with the /data partition and the /data partition will not mount because it is encrypted; therefore the install script fails and does not complete correctly. You might be able to customise the script to work, but that is beyond the scope of this post at the moment.

    For this example, let's say we want to upgrade from MIUI 2.7.6 to MIUI 2.7.13. This is just an arbitrary version I picked, it should work with any MIUIv4 to MIUIv4. Currently, MIUI 2.7.6 is installed on your phone and you have chosen to enable full device encryption. You have probably already noticed that you cannot mount your sdcard or your data partition which means you cannot update your OS using CWM functions.

    Risks:
    This method cannot and will not "brick" your phone. We are only messing with the /system partition here. However, if you need to return your phone to stock for whatever reason (like you've decided to disable encryption) then that process will wipe your sdcard. Make sure you have backups in an encrypted form. Titanium Backup has an encryption option and you can send your encrypted backups to a cloud account (like GDrive, Dropbox, etc). You could also store your backup sdcard data in a Truecrypt container on your PC. Just remember to keep it encrypted, otherwise why even bother with phone encryption in the first place?

    You will NOT be able to make a nandroid backup of your phone. That is a function of your custom recovery and your recovery will not be able to make backups of your /data partition (where all your apps, settings, and data are stored) because it cannot open those encrypted partitions.

    What you will need:
    adb (Here are some instructions on how to install and basic instructions on pushing files via adb: http://prepaidandroid.org/index.php?title=How_to_push_files_to_your_SD_Card_with_ADB)
    Your ROM zip file that needs to be applied (this needs to be a file on your PC)
    Custom Recovery on Phone


    How to upgrade:
    You must have your phone booted into your custom recovery.

    1) Extract and copy the files update-binary and updater-script from your ROM (you must have a copy of this file still in your ROM zip).
    a) Open the ROM zip file in winrar, 7zip, or any program that allows you to manipulate zip files.
    b) Find the update-binary and updater-script usually found here: /miui.zip/META-INF/com/google/android/ and copy those two files to the same folder that contains the zip file.


    2) Plug your phone into your computer via USB.

    3) Now pull up an adb shell and mount /system in rw mode.
    a) Find where you installed the android-sdk. Open two command prompts. In BOTH of them navigate to the android-sdk/platform-tools/ folder.
    For a Windows example:
    Code:
    cd C:\Program Files (x86)\android\android-sdk\platform-tools\
    For a *nix example:
    Code:
    cd /home/user/android-sdk/platform-tools/
    b) Once you are there, run the command
    Code:
    adb shell
    . You should now see a prompt with this symbol: #. That means you are on a root command prompt on your phone. Now type
    Code:
    mount /system
    . If you wish, you can use this window to watch activity for errors by typing
    Code:
    adb logcat
    and simply press Control+C when you're done watching the log.


    4) Now push the binary, script and zip from your PC to your /system partition in a separate adb window.
    a) In your other window, type
    Code:
    adb push C:\wherever\zip\is\MIUI-2.7.13.zip /system/
    . This may take a minute and will say nothing until it completes or fails. When it has completed type
    Code:
    adb push C:\find\update-binary /system/
    and finally push the updater-script with
    Code:
    adb push C:\find\updater-script /system/
    .
    Notice the slashes, use \ on Windows and / for the phone and Linux systems. The trailing / behind system MUST BE THERE or you will overwrite the directory /system/ and cause troubleshooting to start.

    5) In your adb shell window, run the update binary.
    a) You should still have your other window up with the adb shell still up (with the # prompt). In your adb shell type
    Code:
    cd /system/
    . Now type
    Code:
    chmod a+rwx ./MIUI-2.7.33.zip
    ,
    Code:
    chmod a+rwx ./update-binary
    , and finally
    Code:
    chmod a+rwx ./updater-script
    hitting enter after each command. Your last command will be
    Code:
    ./update-binary 2 stdout /system/MIUI-2.7.13.zip
    and you should see the progress in the prompt.

    6) After it is completed type
    Code:
    reboot
    in the adb shell and then unplug your phone when it is rebooting. You should be done. Hopefully it boots fine where you will type in your PIN/Password and then complete booting into your updated MIUI install!

    Troubleshooting:
    If your phone is boot looping, you may have simply had a bad install. I've experienced this and the solution I used was to re-download the zip file and do the process over again with the new file.

    I accidentally forgot the trailing slash and overwrote the /system/ folder! It's ok. You have lost your data on /system, but you were doing that with an update anyway right? Simply open an adb shell just like we did in the instructions above (with the # prompt) and type
    Code:
    rm /system
    and then
    Code:
    mkdir /system/
    and now you have an empty folder called /system/ and you can put all your files in there and run your update as above.

    Encryption Help: If you are encrypting your phone and your phone just reboots without applying encryption, I got mine to complete successfully by going back to stock firmware (which erases ALL of your data, even your sdcard), flashing recovery, then flashing MIUI, choosing fix permissions in recovery and then immediately choosing to encrypt after boot up before I start messing with restoring backups or my settings. You'll know if your phone is not applying encryption if the Android pops up after you choose but you do NOT get a progress bar and it reboots. If your encryption is coming along fine then you will see a progress bar moving slowly above the Android.

    Encryption Failure Question: When the encryption process was failing my logcat said that it was failing to mount /data (even sometimes when /data was as close to being empty as possible and I had a new flash). What can I do about it?
    I haven't figured out why this happens, but my only solution to this was to rinse and repeat the steps under encryption help.

    ---------
    It took me a few hours to figure this out the first time, but eventually I got it down to 10 minutes by knowing what I had to do. After you get the hang of this, it really is not a big deal at all to upgrade (even weekly)! I hope this guide helped you and please let me know of any errors in the guide or trouble you have following it. Thanks to the MIUI and MIUIAndroid teams for the great ROM!
     
    __NoSense__ and c0d3x42 like this.
  2. iBotPeaches

    iBotPeachesScript Gatekeeper

    Oct 31, 2011
    3,811
    1,117
    335
    Kansas
    Wow great tutorial. I saw that encryption option in the menu, but never have wanted to do it.
     
  3. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    Thanks for the compliment and the sticky! I hope it helps and I'll try to help anyone who is having problems with encryption. Feel free to post or pm for help or fixes!

    Sent from my Galaxy Nexus using Tapatalk 2
     
  4. sweiss33

    sweiss33Members

    Jul 27, 2013
    15
    2
    13
    Male
    Hi,
    Is this tutorial still relevant?

    Also, I tried copying the .zip file to /system/ as specified, but it tells me there's no enough memory. It has only 3mb free (system partition that is). May you copy the files elsewhere?

    I got the SGS2 in case it makes a difference.


    Thanks!
     
  5. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    The tutorial is still relevant in cases where you have CWM and an encrypted /data/ partition. If you don't have enough space on /system/ you're only viable option is to use TWRP. TWRP can read encrypted partitions if you provide the password. Then you can just upgrade like normal.

    When I made this tutorial TWRP didn't have that functionality for my phone, so I came up with alternative measures.

    Sent from my Nexus4 using Tapatalk 2
     
  6. sweiss33

    sweiss33Members

    Jul 27, 2013
    15
    2
    13
    Male
    Thanks for the quick reply!
    Unfortunately TWRP is not available for my phone :|

    I guess I'll have to sit this one out then. By the way, is it normal for the /system partition to be almost full?
     
  7. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    It's highly device dependent since the phones are from different manufacturers and have different memory sizes and layouts. Another option to explore is using /tmp instead of /system in case your device handles the temp directory in a different fashion.

    Sent from my Nexus4 using Tapatalk 2
     
  8. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    If you absolutely 100% must have an update you could always backup, decrypt, update, and re-encrypt.

    Sent from my Nexus4 using Tapatalk 2
     
  9. sweiss33

    sweiss33Members

    Jul 27, 2013
    15
    2
    13
    Male
    I believe I can also use my external SD for the update - I believe I can mount it. Question is, will it be safe to run these commands from outside the /system partition?
     
  10. sweiss33

    sweiss33Members

    Jul 27, 2013
    15
    2
    13
    Male
    Well I was too excited to wait for an answer, and I just wanted to say that using /tmp instead of /system worked just fine for me.

    Thanks a lot for the great tutorial and support!
     
    Vertana likes this.
  11. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    Could you be a little more clear in the steps you took to help the next person who reads this thread? I'm glad it worked. Did you just use /tmp instead of system like my suggestion easier or something else?

    Sent from my Nexus4 using Tapatalk 2
     
  12. sweiss33

    sweiss33Members

    Jul 27, 2013
    15
    2
    13
    Male
    Yes, I've followed the tutorial, using /tmp instead of /system for all the mentioned steps.

    A few extra notes:
    1. I did not need to mount /tmp - is was already mounted as I entered the custom recovery
    2. After the reboot, the SMS application crashed right at the start. To solve this, I entered recovery mode again. wiped the cache partition through it and rebooted.

    Now everything seems to be working just fine.
     
    Vertana likes this.
  13. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    Awesome! Thanks for the update; hopefully it helps someone else as well!

    Sent from my Nexus4 using Tapatalk 2
     
  14. Eddles

    EddlesMembers

    Aug 13, 2013
    2
    0
    11
    I had problems following this guide, until I realised that the update package was formatting /system/ before installing the update, thus losing the update package itself! I figured out that an alternative method was to mount a temporary filesystem (mount -t tmpfs -o size=500m tmpfs /sdcard) then copying the 3 update files into /sdcard and running the update from that directory, rather than /system/ (./update-binary 2 stdout /sdcard/update.zip).
     
  15. Vertana

    VertanaMembers

    May 12, 2012
    85
    10
    18
    This guide is pretty old by now. Perhaps they have changed the update script. Thanks for the heads up!

    The script used to just unzip itself over the file system. Maybe now it does a legit format command. Been a while since I've looked at it as I now just use TWRP.

    Sent from my Nexus4 using Tapatalk 2
     
  16. CYB

    CYBMembers

    Jun 7, 2014
    5
    0
    21
    Male
    Italy
    Only one question : Do XIAOMI phones support FULL DEVICE ENCRYPTION ? I really cannot find this option in MIUI roms.
    Thanks


    ---
    Currently running Android 4.2.2 JDQ39 \ MIUI v.JHDCNBA17.0 \ KERNEL 3.4.39
     
  17. CYB

    CYBMembers

    Jun 7, 2014
    5
    0
    21
    Male
    Italy
  18. sulewel

    sulewelMembers

    May 28, 2016
    8
    1
    13
    Male
    What does encrypted mean? a passcode protected Mi phone?
     
    polve91 likes this.

Share Our Site