Where is SD card in Android file system?

An SD card, or Secure Digital card, is a portable flash memory card used in many Android devices to provide additional storage space. SD cards allow you to store media files like photos, videos, and music, as well as documents, apps, and other data beyond what will fit on your device’s internal storage.

On Android phones and tablets, the SD card slots in next to the SIM card and can be easily removed and transferred between devices. Using an SD card is helpful for managing your storage and accessing your files across devices. It also allows you to free up space on your Android’s built-in storage by storing less frequently used apps and files to the removable SD card.

When using an SD card with an Android device, the card appears as external or removable storage within the Android file system. In order to locate and access the SD card storage, you need to understand where Android mounts removable SD cards and how to navigate to the SD card path using various file manager apps and tools.

Android File System Basics

The Android file system is organized in a hierarchy consisting of folders and files. At the top level is the root folder “/”. Under the root folder are several other standard folders that contain the operating system, applications, and user data (1).

Some key folders in the Android file system hierarchy include (2):

  • /system – Contains operating system files and folders.
  • /data – Contains user and app related data.
  • /cache – Contains temporary cached data used by apps.
  • /storage – Mount points for external storage devices like SD cards.

The /data folder contains important subfolders like /data/data which holds app specific data files, and /data/media which contains multimedia files. The /storage folder is where external SD cards are mounted and allows access to SD card content.

Overall, the Android file system organizes files and folders in a structured hierarchy starting from the root folder. This allows organized storage and access of the Android operating system, apps, and user data.

Where External SD Cards Are Mounted

On Android devices, external SD cards are typically mounted in one of two locations:

/sdcard – This is the generic mount point for external storage on many Android devices. Historically, this path was used for SD cards, but on modern Android devices it may point to internal storage instead. Still, external SD cards are often mounted here for backwards compatibility.

/storage/sdcard1 – More recent versions of Android use this path for mounting external SD cards. The number may increment depending on how many external storage devices are mounted (e.g. /storage/sdcard2). This provides a clearer separation between internal storage (/storage/emulated) and removable SD cards.

So in summary, external SD cards can generally be found at either /sdcard or a /storage/sdcard path like /storage/sdcard1. The exact mount point depends on the device manufacturer’s implementation.

To programmatically find the external SD card path on Android, the getExternalStorageDirectory() method will return the primary external storage, which maps to one of these locations.

Using a File Manager to Locate the SD Card

One easy way to find where your SD card is mounted in Android’s file system is by using a file manager app. There are many free file manager apps available on the Google Play Store, such as SD Card Manager and SD Card Manager For Android.

To locate your SD card using a file manager app:

  1. Open the file manager app on your Android device.
  2. Look for a folder called “sdcard” – this is where external SD cards are typically mounted in Android. The sdcard folder may be in the root folder or under a folder like “storage”.
  3. Navigate into the sdcard folder and you will see all the files and folders on your external SD card.

Using a file manager provides a quick visual way to find and access your SD card contents on an Android device. Just remember to look for the sdcard folder within the app.

Finding SD Card Path via Terminal

One way to locate the mount point of the external SD card is by using the df (disk free) or mount commands in a terminal app or adb shell. These commands will show all the currently mounted filesystems and their mount points.

For example, running df may show a mount point like /storage/1234-ABCD which is the external SD card. The exact path can vary depending on the device and SD card. Using the terminal to find the SD card path is useful for developers or advanced users who are comfortable with the command line.

Here is an example command to locate SD card mounts:
df | grep /storage

And to show just the mount point path:

df -h | grep /storage | cut -d" " -f1

This can help identify which path corresponds to the removable SD card, rather than internal storage.

Programmatically Getting the SD Card Path

Android provides a simple way to programmatically get the path to the SD card using the Environment class. The key method is Environment.getExternalStorageDirectory(), which will return the root path to the SD card as a Java File object.

For example:


File sdCard = Environment.getExternalStorageDirectory(); 
String sdCardPath = sdCard.getAbsolutePath();

This will store the full path to the SD card mount point in the sdCardPath variable, which can then be used to access files and directories on external storage.

The getExternalStorageDirectory() method will return null if external storage is not currently available, so it’s best to check for null before using the path.

Changing Default SD Card Mount Point

The default mount point for external SD cards on Android is /sdcard. However, this location can be changed by modifying a configuration file called vold.fstab. This file controls how removable storage media like SD cards are mounted by the Android system.

To change the default mount point for external SD cards, you need root access on your Android device. Then, open the vold.fstab file located at /system/etc/vold.fstab and edit the mount point path. For example, to change it to /external_sdcard, the line would look like:

dev_mount external_sdcard /external_sdcard auto /devices/platform/msm_sdcc.1/mmc_host*

After changing and saving vold.fstab, reboot your Android device. Now the system will mount external SD cards at the new /external_sdcard path instead of /sdcard. This provides more flexibility in configuring Android’s file system mount points.

Source: How to change mount points

Potential Issues Locating SD Card

There are a few potential issues that can make locating the SD card difficult on Android devices:

Adoptable storage – Android 6.0+ allows you to format an SD card as internal storage through a process called adoptable storage. When this is done, the SD card is encrypted and acts as internal storage, becoming indistinguishable from the built-in storage. The adoptable storage will not show up at the standard external SD card path like /storage/SDCard1 (source: https://source.android.com/docs/core/storage/adoptable).

Multiple external cards – Some Android devices support multiple external SD cards, which can lead to confusion over the proper path to each one. For example, you may have /storage/SDCard1 and /storage/SDCard2. Using a file manager is the easiest way to explore and locate the actual external storage paths on your device.

Removable vs non-removable SD cards – SD cards that physically click or slide into the device are obviously removable. However, some phones have SD card slots that hold the card permanently inside. Though not technically removable, these types of SD cards still mount at external storage paths like /storage/SDCard1.

Custom ROMs – With a custom ROM installed, the default mount points for external storage may be changed from the standard paths. This means an external SD could be mounted somewhere other than the typical /storage/SDCard1 location.

Accessing Files on SD Card

Once you know the path to the external SD card, reading and writing files is straightforward. The Android developer documentation provides examples for accessing files in both Java and Kotlin.

To read a file from the SD card, you can use standard Java file IO like FileInputStream or scanner classes. For example:

File file = new File(sdCardPath, "file.txt");
Scanner scanner = new Scanner(file); 
while (scanner.hasNextLine()) {
  String line = scanner.nextLine();
  // process line
}

To write a file, use FileOutputStream or PrintWriter. For example:

File file = new File(sdCardPath, "file.txt");
PrintWriter writer = new PrintWriter(file);
writer.println("Hello world!");
writer.close();

The big thing is knowing the full path to the SD card. Once you have that, reading and writing files is no different than accessing your own internal storage.

Conclusion

In summary, Android mounts external SD cards under the /sdcard or /storage directory by default. The exact location can be found using a file manager app or terminal command. Developers can also programmatically get the external SD card path.

While the mount point is typically configurable, some devices have restrictions. Overall though, the external SD card can be reliably accessed through the consistent abstracted path provided by Android’s media storage framework.

The key points covered were:

  • Android uses a unified abstraction for primary and secondary storage
  • External SD cards are mounted under /sdcard or /storage
  • The File Manager app can locate the SD card path
  • The getExternalStorageDirectory() method returns the primary shared path
  • Terminal commands like df can show SD card mount points
  • Apps can get the SD card path programmatically
  • The default mount point is configurable but some devices restrict this
  • Accessing the consistent SD card path allows apps to use storage space

With an understanding of where external SD cards are located in the Android file system, developers can better utilize expanded storage for apps.