linux、树莓派/etc/rc.local开机启动不运行的解决方法

支付宝内搜索 9155838 即可领现金红包 每天都能领哦

方法1

可能是/etc/rc.local没执行权限,直接赋予权限即可:
sudo chmod +x /etc/rc.local

尝试运行:
sudo systemctl daemon-reload

方法2

运行
sudo systemctl status rc-local

sudo systemctl status rc.local
查看提示信息:

[root@blog.dngz.net ~]# sudo systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
           /etc/systemd/system/rc-local.service.d
           └─ttyoutput.conf
   Active: failed (Result: exit-code) since Fri 2024-05-30 17:20:29 CST; 1h 21min ago
     Docs: man:systemd-rc-local-generator(8)

May 30 17:20:28 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility...
May 30 17:20:29 raspberrypi sudo[580]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/mount -o uid=pi,gid=pi /dev/sda1 /data
May 30 17:20:29 raspberrypi sudo[580]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 30 17:20:29 raspberrypi rc.local[576]: mount: /data: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.
May 30 17:20:29 raspberrypi sudo[580]: pam_unix(sudo:session): session closed for user root
May 30 17:20:29 raspberrypi systemd[1]: rc-local.service: Control process exited, code=exited, status=32/n/a
May 30 17:20:29 raspberrypi systemd[1]: rc-local.service: Failed with result 'exit-code'.
May 30 17:20:29 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.

可以看到/etc/rc.local其实是启动运行了的,只是其中mount命令出现了错误,再测试一下该命令:

[root@blog.dngz.net ~]# mount -o uid=pi,gid=pi /dev/sda1 /data
mount: /data: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.
果然出错了,直接不加参数mount试试
[root@blog.dngz.net ~]# mount /dev/sda1 /data
成功挂载,可能是之前一直用的pi用户以及ntfs分区格式,后来重新格式化为ext4,又更换了用户来登陆ssh操作导致的。

方法3

将/etc/rc.local里第一行的
#!/bin/sh -e
改为:
#!/bin/sh
保存、搞定

因为加了-e参数后,遇到一处错误就会退出整个脚本运行,导致认为/etc/rc.local没有执行的假象。

推荐文章

发表新评论