The screen appears after booting into TWRP and trying to format memory:
I was trying to flash a custom ROM using TWRP recovery but it's showing Unable to mount storage & Failed to mount '/data' (Invalid argument).
I tried several methods like formatting memory but it's also not happening. It's showing Unable to format to remove encryption. Also tried to change the file format but nothing helped me. Now whenever I switch my phone on it automatically boot up into TWRP recovery mode. I tried this method and almost every method possible but nothing helped.
I'm using Moto E4 Plus (nicklaus).
You can always format from command-line to be sure where the problem is (if any). This will erase your whole
/data partition which contains personal data, apps etc.
userdatapartition. Usually it's symlinked at
/dev/block/bootdevice/by-name/userdata. See FINDING BLOCK DEVICE section in this answer.
userdatapartition is not mounted (which already seems the case here). Execute
mountto see all mounted filesystems. To un-mount open terminal or
adb shelland execute:
~# umount /data ~# umount /sdcard
You get size in 512-byte sectors.
~# SIZE=$(blockdev --getsz /dev/block/by-name/userdata)
~# SIZE=$((SIZE - 32))
~# mkfs.f2fs -l data /dev/block/by-name/userdata $SIZE
ext4filesystem, size is to be provided in block count. If using 4KB block size:
Or if older Android-specific
~# mkfs.ext4 -L data -b 4096 /dev/block/by-name/userdata $((SIZE * 512 / 4096))
~# make_ext4fs -L data -l $((SIZE * 512)) /dev/block/by-name/userdata
datais filesystem/volume label.
make_ext4fsare usually bundled with TWRP or you need to get static binaries.
Starting in Android 3.0, the
recovery.fstabfile gains an additional optional field, options. Currently the only defined option is length , which lets you explicitly specify the length of the partition. This length is used when reformatting the partition (e.g., for the
userdatapartition during a data wipe/factory reset operation, or for the
systempartition during installation of a full OTA package). If the
lengthvalue is negative, then the size to format is taken by adding the length value to the true partition size. For instance, setting
"length=-16384"means the last 16k of that partition will not be overwritten when that partition is reformatted. This supports features such as encryption of the
userdatapartition (where encryption metadata is stored at the end of the partition that should not be overwritten).
~# mkfs.f2fs -l data /dev/block/by-name/userdata
I had the same problem, and what worked for me, I formatted it from command line, so while in fastboot mode I typed:
fastboot format userdata
Then I flashed TWRP and rebooted into it and the files in the storage were all showing, all was working.