Skip to content

Instantly share code, notes, and snippets.

@mvidaldp
Created April 11, 2022 12:43
Show Gist options
  • Save mvidaldp/84926c3e6e0d980a9833d8dbee93f0c8 to your computer and use it in GitHub Desktop.
Save mvidaldp/84926c3e6e0d980a9833d8dbee93f0c8 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.

@EMREOYUN
Copy link

If you land there because of MIUI nonsense, you can use sm partition disk:179,32 public command to revert it. Execute the command, then remove the SD card and put it back. It will see the card afterward. Some apps can raise errors, you can re-format to solve.

@kraftwerk28
Copy link

kraftwerk28 commented Feb 18, 2024

For my phone, using sm partition <disk> mixed <percentage> did the opposite, i.e. the percentage specified was applied to public partition, not private. So check the result with df -H after you done partitioning and still have the chance to fix it just in case.

@fapkamaster
Copy link

galahad:/ $ sm partition disk:179,128 public
Error: android.os.DeadObjectException

Then device reboots and gets stuck at logo (same on Xiaomi and Samsung phone). This is what happens when I try to format SD card from Android GUI, too.

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