您尚未登录。

楼主 # 2023-12-17 21:11:18

memory
会员
注册时间: 2021-08-11
已发帖子: 582
积分: 554

ubuntu18.04 ~ ubuntu22.04 开机不能执行 rc.local 脚本的问题解决方案

ubuntu14.04 编辑/etc/rc.local 可以执行开机脚本,

但是后面的版本不行了,

得用下面的办法修复:


https://zhuanlan.zhihu.com/p/364133732



修改:/etc/systemd/system/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=5
RemainAfterExit=yes
GuessMainPID=no

[Install]

WantedBy=multi-user.target

Alias=rc-local.service

/etc/rc.local

#!/bin/bash

echo 00000000000000 > /tmp/x.log

vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other,entry_timeout=3,negative_timeout=3,attr_timeout=3,auto_cache

echo 9999999999999 >> /tmp/x.log

sudo chmod +x /etc/rc.local






接下来是启动服务:
①.刷新systemctl配置
sudo systemctl daemon-reload

②.设置开机启动
sudo systemctl enable rc-local.service

③.启动服务
sudo systemctl start rc-local.service

④.测试服务的状态
sudo systemctl status rc-local.service

以后就能开机运行 /etc/rc.local的脚本了!

离线

#1 2023-12-18 10:19:16

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 696
积分: 830
个人网站

Re: ubuntu18.04 ~ ubuntu22.04 开机不能执行 rc.local 脚本的问题解决方案

/etc/rc.d的启动方式是SysVinit,只能串行执行系统启动脚本,启动速度慢,已经被遗弃了。
现在的启动方式都是Systemd了,不知为何现在很多人诟病Systemd,我记得Systemd引进之初是为了解决SysVinit只能串行启动导致启动速度慢,而仿效MacOS进行并行启动来提高启动速度的。
建议放弃SysVinit了,以后Systemd也可能不再兼容SysVinit

离线

#2 2023-12-21 13:07:28

Fomalhaut
会员
注册时间: 2021-10-28
已发帖子: 37
积分: 32

Re: ubuntu18.04 ~ ubuntu22.04 开机不能执行 rc.local 脚本的问题解决方案

很多人指责systemd是因为它做的事情太多了,违反了UNIX哲学。

离线

#3 2023-12-21 15:44:16

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 696
积分: 830
个人网站

Re: ubuntu18.04 ~ ubuntu22.04 开机不能执行 rc.local 脚本的问题解决方案

Fomalhaut 说:

很多人指责systemd是因为它做的事情太多了,违反了UNIX哲学。

原来如此。我从SysVinit年代就开始坚持使用Linux为主,Systemd带来的启动优化是很明显的,不过现在Systemd可能确实已经脱离它的初衷,俨然一个系统服务管理工具了。但我目前接触Systemd下来感觉还好,挺便利的。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn