I had rooted my Android Lollipop 5.1.1 phone and installed Link2SD and linked installed apps on ext4 7GB 2nd partition of external SD card of 16GB size . The apps installed occupied 6.5GB space and I am getting low space now. I got 64GB external SD card and want to dedicate 30GB.

I created image of 7GB 2nd partition of external SD card through following command:

dd bs=4k count= if=/dev/block/mmcblk1p2 | gzip -5 -c > /storage/sdcard1/sdcard2root.img.gz

Now whats the way to clone this image to a 30GB partition?

  • note that (gzip) compression only works on /dev/block/dm-0 (but not actually on /dev/block/mmcblk0p30) because of encryption
    – alecxs
    Sep 28 at 15:13

It's easy to achieve on a Linux PC:

  • Attach both SD cards to PC.
  • Dump 2nd partition from old SD card to new one. It's also possible directly from Android device. See Creating Partition Dump.
  • Resize filesystem size to 30GB (the new partition size) using resize2fs.


The above approach works on Android too if you are able to attach new SD card through USB OTG SD card reader, while the old one is inside phone.

Or you can do it in 2 steps, as you are already trying:

  • Create partition dump:

    ~# gzip -9ck /dev/block/mmcblk1p2 >/storage/sdcard1/sdcard2root.img.gz

    You can use dd or cat or even cp. Make sure you have enough space on primary external (physically internal) storage to save dumped (and optionally compressed) image of SD card's 2nd partition.

    Compression is useful only with sparseness. To avoid copying freed filesystem blocks (of deleted files) use e2image -rap. Or discard logical to physical block mapping using fstrim (on mounted filesystem) or e2fsck -E discard, and drop page cache using sync; echo -n 1 >/proc/sys/vm/drop_caches.

  • Insert new SD card and do partitioning using parted or gdisk or fdisk.

  • Write partition image to new SD card:

    ~# gzip -dck /storage/sdcard1/sdcard2root.img.gz >/dev/block/mmcblk1p2
  • Maximize filesystem size to partition size:

    ~# resize2fs /dev/block/mmcblk1p2


Another method is to only copy/move filesystem contents (files, directories etc.) and not the whole filesystem structure. But files' metadata needs to be preserved, or things may break (since the partition is to be mounted inside /data). It includes timestamps, permission mode, owner, group and extended attributes, particularly SELinux contexts. Some executable binaries (in /system) might also have file capabilities set (saved as extended attributes) but that's usually not required for user data. Other metadata like ACLs (also saved as extended attributes) and file attributes (inode flags) are not generally used on Android devices.

On Linux tools like rsync (or even cp) can preserve the required metadata. For reference see this and this answer. On Android (to move the contents in 2 steps) tar is a good choice:

~$ cd /path/to/old_sdcard/mountpoint/
~$ tar --create --preserve-permissions --selinux --verbose --gzip --file=/storage/sdcard1/sdcard2root.tar.gz .

Insert new SD card, do partitioning (if required), and create filesystem using mkfs.ext4 (by default it takes whole partition). To restore backup:

~$ cd /path/to/new_sdcard/mountpoint/
~$ tar --extract --preserve-permissions --selinux --verbose --gunzip --file=/storage/sdcard1/sdcard2root.tar.gz
  • thanx for answering i will try it and let you know i have windows so i cant try linx option but will try e2image or dd commands thanx a lot again Jan 3 '20 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.