📢 适用恩山 hoiw 编译固件 Flash_Armbian_25.05.0_rockchip_efused-wxy-oec_bookworm_6.1.99_server_2025.03.20.img
使用 Sytemd 服务 开机自动关闭 LED
1、创建脚本文件led-off.sh
并上传到目录/usr/local/bin/led-off.sh
#!/bin/bash
for led in blue-led green-led red-led; do
echo none > /sys/class/leds/$led/trigger
echo 0 > /sys/class/leds/$led/brightness
done
2、设置脚本文件的执行权限
sudo chmod +x /usr/local/bin/led-off.sh
3、创建 Systemd 服务文件led-off.service
并上传到目录/etc/systemd/system/led-off.service
[Unit]
Description=Disable LEDs at boot
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/led-off.sh
[Install]
WantedBy=multi-user.target
4、启用并启动服务
sudo systemctl daemon-reexec
sudo systemctl enable --now led-off.service
5、重启后执行
systemctl status led-off.service
如果看到状态为 active (exited)
,说明已经成功执行, LED 保持关闭状态。
恢复初始灯光控制(撤销 systemd 控制)
1、停止并禁用 Systemd 脚本服务
sudo systemctl disable --now led-off.service
这条命令会停止当前的 LED 关闭脚本执行,并防止它在下次开机时运行。
2、 删除相关文件(可选)
删除脚本文件
sudo rm /usr/local/bin/led-off.sh
删除 systemd 服务文件
sudo rm /etc/systemd/system/led-off.service
重新加载 systemd
sudo systemctl daemon-reexec
重启
/sbin/reboot
开机后,LED 恢复到以前的状态。
评论区