HOWTO Control LED Lights

From LinuxReviews
Jump to navigationJump to search

The Linux kernel has had a user-controllable LED subsystem since version 4.17. This subsystem makes LED available and controllable led lights show up in the special /sys/class/leds/ folder. Sending commands to files in that folder can make led lights indicate everything from disk activity to battery status.

Inspecting Your LED Lights

A simple /sys/class/leds/ will show you what LED controls are available. That command may show something like

input3::capslock input3::numlock input3::scrolllock mmc0:: phy0-led

Those folders will have a file called trigger which can be abused by sending a command to it. LED triggers can be any of

none usb-gadget usb-host kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock AC0-online BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid disk-activity disk-read disk-write ide-disk mtd nand-disk panic mmc0 mmc1 mmc2 rc-feedback rfkill-any rfkill-none bluetooth-power rfkill0 rfkill1 audio-mute audio-micmute rfkill3 phy0rx phy0tx phy0assoc [phy0radio] hci0-power rfkill5

You can change a LED lights "trigger" by issuing a valid directive to a LED lights trigger file. For example,

echo 'disk-activity' > /sys/class/leds/phy0-led/trigger

will make the phy0-led (typically a WLAN light on laptops) show the disk activity.

As good as all setups will have inputX::capslock, inputX::numlock and inputX::scrolllock available (they are typically present even if the keyboard don't actually have any LED lights at all). The scroll lock light is a good choice if you want to use a LED light for something since that key is rarely used. The keyboards input number will vary and you may have more than one so the following command may be handy:

for led in /sys/class/leds/input?::scrolllock/trigger ;do echo 'disk-activity' > $led ;done


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.