1

A few weeks ago I integrated my SD card to use as phone memory. Everything was fine until a couple of days ago.

All of a sudden I saw the "insert SD card" notice appear on the notification bar. I open the back cover but the SD card looked like it was in place. I remove it and insert it back and the notice disappears. But then I notice that when I go to file explorer (FX) to access my files, it says "Access was denied". I can't access anything that is on my phone memory, although the apps are working. I guess system files are OK, but everything else is not.

My phone is rooted so I tried to access the files through TWRP but I can only see system folders.

Phone is a Moto C plus. Nougat.

1
2

You can recover some files from corrupted MicroSD Card. adoptable-storage is encrypted, it requires the encryption key from the source device. In your case you are lucky your device is rooted

  • insert MicroSD Card into PC Card Reader. figure out which one is the correct block device (/dev/sdc) with sudo blkid

  • mount your hard drive (/media/xubuntu/404CCE454CCE3606). check free disk space with df -h

  • clone 1:1 disk image of the entire MicroSD Card with gddrescue

    sudo -i
    apt install gddrescue
    cd /media/xubuntu/404CCE454CCE3606
    ddrescue -n -b512 -r3 /dev/sdc sd.img gddrescue_sd_img.log
    
  • install android platform-tools

    apt install android-tools-adb android-tools-fastboot
    
  • connect your device in recovery mode (TWRP)

  • get the encryption key file expand_5f5e697154132edfaa6fca7ac23cde2a.key (root access required)

    adb devices
    adb pull /data/misc/vold
    
  • read the 16-bytes hex encryption key (ae126af293501cd130db0637372e8911)

    ls vold
    hexdump -v vold/expand_5f5e697154132edfaa6fca7ac23cde2a.key
    
  • map the image file to create loop devices

    kpartx -av /media/xubuntu/404CCE454CCE3606/sd.img
    
  • get partition size (62299103) and decrypt the 2nd partition (/dev/mapper/loop1p2)

    blockdev --getsize /dev/mapper/loop1p2
    dmsetup create crypt1 --table "0 62299103 crypt aes-cbc-essiv:sha256 ae126af293501cd130db0637372e8911 0 /dev/mapper/loop1p2 0"
    
  • when successfull a new (decrypted) block device /dev/mapper/crypt1 (ext4) will created

  • mount the partition (skip this step Xubuntu will auto mount)

    mkdir /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448
    mount -t ext4 -o ro,noexec,noload /dev/mapper/crypt1 /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448
    
  • Open new terminal (CTRL + ALT + T) and start File Manager (root session) from command line:

    sudo thunar /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448
    
  • in File Manager enable - View - Show Hidden Files
    you should see some directories

    app
    local
    lost+found
    media
    misc
    user
    user_de
    
  • you can now browse media directory for Internal Storage and copy your Pictures to your hard drive

Be aware you can't copy app directory to windows hard drive, because linux permissions and file names aren't compatible with NTFS file system type

  • however, you can create tarball archive to preserve the whole partition content including all metadata

     sudo -i
     cd /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448
     tar --selinux --xattrs -H posix --numeric-owner -vcp * | gzip -cn > /media/xubuntu/404CCE454CCE3606/sdcard.tar.gz
    
  • sdcard.tar.gz can be unpacked with 7-zip in windows, or restored from twrp command line with GNU tar

16
  • on the last step, can you please double check disk usage of sd.img? are there files in it? (if you already have sd.img skip creating again and start with kpartx) when mounted run df -h /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448 or find -type f /media/xubuntu/fa6c4c4c-846e-4c6f-8c02-e93cf5ebf448 – alecxs Oct 22 '20 at 15:45
  • I can see in the phone system root folder in the phone. And it has only 203 MB as well. My concern is...if I "forget" the SD card, will I lose the files from the "phone" internal storage? Because right now I can't access the phone internal storage. I can only see the system folder. But I can see the folders in the adopted SD card (which are almost empty). – JJrussel Oct 22 '20 at 20:22
  • but what about the files in sd.img? – alecxs Oct 22 '20 at 20:53
  • Size: 30G | Used: 239M | Avail: 29G – JJrussel Oct 22 '20 at 21:09
  • Could it be that it was saving most of the data (or all of it) in the internal phone memory instead of the SD card even though they are both integrated? But now my files are being held hostage in the phone memory. If I want to "unlink" or "unadopt", what are my choices? From what I can see, there are 3 ways...1) insert a new SD card and adopt it as internal storage WITHOUT "forgetting" the first SD. 2) "Forget" the adopted SD 3) "Migrate" the files from the internal storage option (even though it says "it will free 0 bytes on SD card"). And then "format" the SD card as portable". Which one? – JJrussel Oct 22 '20 at 21:42

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.