Wednesday, October 16, 2013

How to: Fix a corrupted DATA partition on the HTC One


Since the HTC One was released, I've had a few users asking me to help them fix their broken device. They couldn't boot their system or access anything on the DATA partition from inside custom recovery. Why this happens so often on the HTC One I have no idea...

Here is a short guide explaining how to fix this problem without sending the device for repair under warranty.

Short Explanation

This method can be used to fix any other partition too, just remember about changing the mount point number - from "mmcblk0p37" to the relevant one. For example, the SYSTEM on the HTC One is "mmcblk0p35". In some rare cases the mkfs.ext4 attributes (like dir_nlink or resize_inode) might change too! To get a list of all eMMC mount points on HTC devices use the command cat /proc/emmc. Never format RAW partitions! This method can be used only to format EXT4 partitions. Not following the guide properly might end in permanent damage to your device. I do not take any responsibility for that.

Some people might also find this helpful in case of need to remove the entire contents of the virtual SD-card. As long as the virtual SD-card is not a separate partition, (i.e. it is emulated space on the DATA partition [/data/media]) it can't be formatted - only wiped clean. I wrote an in-depth explanation of how the virtual SD-card works on Android here - Virtual SD card on Android.

How Do I Recognise The Problem?

When trying to mount the DATA partition from inside the custom recovery using the mount /data command you will most likely see this output: mount: mounting /dev/block/mmcblk0p37 on /data failed: Invalid argument

To be 100% sure you can check filesystem structure with the following command: /sbin/e2fsck -n -f /dev/block/mmcblk0p37

Repair Process

Note: the content of your DATA partition will be lost, including the contents of your virtual SD-card! I also assume you already have custom recovery flashed and you are a Windows user - LINUX people please amend as needed.
  1. Download this mini-sdk package and extract it to c:\mini-sdk
  2. Download this mkfs.ext4 binary and put it into c:\mini-sdk
  3. Connect your device to the PC
  4. Boot your device in recovery mode
  5. Open a command prompt on the PC (cmd.exe), type and confirm each command with ENTER:
  6. cd /d c:\mini-sdk
  7. adb push mkfs.ext4 /tmp
  8. adb shell
  9. chmod 777 /tmp/mkfs.ext4
  10. /tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,^extra_isize -m 0 /dev/block/mmcblk0p37
Image of the whole command in one line to avoid mistakes:

Now your DATA partition will be formatted. It is not the same as "wiping", which is only removing all or just some files from particular partition. Formatting means that the entire partition will be re-created with the above attributes. You should see the following output:

mke2fs 1.41.12 (17-May-2010)
Filesystem label=  
OS type: Linux 
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1703936 inodes, 6815744 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
208 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. 
Use tune2fs -c or -i to override.
Your DATA partition is now completely empty, so we need to copy our particular ROM zip file there:
  1. Copy ROM zip file to c:\mini-sdk and rename it to "rom.zip"
  2. In the same command prompt window type and confirm each command with ENTER:
  3. mount /data
  4. mkdir -p /data/media/0
  5. exit
  6. adb push rom.zip /data/media/0
Copying rom.zip to the device will take a few minutes. Wait until it's done. The output should be: xxxx KB/s (xxxxxxxxxx bytes in xxx.xxxs)Now you can flash rom.zip from inside custom recovery. Done!

Have any questions or comments? Feel free to share! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) below this post!

38 comments:

  1. This one is great and irc-proof. Thank you for this. I had to use these commands already twice in the past!!

    ReplyDelete
  2. Tested and proven to work. Definitely there with the best of the repair tools.

    ReplyDelete
  3. i never find any problem with my M7 "for now"

    ReplyDelete
  4. HI! I have problem with Sprint HTC One.... there are no partitions..... and with your suggested fix i receive such error:
    Could not stat /dev/block/mmcblk0p37 --- No such file or directory
    The device apparently does not exist; did you specify it correctly?

    i'm loading recovery throw fastboot boot command. TWRP 2.6.3.0 ..... in recovery file manager i check /dev/block folder.... only Loop&Ram partitions.... nothing else....
    whet is it???

    ReplyDelete
    Replies
    1. Sprint variant has different mmcblk numbers.

      International:
      mmcblk0p37: 680000000 00000200 "userdata"

      Sprint:
      mmcblk0p39: 680000000 00000200 "userdata"

      mmcblk0p37 on Sprint is "system" partition, so instead of "data" you formatted "system".

      Delete
    2. thanks for reply... pls read my question one more time.... in /dev/block folder.... only Loop&Ram partitions.... nothing else.... there are no mmcblk partitions..... where is they???

      Delete
    3. Can you turn on your device? If you can enter recovery mode, then there must be eMMC partition from where recovery boots. What does cat /proc/emmc command gives as an output?

      Delete
    4. Yes i can turn om my device, but only to bootloader..... i can unlock it and relock it, but i cant flash recovery, can't enter recovery trow bootloader options. When i ask rebootRuu phone just reboots to bootloader....

      C:\Documents and Settings\Admin>fastboot oem rebootRUU
      ...
      (bootloader) Start Verify: 3
      (bootloader) SD: write failed in CMD25.
      OKAY [ 1.094s]
      finished. total time: 1.094s

      and it's rebooting to bootloader......

      Only way to start recovery fastboot boot command..... and after fastboot boot recovery.img i can have access to adb...

      Here what you ask to execute:

      cat /proc/emmc
      dev: size erasesize name
      mmcblk0p19: 000ffa00 00000200 "misc"
      mmcblk0p36: 00fffe00 00000200 "recovery"
      mmcblk0p35: 01000000 00000200 "boot"
      mmcblk0p37: 73fffc00 00000200 "system"
      mmcblk0p26: 00140200 00000200 "local"
      mmcblk0p38: 27fffe00 00000200 "cache"
      mmcblk0p39: 680000000 00000200 "userdata"
      mmcblk0p22: 01400000 00000200 "devlog"
      mmcblk0p24: 00040000 00000200 "pdata"
      mmcblk0p27: 00010000 00000200 "extra"
      mmcblk0p33: 04b00200 00000200 "radio"
      mmcblk0p16: 03c00400 00000200 "adsp"
      mmcblk0p15: 00100000 00000200 "dsps"
      mmcblk0p17: 007ffa00 00000200 "radio_config"
      mmcblk0p20: 00400000 00000200 "modem_st1"
      mmcblk0p21: 00400000 00000200 "modem_st2"
      mmcblk0p29: 00040000 00000200 "skylink"
      mmcblk0p30: 01900000 00000200 "carrier"
      mmcblk0p28: 00100000 00000200 "cdma_record"
      mmcblk0p18: 02000000 00000200 "reserve_1"
      mmcblk0p32: 034ffa00 00000200 "reserve_2"
      mmcblk0p34: 05fffc00 00000200 "reserve_3"
      mmcblk0p31: 04729a00 00000200 "reserve"


      big thanks for your help to me!!!

      Delete
    5. As I said, you can see clearly:

      mmcblk0p39: 680000000 00000200 "userdata"

      Delete
    6. Same problem here. None of the mmc* files exist under /dev/block, regardless of what cat /proc/emmc outputs. Furthermore, cat /proc/partitions outputs nothing, which is worrying.

      Delete
  5. Thanks for sharing.. nice article.

    ReplyDelete
  6. I have a big problem, i want to fix my corrupted DATA partition on the HTC One.
    But adb is not working on my device. Fastboot is. My phone does not boot only the bootloader and recovery is.
    I am on hboot 1.55, s-on and unlocked.
    Please help i am trying to fix my phone for two month's now.
    Sorry for my bad english

    ReplyDelete
    Replies
    1. If your adb is not working then you need to install drivers properly.

      Delete
    2. The drivers on my pc are installed properly.

      When i connect a diffrent device it is working.

      On my htc one do not know how to do it.
      The device only start up in hboot and recovery.
      Please tell me how to do it.
      Thanks

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Hi Mike,

      adb was working, i did not read well.
      Sorry
      I had to reboot in recovery.
      This is what i get back.
      Am i doing something wrong?


      C:\mini-sdk>adb push mkfs.ext4 /tmp
      2477 KB/s (3537143 bytes in 1.394s)

      C:\mini-sdk>adb shell
      ~ # ←[6n

      ~ # ←[6nchmod 777 /tmp/mkfs.ext4
      chmod 777 /tmp/mkfs.ext4
      ~ # ←[6n/tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,
      ^extra_isize -m 0 /dev/block/mmcblk0p37
      /tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,^ext
      ra_isize -m 0 /dev/block/mmcblk0p37
      mke2fs 1.41.12 (17-May-2010)
      /dev/block/mmcblk0p37 is mounted; will not make a filesystem here!
      ~ # ←[6n

      Delete
    5. Hi Mike,

      It worked i am now pushing a rom.zip

      i had to format within recovery and unmount
      Thank you, i was almost giving up
      I will sent a message when can use my phone

      Delete
    6. Hi Mike, i stil can not install an rom.

      Is the data good,

      Pleas inform me:

      error: device not found

      C:\mini-sdk>adb push mkfs.ext4 /tmp
      2835 KB/s (3537143 bytes in 1.218s)

      C:\mini-sdk>adb shell
      ~ # ←[6nchmod 777 /tmp/mkfs.ext4
      chmod 777 /tmp/mkfs.ext4
      ~ # ←[6n/tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,
      ^extra_isize -m 0 /dev/block/mmcblk0p37
      /tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,^ext
      ra_isize -m 0 /dev/block/mmcblk0p37
      mke2fs 1.41.12 (17-May-2010)
      /dev/block/mmcblk0p37 is mounted; will not make a filesystem here!
      ~ # ←[6n/tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,
      ^extra_isize -m 0 /dev/block/mmcblk0p37
      /tmp/mkfs.ext4 -b 4096 -O ^huge_file,^dir_nlink,^ext_attr,^resize_inode,^ext
      ra_isize -m 0 /dev/block/mmcblk0p37
      mke2fs 1.41.12 (17-May-2010)
      Filesystem label=
      OS type: Linux
      Block size=4096 (log=2)
      Fragment size=4096 (log=2)
      Stride=0 blocks, Stripe width=0 blocks
      1703936 inodes, 6815744 blocks
      0 blocks (0.00%) reserved for the super user
      First data block=0
      208 block groups
      32768 blocks per group, 32768 fragments per group
      8192 inodes per group
      Superblock backups stored on blocks:
      32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

      4096000

      Writing inode tables: done
      Creating journal (32768 blocks): done
      Writing superblocks and filesystem accounting information: done

      This filesystem will be automatically checked every 34 mounts or
      180 days, whichever comes first. Use tune2fs -c or -i to override.
      ~ # ←[6nmount /data
      mount /data
      ~ # ←[6nmkdir -p /data/media/0
      mkdir -p /data/media/0
      ~ # ←[6nexit
      exit

      C:\mini-sdk>adb push rom.zip /data/media/0
      2946 KB/s (1162940082 bytes in 385.381s)

      C:\mini-sdk>

      Delete
    7. Now you need to push the rom.zip to the virtual sd card

      adb push rom.zip /data/media/0

      Delete
    8. Yes i have done that. Rom.zip is installing.
      At the end it looks like twrp is stopping and when it reboots i stay in an bootloop
      Only the data can be mount
      After format and reboot it is possibile to mount cache and data
      it is frustrating for two month's i see the same problem's
      Just now i have format,
      Its is possibile to mount data, cache and system.
      I go to sideload, select the two buttons for cache and dalvik cache.
      select push rom(Guru_Reset_M7_3.62.401.1)
      Within 4 seconds twrp is rebooting
      Some times it is possibile to install the rom.
      But it always end in a bootloop.
      I have no idea what do.

      Do you have a clue
      Can i send you my phone?

      Pleas help

      Delete
  7. Hello! Will this work on Htc ONE S??

    tnx

    ReplyDelete
  8. Hi mike,

    Formatting helped me, the first time failed, the second time i had to wait for 4 minutes.
    But i still cannot install rom's.
    I have repaeted the above severall time's.
    I is now going very fast.
    So i think that you have helped for a great part to solve the problems.
    On the google rom it is booting now. I see the google text and the for colors of animation.
    After four seconds it stops. And start to reboot.

    In recovery i am able to mount and unmount cache, data and system.

    I can not do this for usb-otg .

    Is pointing to a problem?
    I there a way to format for a more deep level, or format a different way?

    Please can you help me.

    ReplyDelete
  9. Sorry for this question @mike1986 but what can we do if the recovery partition is corrupt..? Then we won't be able to boot into recovery and in that case we won't manage to use adb...
    (I mean what could we do if there was only the bootloader available?)
    Because I think someone has this problem..
    (http://forum.xda-developers.com/showthread.php?p=47972803)

    ReplyDelete
    Replies
    1. Just reflash recovery partition in fastboot mode: fastboot flash recovery recovery.img

      Delete
    2. I have the same issue and I'm not able to flash recovery (diff versions of cwm, twrp, stock ...) always get the same error:
      "FAILED (remote: image update error)", my phone is S-OFF, unlocked.
      I'm able to lock and unlock the phone, I tried too many other things as well all failed
      one of them was RUU which always error or with 171 USB connection error.

      I believe I'm doomed, but I'm not giving up yet ... already 4th day and running
      another q: is there is a way to turn on debugging on fastboot so you can more detailed erros.

      your help is greatly appreciated.

      Delete
    3. @Ana Mino, try to catch my on my IRC channel, #AndroidRevolution at Freenode. I'll try to help you.

      Delete
  10. Hello help me pleasee ... any idea how to fix camera issues of the htc one, i have a purple screen in the night* thanks for your time !

    ReplyDelete
  11. Hello sir, may i ask how to recover my data partition on my MID Tablet, a china one. File managers on the tablet itself can see the data folder on the root of the system, but why is that , that if i install a third party app, it always shows that i have insufficient storage even if there is no one single app installed... I think the data partition is corrupted... If i am going to push apks to /data/app thru adb, it goes through but why then if i restart the device, the data is automatically wiped out, meaning no app installed even the pushed one... please help thanks... Dan (wahbufetz@gmail.com)

    ReplyDelete
  12. Hi Mike, I had accidentally flashed Revolution 40.1 to my HTC ONE Sprint and got stuck in the boot loop for 2 days. I couldn't figure out after all the wiping formating ect.. why it kept boot looping.. Than when I found this thread from the Dev I was so happy it all made sense. I did everything above and it worked just as you said however.. I flashed Revolution 31.6 which is what I inititally had and it's still doing the boot loop.. I tried relocking and installing and RUU even and it said something about couldn't read 24 parsions or whatever.. I used Root kit from Hon2000 for that.. That was before I did this.. I unlocked and did this but... I'm at wit's end.. Please.. Could you help me? I'd be forever grateful.
    Thanks, Rob Eggers

    ReplyDelete
    Replies
    1. Please catch me on my IRC channel so that I can help you further.

      Delete
    2. Awesome Thank You!! I may sound stupid but.. How do I get in your IRC Channel?

      Delete
    3. Look at the top of this page.

      Delete
  13. Can this please work with the HTC one s. i have a great problem with E: failed to mount sdcard...
    Tahnks

    ReplyDelete
  14. When flashing a RUU, why secondary bootloader (sbl1 & sbl2) always fail and skipped. Is there any particular reason, I have observed this in almost all RUUs.

    ReplyDelete
  15. Jadwal Resmi Adu Ayam SV388 9 Maret 2019 di Situs Judi Sabung Ayam Online Melalui Agen Resmi Taruhan Sabung Ayam Live Asli Thailand.

    Situs Judi Sabung Ayam Online SV388 Merupakan Situs Judi Asal Thailand Yang Sangat Terkenal Dengan Permainan Sabung Ayam Yang Fair dan Menghibur Para Penonton Judi Sabung Ayam.

    Untuk Info Lebih Lanjut Bisa Hub kami Di :
    wechat : bolavita
    line : cs_bolavita
    whatsapp : +628122222995
    BBM: BOLAVITA

    ReplyDelete
  16. lpgot@outllok.com7/27/20, 7:51 AM

    Hi Mike, I am facing a similar issue with HTC one m8 and it is stuck on Boot-loop, sometimes it stay 2-5 minutes after unlock but reboot again. Hard-reset, recovery or factory reset does not delete the contents. I tried to use the repair process mentioned in your post.The provided links in step one and two are not working? Can you please update the links or provide the files needed?

    ReplyDelete
  17. HTC VIVE Starter Kit in UAE, Vive PRO HMD 2Base Stataion Starter Kit in UAE, 2 Controller Starter Kit in UAE
    https://pcdubai.com/htc-vive-starter/
    HTC VIVE Starter Kit in UAE, Safe Shopping Multiple Payment Options Express Delivery PC Dubai Moneyback Guarantee.
    1634112039824-11

    ReplyDelete