1

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.

27
  • 2
    ddrescue <old card> <new card>. Done. But if reading sectors fails due to corruption in large areas, filesystem may not get mounted in Android. Also won't work if you forgot the card in Android. Sep 6 '20 at 5:15
  • @IrfanLatif Thanks. Could you please give and example for <old card> <new card>? And what do you mean by "forgot the card in Android?
    – JJrussel
    Sep 6 '20 at 7:26
  • 2
    How to use ddrescue: unix.stackexchange.com/a/14577/262728. Forgetting SD card: android.stackexchange.com/questions/181476 Sep 6 '20 at 7:40
  • 1
    sudo dd if=/media/xubuntu/404CCE454CCE3606/sd.img of=/dev/sdc bs=4M; sync android.stackexchange.com/a/186956 be careful with that! make sure /dev/sdc is your MicroSD Card (otherwise your hard drive may erased)
    – alecxs
    Sep 6 '20 at 9:09
  • be aware there is a slight chance that 1:1 cloning will corrupt new MicroSD Card, too android.stackexchange.com/q/221269
    – alecxs
    Sep 6 '20 at 9:15
0

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

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

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.