I adopted an SD card as internal memory and one day it just suddenly stopped working.

With tremendous help from the member @alecxs I was able to make an img copy of it and browse the files in it. Here is some of the basics of how that was done.

I'm not sure why it failed on the phone since if it was a physical problem with the SD card then shouldn't it NOT have been possible to read or decrypt it?

In any case, I have another (new) SD card and I would like to clone the old one on it so that I can effectively start using it as if it was the old one...basically everything to be as it was pre-SD card failure.

Is there a way to do that? How?

I'm able to see my photos which is a HUGE relief but my concern now is the app data that is un-viewable unless it's put back in the phone and opened with it's app.

  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Andrew T.
    Commented Jul 28, 2022 at 20:38

1 Answer 1


Try the following

  • first copy sd.img to new MicroSD Card (it will finish unsucessful "error writing, not enough space")

  • create another sd2.img from new MicroSD Card (the one which ended unsucessful, we just need raw sd2.img with correct size)

  • run kpartx to map sd.img into /dev/mapper/loop1p1, /dev/mapper/loop1p2 and sd2.img into /dev/mapper/loop2p1, /dev/mapper/loop2p2 (may vary)

  • create two new block devices for /dev/mapper/loop1p2 and /dev/mapper/loop2p2 (see link in your question)

  • now lets assume /dev/mapper/loop1p2 is /dev/mapper/crypt1 (= sd.img) and /dev/mapper/loop2p2 is /dev/mapper/crypt2 (= sd2.img)

  • crypt1 should be mountable as ext4 partition to any mount point (that's your old MicroSD Card)

  • crypt2 is probably broken because of less size and must be formatted with mke2fs

    mke2fs -t ext4 /dev/mapper/crypt2

  • now crypt2 should be mountable as ext4 too, mount to another mount point

  • next, copy all files from one mount point to another. make sure you preserve secontext, xattrs, uid and file permissions. this can be done with busybox cp -ac or tar --selinux --xattrs -p

i am on mobile and busy today, will improve that answer later. btw i am not sure that's how it works at all (the dmsetup part)

good luck

  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Firelord
    Commented Oct 23, 2020 at 6:21

You must log in to answer this question.

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