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.
After banging my head against the wall for a while, I noticed that when I
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
/storage/emulated/0 also lists
/sdcard, as before. Who knows what happened there.
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.