When I create a gzip image of userdata partition (/dev/block/mmcblk0p29) it creates huge 6.8GB image, previously it was 350MB.

Is it possible through command-line to erase or wipe or delete space on userdata partition? I want to keep small compact compressed gzip or shadow images of clean unrooted and rooted partition on various dates and times.

I tried the following commands but nothing worked for me:

  1. fastboot erase userdata
  2. rm -r /data/*.*
  3. rm -r /sdcard/*.*

Still image is 6.8GB.

  1. dd if=/dev/zero if=/dev/block/platform/7824900.sdhci/by-name/userdata bs=8192
  2. dd if=/dev/urandom of=/dev/block/platform/7824900.sdhci/by-name/userdata bs=8192

/dev/zero and /dev/urandom not found in device.

  1. newfs
  2. iShredder 3 app
  3. Secure Eraser app
  4. Andro Shredder or Disk Sanitizer

But how will I format in unrooted while working in the Android userdata partition?

  1. Any adb shell command to clear, format or zero fill
  • This is a Q&A site, not a troubleshooting forum. Comments are not for extended discussion; this conversation has been moved to chat. To the asker: please edit the question according to the comment feedback to focus on a single, answerable issue.
    – Andrew T.
    Commented Jan 3, 2020 at 3:01
  • @IrfanLatif kindly post the comments in chat as answer so i can vote and accept it as this question you edited and explained and gave me answers for trim and zero fill and e2image that all worked a greatful thanks to you for all your efforts and precious advice Commented Jan 10, 2020 at 13:18

1 Answer 1


I guess your real purpose of this question is not what the headline suggests - secure erase your data - but instead you want to have a full backup of userdata including /data/media (downvote if I am wrong).

You have some options, most require additional binaries which you can copy to /cache partition or permanently integrate into your twrp /sbin:

  • e2image (thx @IrfanLatif)
  • make twrp backup of /data to internal storage and just adb pull -a /sdcard afterwards, which you can zip without worry about file permissions
  • just create tar.gz instead of img.gz with gnu tar (with --selinux --xattrs -p flags)
  • create empty disk image and copy all (mke2fs + busybox cp -ac) then compress img with gz (requires much disk space and underlying non-fat32 file system type)
  • permanent tweak for twrp

(I will improve this answer when I have time)

  • yes purpose is image backup userdata partition problem its creating image including empty space deleted data i want clear it first ... e2image is not found in system/bin kindly tell way to install in android.....twrp backup tried but dont copy media and all other files.........tar.gz with --selinux flag works in android 7 and i am using android lolipop 5.1.1 ......empty disk image and copy all (mke2fs + busybox cp -acv) then compress img with gz takes too much time .. and its recompressing is a lengthy procedure..... tweaking twrp i havent tried yet will try to see it... Commented Jan 2, 2020 at 13:35
  • i am pretty sure the gnu tar binary i have compiled is backwards compatible - if not, download for your platform open_gapps.zip
    – alecxs
    Commented Jan 2, 2020 at 14:20
  • 1
    i founded a command for trimming the device partition directly after unmounting it is it a safe a command e2fsck -E discard /dev/block/mmcblk0p29 (userdata partition block) Commented Jan 2, 2020 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .