Nexus 5/6P Flashing Factory Image fastboot error: mke2fs failed with status 1, Cannot generate image for userdata

During flashing of Nexus factory image, running or simply

# fastboot -w update

fails with message

/usr/bin/mke2fs failed with status 1
fastboot: error: Cannot generate image for userdata

If you remove ‘-w’ from the fastboot command, the installation can complete without formatting (wiping) userdata partition. However that is not an ideal situation and may cause first boot to freeze or loop.

mke2fs is part of Android platform tools that also come with adb and fastboot.

The error is caused by older platform tools version where mke2fs is not compatible with the newer factory images.

Install the latest platform tools from Google Android Developer website.

Check for correct PATH where platform tools are located. Eg. /usr/bin/ and /usr/loca/bin to make sure you only have one and latest copy of adb, fastboot and mke2fs in PATH

When done correctly, mke2fs will format (wipe) the userdata partition with the fastboot -w update command.

# fastboot -w update
Erasing 'userdata' OKAY [ 10.202s]
mke2fs 1.44.4 (18-Aug-2018)
Creating filesystem with 3351034 4k blocks and 838832 inodes
Filesystem UUID: 5e6cb2b1-73ad-4645-8e75-27dddcacd9fd
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

However, the latest mke2fs may still cause first boot freeze or bootloop especially for Nexus 5. Wiping Dalvik and Cache will help. To do this, use third party recovery tools such as Team Win Recovery Project (twrp) for wiping partitions.

Download latest twrp recovery images from:
twrp recovery image for Nexus 5
twrp recovery image for Nexus 5X
twrp recovery image for Nexus 6P

If you have other model, just replace the model code name (hammerhead/bullhead/angler) in the url with your model. Then flash the recovery with fastboot

# fastboot flash recovery twrp-3.3.0-0-hammerhead.img

Reboot into recovery (it should start Team Win Recovery), and perform Wipe-> Format Data, then Advanced Wipe select to wipe Dalvik / Art Cache, Data, Internal Storage (optional) and Cache. (Leave System unchecked unless you want to re-flash factory image)

You may re-flash factory image and restore stock recovery. If you like, leave out the ‘-w’ option to bypass format of userdata partition.

# fastboot update