[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!

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


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

mkdir restore_logd
cp restore_logd
cd restore_logd
Now, look for a file named either or system.img.

If you have system.img, then run:

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

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

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:

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

mount -o rw,remount /system
cp /sdcard/logd /system/bin/logd
chmod 755 /system/bin/logd
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:

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

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

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

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:

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

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
Execute command failed while replacing permission

adb shell su root chcon permission /system/bin/logd
/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)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes