Linux如何设置开机⾃启动脚本
Linxu开机⾃启动脚本
⼀、CentOS系统和Redhat系统如下:
1.修改/etc/rc.d/rc.local为
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
source /root/Desktop/start.sh
“sourece /root/Desktop/start.sh”为要添加开机⾃启动的脚本,并且要给“/root/Desktop/start.sh”赋予执⾏权限(chmod +x /root/Desktop/start.sh)
2.chmod 777 rc.local
3.重启系统后就会开始执⾏预设置执⾏的脚本。(此种⾃启动⽅式不会在GUI界⾯显⽰执⾏的具体进程)**
⼆、Suse 系统如下:
1.suse15
1)将需要开机启动脚本xxx.sh复制到 /etc/profile.d
chmod 777 xxx.sh
2)将系统改成root ⾃动登录
vi /etc/sysconfig/displaymanager
displaymanager-autologin=“root”
备注:
2.Suse12
1.修改/etc/init.d/下⾯有个boot.local为:
#! /bin/sh
#
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.
#
# Author: Werner Fink, 1996
# Burchard Steinbild, 1996
#
# /etc/init.d/boot.local
#
# script with local commands to be executed from init on system startup
#
# Here you should add things, that should happen directly after booting
# before we're going to the first run level.
#
source /root/Desktop/start.sh
“sourece /root/Desktop/start.sh”为要添加开机⾃启动的脚本,并且要给“/root/Desktop/start.sh”赋予执⾏权限(chmod +x /root/Desktop/start.sh)
2.重启系统后就会开始执⾏预设置执⾏的脚本。(此种⾃启动⽅式不会在GUI界⾯显⽰执⾏的具体进程)
三、Ubuntu 系统如下:
1、建⽴rc-local.service⽂件
sudo vi /etc/systemd/system/rc-local.service
2、将下列内容复制进rc-local.service⽂件
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
linux循环执行命令脚本ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3、创建⽂件rc.local
sudo vi /etc/rc.local
4、将下列内容复制进rc.local⽂件
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo ./root/Desktop/start.sh
5、给rc.local加上权限sudo chmod +x /etc/rc.local
6、启⽤服务sudo systemctl enable rc-local
7、启动服务并检查状态
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
在Redhat Redflag centOS fc linux系统⾥⾯脚本的启动先后顺序:
第⼀步:通过/boot/vm进⾏启动 vmlinuz
第⼆步:init /etc/inittab
第三步:启动相应的脚本,并且打开终端
rc.sysinit
rc.d(⾥⾯的脚本)
rc.local
第四步:启动login登录界⾯ login
第五步:在⽤户登录的时候执⾏sh脚本的顺序:每次登录的时候都会完全执⾏的
/etc/profile.d/file
/etc/profile
/etc/bashrc
/root/.bashrc
/
root/.bash_profile
Redhat中的运⾏模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后⼀个,所以⽤户可以⾃⼰在这个⽂件中添加⼀些需要在其他初始化⼯作之后,登录之前执⾏的命令
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论