写入以下内容:
# 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 publishe d 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=nosudo vi /etc/rc.local
#!/bin/bash # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will"exit 0"on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. #your shell #excample: /scu/autorun.sh exit 0其中,/scu/autorun.sh就是我需要运行的脚本
更改权限:
sudo chmod 775 /etc/rc.local
开启服务:
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
链接:
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
重启电脑查看:
sudo reboot
观察成功