Skip to content

Instantly share code, notes, and snippets.

@mateuszszulc
Forked from mvidaldp/sdcard_fix.md
Created October 16, 2023 11:28
Show Gist options
  • Save mateuszszulc/3eb6bfb28e4ba3c1486f4d39a4823e89 to your computer and use it in GitHub Desktop.
Save mateuszszulc/3eb6bfb28e4ba3c1486f4d39a4823e89 to your computer and use it in GitHub Desktop.
SD card formating fix via ADB shell when Android GUI fails (internal, portable/external or mixed). Works on Retroid Pocket 2+

I wrote this short tutorial because extending my internal storage using my new micro SD card on my Retroid Pocket 2+ failed all the time. Only setting it up as portable/external worked. However, this instructions should work in any Android 5.0+ device.

So, in case you have problems setting up your SD card on your Android device via graphical interface (setting up storage as extended internal memory or portable), and you get a corrupted SD card or any other error, follow these steps to fix it via adb shell:

  1. Make sure you have adb access to your Android device: Settings > System > About, touch/click on Build number until Developer options are enabled:
  2. Go to Settings > System > Developer options and enable USB debugging.
  3. Assuming you have adb installed on your remote terminal run the following:
    adb shell
  4. Check if your device supports adopting SD card storage as internal by:
    sm has-adoptable
  5. If you get true, you can set up sd card storage to extend the internal storage of your device. Otherwise (false), you can only set it up as portable/external (like a normal connected storage drive). In any case, ensure your device enforces this mode by:
    sm set-force-adoptable on
  6. Check your sd card disk id:
    sm list-disks
  7. Partition your SD card (use your disk id):
    • Only as extended internal storage:
      sm partition disk:179,32 private
    • Only as portable (external) storage:
      sm partition disk:179,32 public
    • Mixed (part internal and part portable storage):
      sm partition disk:179,32 mixed 50
      The value after mixed is the ratio (%) of internal. The rest (100 - internal ratio) will be partitioned as public.
  8. Once it's partitioned, you only need to format it. But first you need to know the id of your volume (partitions):
    sm list-volumes
  9. Format your volume or volumes:
    sm format private:179,34
  10. Then you should be able to mount your new volume or volumes from Android's graphical interface. You can also do it via shell:
    sm mount private:179,34
    In case you don't see your new volume mounted correctly (e.g. wrong capacity displayed), just reboot your device and it should be fixed.

Important: Make sure you input the right disk and volume ids to run the commands. They probably won't be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment