Linux开机自启 stm32MP157 测试成功,添加rc.local

文章讲述了在Ubuntu18.04中,由于/etc/rc.local不再直接支持开机启动,作者介绍了使用systemd创建rc-local.service来实现开机自启的过程,包括创建启动文件、设置权限和服务配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用ubuntu18.04系统中发现,原来可以写入/etc/rc.local开机启动文件现在没有了,现在采用其他方式来做开机自启,方式亲测有效:

步骤一:在/etc文件夹里面创建 rc.local 添加开启启动文件,创建完成后,添加可执行文件

vi rc.local

chmod 777 rc.local
#!/bin/sh -e
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

#touch /var/lock/subsys/local


#以下是开启启动程序 :
/lib/firmware/tast.sh
#sleep(3)
#/lib/firmware/tcp.sh &

步骤二:进入/etc/systemd/system 文件夹创建 rc-local.service 文件(此文件不用加权限) 添加以下内容

vi rc-local.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

步骤三:使能rc-local服务

systemctl enable rc-local

步骤四:rc-local.service服务设置开机自启

systemctl enable rc-local.service

查看服务是否启动成功:systemctl is-active rc-local.service ——状态是active即为启动成功的,如果不成功则或者重启一下亦可:systemctl restart rc-local.service(此段重启为开机脚本rc.local文件重启

最后重启后查看添加的开机启动脚本是否正常运行;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值