(自用)在派上设置自启动时的问题

从你提供的/etc/rc.local文件内容来看,存在一些问题可能导致rc-local.service启动失败。我将逐一指出问题并提供修正建议。

问题 1:Python 脚本路径错误

在文件的最后部分,你写的是:

#!/bin/bash
/usr/python3 /path/to/your/ser.py
exit 0
  • /usr/python3路径不正确,通常Python 3的路径是/usr/bin/python3

  • /path/to/your/ser.py是占位符路径,你需要将其替换为实际的Python脚本路径。

问题 2:文件格式问题

你的文件中包含了两行#!/bin/sh#!/bin/bash,这是不正确的。文件的开头只能有一个shebang行,且应该与文件内容的语言一致。如果文件内容是sh脚本,就使用#!/bin/sh;如果是bash脚本,就使用#!/bin/bash

问题 3:insmod命令可能失败

日志中显示insmod: ERROR: could not insert module /lib/modules/rtw88/...,这表明内核模块加载失败。可能的原因包括:

  • 模块路径错误或模块文件不存在。

  • 内核版本与模块不匹配。

  • 权限不足。

问题 4:iw命令可能失败

日志中显示iw wlan0 set power_save off可能失败,原因可能是:

  • wlan0接口不存在。

  • iw命令未安装或路径错误。

修正后的/etc/rc.local文件

以下是修正后的/etc/rc.local文件内容:

#!/bin/bash
. /etc/user_script/led_trigger.sh &

cpufreq-set -c 0 -g performance
cpufreq-set -c 1 -g performance
cpufreq-set -c 2 -g performance
cpufreq-set -c 3 -g performance

echo c > /proc/irq/20/smp_affinity

insmod /lib/modules/rtw88/rtw_core.ko
insmod /lib/modules/rtw88/rtw_sdio.ko
insmod /lib/modules/rtw88/rtw_8821c.ko
insmod /lib/modules/rtw88/rtw_8821cs.ko

#sleep 2
iw wlan0 set power_save off

if [ -f "/etc/user_script/resize-once" ]; then
    /etc/user_script/resize.sh >/dev/null 2>&1 &
    rm /etc/user_script/resize-once
fi

# 确保Python脚本路径正确
/usr/bin/python3 /path/to/your/ser.py &

exit 0

修正说明

  1. Shebang行:统一使用#!/bin/bash

  2. Python路径:将/usr/python3改为/usr/bin/python3,并确保路径正确。

  3. Python脚本路径:将/path/to/your/ser.py替换为实际的Python脚本路径。

  4. 后台运行Python脚本:在/usr/bin/python3 /path/to/your/ser.py后添加&,使其在后台运行。

  5. 其他命令:确保所有命令路径和参数正确。

验证步骤

  1. 保存文件并设置权限

    sudo chmod +x /etc/rc.local
  2. 手动运行脚本测试

    sudo /etc/rc.local start

    检查是否有错误输出。

  3. 检查日志: 如果手动运行没有问题,但rc-local.service仍然启动失败,查看更详细的日志:

    sudo journalctl -xe
  4. 重新启动服务

    sudo systemctl daemon-reload
    sudo systemctl start rc-local.service
    sudo systemctl status rc-local.service