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”
備註:
a.安裝suse15系統參考:http://morecoder.com/article/1120393.html
b.查看OS IP指令爲“ip -4 address”
c.遠程連接請用putty,ssh 工具無法使用。
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
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.
soure /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做爲初始化腳本中的最後一個,所以用戶可以自己在這個文件中添加一些需要在其他初始化工作之後,登錄之前執行的命令