FORUMS

[GUIDE] How to restore logd to your device/fix adb logcat read failure or empty logs

81 posts
Thanks Meter: 119
 
Post Reply Email Thread
A few days ago, I flashed a zip onto my phone that set SELinux to permissive. However, there was a problem: it deleted logd, which is essential to adb logcat. Considering I'm an Android developer, that isn't a good thing! It took me a bit to figure out how to get it back, so I'm making this guide to share with you guys to help whatever poor soul has to fix this next.

Note that these steps were designed with Linux in mind, though they might be adaptable to Cygwin/OSX with some effort.

Also, make sure you delete any SELinux permissive scripts from init.d/su.d first!

Prerequisites
  • The OTA or custom rom zip that your device is currently running
  • adb
  • simg2img (available in the Ubuntu software repositories)
  • sdat2img (available here)

Instructions

Put your OTA/custom ROM zip file in a new folder and unzip it (this example is using the Pure Nexus ZIP):

Code:
mkdir restore_logd
cp pure_nexus_hammerhead-7.0-20161025-HOMEMADE.zip restore_logd
cd restore_logd
unzip pure_nexus_hammerhead-7.0-20161025-HOMEMADE.zip
Now, look for a file named either system.new.dat or system.img.

If you have system.img, then run:

Code:
simg2img system.img system.raw.img
If you have system.new.dat AND system.transfer.list, instead run:

Code:
sdat2img.py system.transfer.list system.new.dat system.raw.img
Either way, you should now have a file named system.raw.img. Next, mount it:

Code:
mkdir system_mnt
sudo mount -t ext4 -o loop system.raw.img system_mnt
This will mount the system image onto the system_mnt folder.

Plug in your device to your computer and make sure USB debugging is enabled, then run:

Code:
adb push system_mnt/bin/logd /sdcard/logd
adb shell
You should now be in a shell connected to your device. Inside, run:

Code:
su
mount -o rw,remount /system
cp /sdcard/logd /system/bin/logd
chmod 755 /system/bin/logd
exit
This will install the logd binary and close the shell.

This next part is very important! Making sure you closed the adb shell and are still inside the directory you created, run:

Code:
ls -Z system_mnt/bin/logd
If the output looks like this:

Code:
? system_mnt/bin/logd
then you have nothing else to do. Otherwise, it might look a bit like this:

Code:
u:object_r:logd_exec:s0 system_mnt/bin/logd
Copy part before the path; in this case, it's:
Code:
u:object_r:logd_exec:s0
Then, run:

Code:
adb shell su root chcon permission /system/bin/logd
replacing permission with the string you copied.

Now you can unplug and restart your device; logd should now be fully working!

Last but not least, run:

Code:
sudo fusermount -u system_mnt
to unmount the system image from your computer.

Enjoy!
The Following 3 Users Say Thank You to refi64 For This Useful Post: [ View ] Gift refi64 Ad-Free
19th February 2019, 04:01 PM |#2  
Junior Member
Thanks Meter: 2
 
More
Execute command failed while replacing permission

Code:
adb shell su root chcon permission /system/bin/logd
u:object_r:logd_exec:s0
/system/bin/sh: <stdin>[1]: u:object_r:logd_exec:s0: not found
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes