ubuntu 开启rc.local

1、创建rc.local.service服务的软链接

ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
touch /etc/rc.local
chmod +x /etc/rc.local

2、修改  /etc/rc.local

#!/bin/bash
 
#你的命令,不要有死循环或无法退出的程序,不然进不了系统
#mount -t 9p -o trans=virtio hostshare /mnt/share
 
exit 0

3、直接执行生效

/etc/rc.local start

4、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

 

posted on 2023-10-16 16:52  五光十色  阅读(342)  评论(0编辑  收藏  举报

导航