Creating and flashing image to Android device I have created an image of my Android device (Lenovo A6000) using the command

adb shell -c su 'dd if=/dev/block/mmcblk0p23 &gt; data.img' 


Now I would like to flash this image to the same device, and I am trying to accomplish this using fastboot in the following way

sudo fastboot flash data data.img


I am using the latest version of fastboot shipped with Android's SDK.

Doing the above command I get the error

    target reported max download size of 268435456 bytes
    Invalid sparse file format at header magi
    error: write_sparse_skip_chunk: 
    don't care size 4894735982 is not a multiple of the block size 4096
    fastboot: ../libsparse/sparse.c:143: 
               write_all_blocks: Assertion `pad &gt;= 0' failed.


I suspect it has something to do with the sizes, the image appears to have size ~5GB while the reported max download size appears to be ~2GB.

But I am not sure what the real error is and how to fix it?

Can someone tell me where the mistake is and how to solve it? It seems that if I make a smaller image I can flash it properly.
Android fsutils (on ubuntu) comes with tools you need. You can also find them on GitHub. You need: simg2img, simg2simg, img2simg, make_ext4fs, and some terminal knowledge.

sudo simg2simg ./data.img ./data.raw.img
This gives you an image that can be mounted on Linux. To mount it, create an empty folder, then issue command...
sudo mount -t ext4  -o loop ./data.raw.img [new_folder_name]/
You can the find all the files in the folder you created. When you're done with the changes you want to make. Use this to make an Android image for fastboot.
sudo make_ext4fs -s -l [size_of_partition_in_bytes] -a data ./data data_new.img
The output will be the file data_new.img. Then you just use fastboot to flash like you normally would.