Permission Denied when Push File to /mnt/sdcard on Android 11

When we use adb push $file /mnt/sdcard on Android 11 devices, we will encounter adb: error: stat failed when trying to push to /mnt/sdcard/: Permission denied error message. This article will introduce how to solve the problem and share related thoughts.

Solution

Change the path from /mnt/sdcard to /sdcard, which means adb push $file /sdcard

The difference between /sdcard and /mnt/sdcard

Regarding these two symlinks, they have to be traced back to the period before and after Android 4.0, and there is less information available for research. Before Android 4.0, the /mnt/sdcard should be used. After the system is upgraded, to be compatible with the old version, this Pointing becomes symlink.

On systems below 6.0, there is also /storage/sdcard/legacy, and on 6.0 and above, it become /storage/self/primary.

Now, I found an Android 6.0.1 mobile phone, let’s take a look at the symlinks left over from various historical versions, and what they look like in the shell.

1
2
$ adb shell ls -al /mnt | grep sdcard
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /sdcard

As you can see, /mnt/sdcard points to /sdcard

1
2
$ adb shell ls -al / | grep sdcard   
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /storage/self/primary

And /sdcard points to /storage/self/primary

1
2
$ adb shell ls -al /storage/self/      
lrwxrwxrwx root root 2021-02-16 11:17 primary -> /mnt/user/0/primary

/storage/self/primary points to /mnt/user/0/primary

1
2
$ adb shell ls -al /mnt/user/0/primary
lrwxrwxrwx root root 2021-02-16 11:17 primary -> /storage/emulated/0

Continue to trace back, /mnt/user/0/primary points to /storage/emulated/0, which is the path of the SD card that we are familiar with.

Why is /mnt/sdcard invalid on Android 11

As can be seen from the above, /mnt/sdcard is a symlink, which can be viewed on Android 11 devices through ls

1
2
$ adb shell ls -al /mnt | grep sdcard
l????????? ? ? ? ? ? sdcard -> ?

As you can see, although the soft link still exists, it can no longer be accessed normally, that is, the error of Permission denied shown in the title will be thrown.

For comparison, use the same command to view on the Android 6.0.1 device

1
2
$ adb shell ls -al /mnt | grep sdcard
lrwxrwxrwx root root 2021-02-16 11:17 sdcard -> /sdcard

This is the symlink that can be used normally.

Conclusion

Nowadays, very few apps support Android versions below 5.0, and each major version of the Android system is updated. In addition to the compatibility issues of the APP itself, it takes time to pay attention to compatibility issues in the same ecosystem.

More

/mnt stands for the mount , you will find files there when you mount your filesystem or devices.

Reference

  1. Confused by the many locations of the virtual /sdcard/
  2. Why did /sdcard/ turn into /sdcard/0/ with 4.2?
  3. Why is the SD-card mounted to “/sdcard/external_sd” instead of “/sdcard” (or “/mnt/sdcard”)?
  4. Android 11 adb push Permission denied
  5. How to list all the files in android phone by using adb shell?
  6. What is /mnt