第七周博客作業

1、簡述linux操作系統啟動流程
2、簡述grub啟動引導程序配置及命令行接口詳解
3、實現kickstart文件制作與光盤鏡像制作

1、簡述linux操作系統啟動流程

* ?Linux系統的組成部分:內核+根文件系統

內核:進程管理、內存管理、網絡協議棧、文件系統、驅動程序、安全功能

* ? 運行中的系統環境可分為兩層:內核空間、用戶空間

用戶空間:應用程序(進程或線程)

內核空間:內核代碼(系統調用)

* ?內核設計流派:

單內核設計:把所有功能集成于同一個程序;例如Linux系統

微內核設計:每種功能使用一個單獨的子系統實現;例如:Windows系統

* ?Linux內核特點:

支持模塊化:? .ko (kernel object)

支持模塊運行時動態裝載或卸載;

 

(1)內核版本查詢

11

(2)內核文件 可以多內核

12

(3)內核模塊里的文件

13

(4)ramdisk虛擬根

ramdisk: 虛擬根 啟動時候在內存中虛擬一個根 用于加載當前硬件驅動(適用不同硬件的主機), 如果是編譯安裝系統 僅針對本機硬件, 不需要這個虛擬根。

(5)系統的啟動流程

16

(6)系統的初始化

15

(7)內核空間的啟動流程:1

 

(8)CentOS的運行級別init

17

(9)配置inittab文件

文件所在位置/etc/inittab,inittab在啟動中起著非常重要的作用2

每行定義一種action(動作)以及與之對應的process(任務)

id:runlevels:action:process

id:一個任務的標識符;

runlevels:在哪些級別啟動此任務;#,###,也可以為空,表示所有級別;

action:在什么條件下啟動此任務;

process:任務;

 

action:

wait:等待切換至此任務所在的級別時執行一次;

respawn:一旦此任務終止,就自動重新啟動之;

initdefault:設定默認運行級別;此時,process省略;

sysinit:設定系統初始化方式,此處一般為指定/etc/rc.d/rc.sysinit腳本;

 

例如:

id:3:initdefault:

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc? 0

l1:1:wait:/etc/rc.d/rc? 1

…………

l6:6:wait:/etc/rc.d/rc? 6

意味著去啟動或關閉/etc/rc.d/rc3.d/目錄下的服務腳本所控制服務;

K*:要停止的服務;K##*,優先級,數字越小,越是優先關閉;依賴的服務先關閉,而后關閉被依賴的;

S*:要啟動的服務;S##*,優先級,數字越小,越是優先啟動;被依賴的服務先啟動,而依賴的服務后啟動;

(10)用戶空間的啟動流程:設置默認運行級別 –>運行系統初始化腳本,完成系統初始化 –>關閉對應級別下需要停止的服務,啟動對應級別下需要開啟的服務–>設置登錄終端 [–>啟動圖形終端]

2、簡述grub啟動引導程序配置及命令行接口詳解

(1)什么是grub

? ? ? GNU GRUB(GRand Unified Bootloader簡稱“GRUB”)是一個來自GNU項目的多操作系統啟動程序。GRUB是多啟動規范的實現,它允許用戶可以在計算機內同時擁有多個操作系統,并在計算機啟動時選擇希望運行的操作系統。GRUB可用于選擇操作系統分區上的不同內核,也可用于向這些內核傳遞啟動參數。

(2)grub版本

grub 0.x: grub legacy經典版本:Centos6和Centos5使用該版本

grub 1.x: grub2:Centos7使用該版本

(3)grub啟動的三個階段

第1階段:stage1: 用于啟動mbr中Boot loader

第1.5階段: stage1_5: mbr之后的扇區,讓stage1中的bootloader能識別stage2所在的分區上的文件系統;

第2階段 ?stage2:讀取grub.conf 配置文件,并實現引導功能的擴展,第二階段的內核通常放置在一個基本磁盤分區上。

(4)與grub相關的配置文件

與grub相關的配置文件包括:/etc/grub.conf和/boot/grub/grub.conf,其實/etc/grub.conf是指向/boot/grub/grub.conf的軟鏈接,grub程序在引導啟動時會讀取這個配置文件并按照該文件的配置參數引導啟動系統。
通常其內容為:

3

default=0:表示有多個grub引導菜單時,選擇哪一個作為默認啟動引導菜單,default=0表示默認使用第一個title菜單中的配置;
timeout=5:在grub選擇菜單中,5秒內,如果用戶沒有選擇任何一個title,則使用default中指定的titile菜單中的配置進行啟動。
splashimage:指定引導菜單中的背景圖片的路徑;
titile:指定title菜單到的名稱;
root:表示kernel和initrd文件所在的分區路徑,而不是“根分區”;其設置格式為:root (hd#,#),硬盤均會被識別為hd,第一個#表示第幾個硬盤,從0開始;地第二個#表示同一個硬盤上的不同分區,也使用數字標識,從0開始;
kernel:通常用于指定要運行的內核文件路徑,如:/vmlinuz-2.6.32-642.el6.x86_64;另外也可在其后設置相關的內核參數,如:ro表示只讀,root表示指定根分區所在路徑,關閉selinux等等;
initrd:為內核運行指定其可用的ramdisk文件,其版本須與內核版本相一致;

(5)grub程序的功能

1)、 提供菜單、并提供交互式接;?e: 編輯模式,用于編輯菜單;c: 命令模式,交互式接口;

2) 、加載用戶選擇的內核或操作系統,?允許傳遞參數給內核,也?可隱藏此菜單。

3)、 為菜單提供了保護機制,為編輯菜單進行認證,為啟用內核或操作系統進行認證。

在系統開機啟動過程中,有幾秒的過渡頁面,此時按任意鍵可進入到菜單頁面中:5

按e鍵進入編輯模式6

按c鍵進入命令模式,按esc鍵返回7

(6)grub的命令行接口

在菜單頁面按c即可進入命令行接口,在此命令行接口, 我們可以配置相關的grub設置,如指定root 路徑、kernel文件的路徑等等。grub命令行接口的常用指令有:

help:查看命令幫助;
root (DEVICE):指定系統和內核文件所在的分區,如root(hd0,0)。
find  (hd0,0) /path/to/file:用于查找對應分區下的文件。常用于當不確認內核文件在哪個分區時,可使用此命令確認文件所在路徑;支持tab補全;
kernel /path/to/kernel_file:用于指定要運行的內核文件。
initrd /path/to/kernel_file:指定initrd文件;
boot:以當前配置好的grub配置啟動系統;


10

 

(7)進入單用戶模式:

1) 、編輯grub菜單(選定要編輯的title,而后使用e命令);

2) 、在選定的kernel后附加

1, s, S或single都可以;

3)、 在kernel所在行,鍵入“b”命令;

 

(8)安裝grub方法:

1)、 grub-install命令

格式: ? ?grub-install –root-directory=ROOT /dev/DISK

DEVICE:安裝的目標磁盤;
–root-directory=DIR:指grub映像文件的存放位置,默認為當前系統根目錄。grub-install會在指定的目錄下創建boot/grub/的層級目錄,并生成相關的grub文件生成在DIR/boot/grub/下。

2)、在grub中安裝grub

[root@bogon ~]# grub        #輸入grub命令
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

grub> root (hd0,0)            #指定boot分區位置
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)             #安裝grub
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  27 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit                    #退出grub

 

 

3、實現kickstart文件制作與光盤鏡像制作

anaconda的配置方式:

(1) 交互式配置方式;

(2) 支持通過讀取配置文件中事先定義好的配置項自動完成配置;遵循特定的語法格式,此文件即為kickstart文件;

安裝kickstart工具

[root@localhost ~]# yum -y install system-config-kickstart    #安裝kickstart工具
已加載插件:fastestmirror, refresh-packagekit, security
設置安裝進程
Repository base is listed more than once in the configuration
Determining fastest mirrors
 * base: mirrors.sohu.com
 * extras: mirrors.163.com
* updates: mirrors.163.com
base                                                                                                                                                           | 3.7 kB     00:00     
extras                                                                                                                                                         | 3.4 kB     00:00     
updates                                                                                                                                                        | 3.4 kB     00:00     
updates/primary_db                                                                                                                                             | 7.0 MB     00:02     
解決依賴關系

Kickstart配置文件內容

kickstart文件的格式

命令段:

指定各種安裝前配置選項,如鍵盤類型等;

必備命令

可選命令

程序包段:

指明要安裝程序包,以及包組,也包括不安裝的程序包;

%packages

@group_name

package

-package

%end

腳本段:

%pre:安裝前腳本

運行環境:運行安裝介質上的微型Linux系統環境;

 

%post:安裝后腳本

運行環境:安裝完成的系統;

 

# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang zh_CN.UTF-8                                                    #系統語言支持
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6        #開機onboot設置成yes
rootpw 12345                                                        #密碼修改
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Shanghai                                          #設定時區
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"     #BootLoader設定
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --drives=sda                                  
volgroup VolGroup --pesize=4096 pv.008002
logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=VolGroup --grow --size=1984 --maxsize=1984

part /boot --fstype=ext4 --size=500
part pv.008002 --grow --size=1
repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100
%packages
@additional-devel
@base
@chinese-support
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@directory-client
@eclipse
@emacs
@fonts
@general-desktop
@graphical-admin-tools

啟用窗口配置ks

[root@localhost ~]# system-config-kickstart &

4

創建一個目錄

[root@localhost ~]# mkdir /myboot

轉到這個目錄并查看光盤

[root@localhost ~]# cd /myboot
[root@localhost myboot]# ls  /media/CentOS_6.9_Final/
CentOS_BuildTag  EULA  images    Packages                  repodata              RPM-GPG-KEY-CentOS-Debug-6     RPM-GPG-KEY-CentOS-Testing-6
EFI              GPL   isolinux  RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Security-6  TRANS.TBL

拷貝光盤里面isolinux整個目錄

[root@localhost myboot]# cp -a /media/CentOS_6.9_Final/* ./

轉到isolinux本地目錄下并賦予寫入權限

[root@localhost myboot]# cd isolinux/
[root@localhost isolinux]# chmod +w *
[root@localhost isolinux]# ll
總用量 28
-rw-r--r--. 1 root root  2048 5月   3 23:48 boot.cat

修改相關項目.

[root@localhost isolinux]# vim isolinux.cfg

default vesamenu.c32
#prompt 1
timeout 600

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.9!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000

label linux
  menu label ^Install or upgrade an existing system ^-^
  menu default
  kernel vmlinuz
  append initrd=initrd.img
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img nomodeset
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel memtest
  append -

拷貝anaconda文件到myboot目錄

[root@localhost myboot]# cp /root/anaconda-ks.cfg  ks.cfg
[root@bogon myboot]# ls -a
. EULA Packages RPM-GPG-KEY-CentOS-Security-6
.. GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Testing-6
CentOS_BuildTag images repodata TRANS.TBL
.discinfo isolinux RPM-GPG-KEY-CentOS-6
EFI ks.cfg RPM-GPG-KEY-CentOS-Debug-6


注意查看myboot目錄里面查看是否有.discinfo這個隱藏文件,如果沒有使用鏡像會報錯無法找到光盤,從新到光盤里面拷貝出來即可。

 

創建光盤鏡像

[root@localhost ~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6 boot" -c isolinux/boot.cat -b isolinux/isolinux.bin -o /root/boot.iso  /myboot/

I: -input-charset not specified, using utf-8 (detected in locale settings)
genisoimage 1.1.9 (Linux)
Scanning /myboot/
Scanning /myboot/isolinux
Excluded by match: /myboot/isolinux/boot.cat
Excluded: /myboot/isolinux/TRANS.TBL
Writing:   Initial Padblock                        Start Block 0
Done with: Initial Padblock                        Block(s)    16
Writing:   Primary Volume Descriptor               Start Block 16
Done with: Primary Volume Descriptor               Block(s)    1
Writing:   Eltorito Volume Descriptor              Start Block 17
Size of boot image is 4 sectors -> No emulation
Done with: Eltorito Volume Descriptor              Block(s)    1
Writing:   Joliet Volume Descriptor                Start Block 18
Done with: Joliet Volume Descriptor                Block(s)    1
Writing:   End Volume Descriptor                   Start Block 19
Done with: End Volume Descriptor                   Block(s)    1
Writing:   Version block                           Start Block 20
Done with: Version block                           Block(s)    1
Writing:   Path table                              Start Block 21
Done with: Path table                              Block(s)    4
Writing:   Joliet path table                       Start Block 25
Done with: Joliet path table                       Block(s)    4
Writing:   Directory tree                          Start Block 29
Done with: Directory tree                          Block(s)    2
Writing:   Joliet directory tree                   Start Block 31
Done with: Joliet directory tree                   Block(s)    2
Writing:   Directory tree cleanup                  Start Block 33
Done with: Directory tree cleanup                  Block(s)    0
Writing:   Extension record                        Start Block 33
Done with: Extension record                        Block(s)    1
Writing:   The File(s)                             Start Block 34
 21.94% done, estimate finish Fri May  4 00:43:47 2018
 43.79% done, estimate finish Fri May  4 00:43:47 2018
 65.72% done, estimate finish Fri May  4 00:43:47 2018
 87.57% done, estimate finish Fri May  4 00:43:47 2018
Total translation table size: 4701
Total rockridge attributes bytes: 1438
Total directory bytes: 2048
Path table size(bytes): 26
Done with: The File(s)                             Block(s)    22660
Writing:   Ending Padblock                         Start Block 22694
Done with: Ending Padblock                         Block(s)    150
Max brk space used 0
22844 extents written 

查詢新建的iso文件

[root@localhost ~]# ls
anaconda-ks.cfg  boot.iso  install.log  install.log.syslog  公共的  模板  視頻  圖片  文檔  下載  音樂  桌面

拷貝出來boot.iso并加載使用

1

啟動虛擬機并加載2

設置語言并完成安裝

3

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/97473

(0)
任總任總
上一篇 2018-05-04 13:15
下一篇 2018-05-04

相關推薦

  • 09葵花寶典Openssl和DNS

    openssl cd bind named

    Linux筆記 2018-05-16
  • 作業管理(任務計劃)

    任務計劃就好比我們的鬧鐘一樣,到了指定的時間就該去做對應的事情。 任務計劃分為兩類: 一次性的任務計劃:只執行一次就結束 周期性的任務計劃:每隔一定的周期去做相同的事情 at命令就是專門用來處理一次性的計劃任務 batch也是處理一次性的計劃任務但是它是由系統自行選擇空閑時間去執行此處指定的任務(不常用) crontab可以根據定義的周期信息,循環的去做一些…

    Linux筆記 2018-05-05
  • DNS服務

    1、相關原理概念
    2、配置主DNS服務器
    3、配置從DNS服務器

    2018-06-03
  • sed

    用法: sed? [選項]… ‘script’ inputfile 其中script是腳本基于sed語法的腳本 ? ? ? ? ? ? ? ? inputfile文件內容 常用選項 -n ? :不輸出模式空間內容到屏幕,即不自動打印 -e ? :多點編輯 -f ?? : ? /PATH/SCRIPT_FILE:從指定文件中…

    Linux筆記 2018-04-14
  • 第四周作業:etc/skel實戰聯系

    第四周作業

    2018-04-13
欧美性久久久久