0%

Ubuntu20.04开机启动

1
2
3
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
cd /etc/systemd/system/
nano rc-local.service

rc-local.service 内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#  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
Alias=rc-local.service

创建 rc.local 文件

1
touch /etc/rc.local

赋予可执行权限

1
chmod 755 /etc/rc.local

编辑 rc.local

1
nano /etc/rc.local

文件内容

1
2
3
4
5
6
#!/bin/bash

# 这里开机执行的脚本
# 要卸载 exit 0 之前

exit 0

完成。

参考链接 https://blog.csdn.net/zhengchaooo/article/details/80202599