Linux 启动配置项

来源:互联网 发布:c 网页中数据写入xml 编辑:程序博客网 时间:2024/06/02 07:28



大多数的Linux 发行版本中,启动脚本都被放在/etc/rc.d/init.d。(rc:runlevel control directory)这些脚本被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@dev-zhanghua ~]# 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

重启计算机,完成!

reboot


注:转载(本文稍有改动)



原创粉丝点击