Linux中设置开机启动脚本(fedora)

rc是runlevel control directory的缩写。


大多数的Linux 发行版本中,启动脚本都被放在/etc/rc.d/init.d。这些脚本被ln 命令来连接到 /etc/rc.d/rcn.d 目录。(这里的n 就是运行级0-6)

init.d/ :各种服务器和程序的二进制文件存放目录。
rcx.d/: 各个启动级别的执行程序连接目录。里头的东西都是指向init.d/的一些软连接。


还有三个脚本:rc.sysinit, rc, rc.local 


redhat的启动方式和执行次序是:
加载内核  执行init程序  /etc/rc.d/rc.sysinit # 由init执行的第一个脚本  
/etc/rc.d/rc $RUNLEVEL # $RUNLEVEL为缺省的运行模式  
/etc/rc.d/rc.local  /sbin/mingetty # 等待用户登录  
/etc/rc.d/rc.sysinit主要做在各个运行模式中相同的初始化工作,包括:  调入keymap以及系统字体  启动swapping  设置主机名  设置NIS域名  检查(fsck)并mount文件系统  打开quota  装载声卡模块  设置系统时钟  等等。
/etc/rc.d/rc则根据其参数指定的运行模式(运行级别,你在inittab文件中可以设置)来执行相应目录下的脚本。
凡是以Kxx开头的  ,都以stop为参数来调用;凡是以Sxx开头的,都以start为参数来调用。调用的顺序按xx  从小到大来执行。
例如,假设缺省的运行模式是3,/etc/rc.d/rc就会按上述方式调用  /etc/rc.d/rc3.d/下的脚本。
  
值得一提的是,Redhat中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中  的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。  init在等待/etc/rc.d/rc执行完毕之后(因为在/etc/inittab中/etc/rc.d/rc的  action是wait),将在指定的各个虚拟终端上运行/sbin/mingetty,等待用户的登录。


Fedora 设置开机启动脚本

sudo touch /etc/rc.d/rc.local
sudo vim /etc/rc.d/rc.local

在/etc/rc.d/rc.local文件中写入, 然后使用:wq命令 保存并退出.

#!/bin/bash
# 在这个文件中写入开机启动需要执行的命令

赋予可执行权限:
sudo chmod+x /etc/rc.d/rc.local

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


如果出现以下错误提示:
[root@abc ~]# systemctl enable rc-local.service
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).


sudo vim /usr/lib/systemd/system/rc-local.service

在rc-local.service文件末尾加入:
[Install]
WantedBy=multi-user.target

并重新设置开机启动:
sudo systemctl enable rc-local.service

查看状态, 如果出现以下提示, 设置成功!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值