KISS 🇺🇦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

/sdcard "Permission denied" on Android

| comments

I’ve found some old notes about rooting a Motorola G4 Android phone and a puzzling issue I stumbled upon then. It may be useful to someone even though I couldn’t reproduce it now and don’t remember all the details.

I had a Moto G4 phone and it’s possible to officially unlock its bootloader in order to root it, remove some preinstalled (goog’s) crap and possibly install another firmware (Android is notoriously bad with software updates, Motorola was not very bad, they had occasional security updates). I followed one of the unlocking and rooting guides online: backed up as much stuff as I could (which is not much on a non-rooted phone), unlocked the bootloader by getting a code from Motorola, replaced the boot image, flashed TWRP, installed SuperSU, and replaced the kernel with ElementalX G4 because something didn’t work with the stock one.

Then I installed ABBYY Lingvo in the new system, but it was crashing on startup. I discovered that its directory on the internal storage (which I believe was in /sdcard/Android/) was empty and was trying to adb push it from the backup, but got “permission denied”. In fact, I couldn’t create any directory on /sdcard/. The permissions and owner on the directory were correct. Searching online didn’t find a solution, I tried a number of things, even editing platform.xml to change a setting. However when I booted into TWRP, I could write files to SD card fine.

Solution

After banging my head against the wall for a while, I noticed that when I cd’d into /sdcard as root, the working directory displayed as /storage/emulated/0; the second piece of the puzzle was that it’s parent directory was actually mounted from /data/media. I checked /data/media/0 and saw the real permissions: root:root — I had probably restored those directories from a backup in TWRP, which made root their owner. Changing the owner to media_rw:media_rw did the trick.

Trying to reproduce it

I couldn’t reproduce this issue now after restoring an old backup and the /sdcard symlink is also different (although I have not done any significant changes for a while):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
athene:/ $ ls -l /sdcard/
total 53848
drwxrwx--x 2 root sdcard_rw     4096 2019-02-03 21:30 Alarms
drwxrwx--x 5 root sdcard_rw     4096 2018-03-28 19:28 Android
drwxrwx--x 4 root sdcard_rw     4096 2019-02-07 06:17 AnkiDroid
athene:/ $ ls -ld /sdcard/
drwxrwx--x 28 root sdcard_rw 4096 2020-09-04 07:42 /sdcard/
athene:/ $ ls -ld /sdcard
lrwxrwxrwx 1 root root 21 2019-02-04 07:49 /sdcard -> /storage/self/primary

athene:/ $ su
athene:/ # ls -ld /storage/self
drwxr-x--x 2 root root 60 2021-04-07 08:32 /storage/self

athene:/ # ls -ld /storage/emulated/
drwx--x--x 4 root sdcard_rw 4096 2019-02-03 21:30 /storage/emulated/
athene:/ # ls -ld /storage/emulated/0/
drwxrwx--x 28 root sdcard_rw 4096 2020-09-04 07:42 /storage/emulated/0/
athene:/ # ls -l /storage/emulated/0/
total 53848
drwxrwx--x 2 root sdcard_rw     4096 2019-02-03 21:30 Alarms
drwxrwx--x 5 root sdcard_rw     4096 2018-03-28 19:28 Android
drwxrwx--x 4 root sdcard_rw     4096 2019-02-07 06:17 AnkiDroid

Well, /storage/emulated/0 also lists /sdcard, as before. Who knows what happened there.

Constant disconnects

PS. While connecting the Moto G4 to the mac to get adb shell, the device kept disconnecting every 5 seconds and the shell would also last only for a few seconds. Replacing the cable didn’t help. Then I noticed a message from Calibre, which was running in the background:

motorola Moto G (4): The device motorola Moto G (4) is not allowing connections. Unlock the screen on the motorola Moto G (4), tap “Allow” on any connection popup message you see, then either wait a minute or restart calibre. You might also have to change the mode of the USB connection on the motorola Moto G (4) to “Media Transfer mode (MTP)” or similar.

I didn’t need to enable file transfer, so closing Calibre worked to stop the disconnects.

Comments