1. 程式人生 > >運維自動化—Linux系統自動化安裝

運維自動化—Linux系統自動化安裝

Linux系統自動化運維安裝章節

統安裝過程

配置anaconda

自動化安裝系統

製作引導光碟和U盤

DHCP服務

PXE安裝系統

cobbler企業級應用

運維自動化發展歷程及技術應用

安裝程式

CentOS系統安裝

系統啟動流程:

bootloader-->kernel(initramfs)-->rootfs-->/sbin/init

anaconda: 系統安裝程式

  • gui:圖形視窗
  • tui: 基於圖形庫curses的文字視窗

安裝程式啟動過程

MBR: isolinux/boot.cat

在linux 系統的iso中有個isolinux/boot.cat

stage2: isolinux/isolinux.bin

配置檔案: isolinux/isolinux.cfg 安裝啟動選單:安裝、救援等

每個對應的選單選項:

  • 載入核心: isolinuz/vmlinuz
  • 向核心傳遞引數: append initrd=initrd.img ...

裝載根檔案系統,並啟動anaconda

預設啟動GUI介面

  • 若是顯式指定使用TUI介面: 向核心傳遞text引數即可
  • (1)按tab鍵,在後面增加text
  • (2)按ESC鍵: boot: linux text

system-config-kichstart

第一步:掛載光碟

boot.iso 燒錄U盤

dd if=boot.iso of=/dev/sdb5

hexdump -C boot.iso in 512 檢查u盤中的引導資料是否寫進去了

安裝過程:

第一步: 

1、 [[email protected] ~]# cd /misc/cd		##進入光碟
[[email protected] cd]# cd isolinux/		      ##光碟目錄中的isolinux目錄
[[email protected] isolinux]# ls
boot.cat   initrd.img    memtest     vesamenu.c32
boot.msg   isolinux.bin  splash.jpg  vmlinuz
grub.conf  isolinux.cfg  TRANS.TBL
[
[email protected]
isolinux]# hexdump -C boot.cat 00000000 01 00 00 00 43 65 6e 74 4f 53 20 50 72 6f 6a 65 |....CentOS Proje| 00000010 63 74 00 00 00 00 00 00 00 00 00 00 4b 8f 55 aa |ct..........K.U.| 00000020 88 00 00 00 00 00 04 00 a1 02 00 00 00 00 00 00 |................| 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000040 91 ef 01 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000060 88 00 00 00 00 00 e8 02 e7 01 00 00 00 00 00 00 |................| 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000800

第二步:

2、 isolinux/isolinux.bin			##等價於grub2階段

第三步:

3、isolinux/isolinux.cfg			##相當於啟動選單	它是個文字檔案

此圖為演示圖片,作者使用的是centos6版本,道理是相同的

[[email protected] isolinux]# cat isolinux.cfg 		###centos7中的isoliux.cfg檔案內容
default vesamenu.c32
timeout 600
label linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
label check
  menu label Test this ^media & install CentOS 7
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting
label vesa
  menu indent count 5
  menu label Install CentOS 7 in ^basic graphics mode
  text help
        Try this option out if you're having trouble installing
        CentOS 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
label rescue
  menu indent count 5
  menu label ^Rescue a CentOS system
  text help
        If the system will not boot, this lets you access files
        and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
label memtest
  menu label Run a ^memory test
  text help
        If your system is having issues, a problem with your
        system's memory may be the cause. Use this utility to
        see if the memory is working correctly.
  endtext
  kernel memtest
menu separator # insert an empty line
label local
  menu label Boot from ^local drive
  localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
  menu label Return to ^main menu
  menu exit

centso6中isolinux.cfg配置檔案內容

####定義Linux啟動選單,注意檔案中每個label後面的標題,每個標題代表一種模式,分別表示選單中的一種啟動項。

[[email protected] isolinux]# cat 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 -

2、安裝時在一下圖形介面鍵入Esc鍵

進入boot:介面

輸入:boot: rescue ##表示也是進入救援模式

同樣也可以進入救援模式;

當我們瞭解了這些啟動選單檔案後,我們就知道了Linux系統的安裝啟動過程,它是由在系統光碟中的/isolinux.cfg檔案中的每個label項定義引導;從而來選擇光碟中的系統檔案用來安裝系統。

那麼我們利用這個檔案也可以自己編輯定義Linux的啟動選單和選單下引導系統安裝的檔案路徑

使用 yum 定義選單引導安裝Linux系統路徑

準備環境:2臺虛擬主機 A B

主機A:安裝好的Linux主機作為yum源;後續安裝系統的選單路徑利用網路搭建好的yum源來引導安裝。

主機B:未安裝系統

第一步:在yum源主機下建立yum路徑

[[email protected] ~]# yum install httpd ###安裝http服務包

[[email protected] ~]# service httpd start ###啟動http服務

[[email protected] ~]# cd /var/www/html/ ###進入HTTP預設網站檔案路徑

[[email protected] html]# mkdir centos/6 -pv ###建立yum源路徑

[[email protected] html]# mount /dev/sr0 centos/6 ###掛在光碟

第二步:測試yum源是否正常

測試成功。

第三步:在主機B上設定通訊

這個介面在以上有說明。

選擇eth0網絡卡

省略一下安裝過程.......

atl+F2調出字元安裝介面。檢視安裝過程

最小化安裝成功。

輸入使用者名稱口令登陸

另一中方法:

接以上第三步開始

如果想手動指定安裝源:

  • boot: linux askmethod

第一步:重啟主機B esc進入光碟引導

輸入:linux askmethod

選擇URL安裝,連線主機A的yum源

點選ok

可以手動指定也可以自動獲取,我們這裡選擇自動獲取,因為網中有dhcp伺服器

繼續重複同以上安裝步驟