§·Centos系統光盤安裝的流程
大概的了解下Centos的光盤系統安裝流程:
1.插入光盤,出現菜單選擇界面;通常情況下我們選擇第一項:
第一項 : Install or upgrade an existing system
2.默認進入圖形界面安裝并且進行一些必要的環境設置(安裝前的配置階段)
需要我們手工設置的項目
比如:
安裝過程使用的語言
鍵盤類型
安裝目標存儲設備
Basic Storage:本地磁盤
特殊設備:iSCSI
設定主機名
配置網絡接口
時區
管理員密碼
設定分區方式及MBR的安裝位置
創建一個普通用戶
選定要安裝的程序包
3.點擊開始安裝后,系統就自動安裝系統(安裝階段)
在目標磁盤上創建分區并執行格式化
將選定的程序包安裝至目標目錄
安裝 bootloader;(可以在安裝前設置安裝腳本,還可以在安裝后設置安裝腳本)
4.首次啟動,系統需要的工作。
iptables 防火墻是否啟用
selinux 是否啟用
coer dump 核心轉存功能(在內核崩潰的那一刻,把內存中所有的數據生成一個鏡像文件)
§·Centos光盤流程問題分析
※·光盤是如何啟動的?光盤啟動的大概流程是如何的?
回顧Centos啟動流程,POST加電自檢,啟動設備為光盤啟動,讀取光盤的bootloader程序,加載相應的驅動識別光盤,光盤上使用相應的 grub.conf文件生成菜單界面,通過grub程序找到光盤的kernel 與 initrd文件,啟動相應的系統。
[root@centos68 isolinux]# pwd /mnt/cdrom/isolinux [root@centos68 isolinux]# ll total 44418 -r--r--r--. 1 root root 2048 May 23 07:51 boot.cat #提供MBR功能 -r--r--r--. 2 root root 84 May 22 14:06 boot.msg #某個程序 -r--r--r--. 2 root root 321 May 22 14:06 grub.conf #配置文件 -r--r--r--. 4 root root 40688737 May 22 14:06 initrd.img #initrd文件系統 -r--r--r--. 2 root root 24576 May 23 05:21 isolinux.bin #提供stage2功能 -r--r--r--. 2 root root 923 May 22 14:06 isolinux.cfg #提供菜單功能 -r--r--r--. 2 root root 183012 May 22 14:06 memtest #內存測試程序 -r--r--r--. 2 root root 151230 May 22 14:06 splash.jpg #背景圖片 -r--r--r--. 1 root root 2215 May 23 07:51 TRANS.TBL -r--r--r--. 2 root root 163728 May 22 14:06 vesamenu.c32 -r-xr-xr-x. 4 root root 4264528 May 22 14:06 vmlinuz #內核文件
光盤上引導加載器(MBR bootloader): /mnt/cdrom/isolinux/iboot.cat
光盤上 stage2 : /mnt/cdrom/isolinux/isolinux.bin
光盤上 kernel文件為: /mnt/cdrom/isolinux/ivmlinuz
光盤上 initrd文件為: /mnt/cdrom/isolinux/iinitrd.img
※·菜單界面是如何實現與配置的?
既然光盤上提供了相應的引導程序,內核文件,initrd文件,光盤就相當于一個系統。
對應的菜單兩個文件: grub.cfg isolinux.cfg
◎·cat grub.conf文件內容查看
#文件內容一句沒有看懂
[root@centos68 isolinux]# cat grub.conf #debug --graphics default=0 splashimage=@SPLASHPATH@ timeout 5 hiddenmenu title @PRODUCT@ @VERSION@ kernel @KERNELPATH@ initrd @INITRDPATH@ title Install system with basic video driver kernel @KERNELPATH@ nomodeset askmethod initrd @INITRDPATH@ title rescue kernel @KERNELPATH@ rescue askmethod initrd @INITRDPATH@
◎·cat isolinux.cfg文件內容查看
#可以大概看出一點東西
[root@centos68 isolinux]# cat isolinux.cfg default vesamenu.c32 #prompt 1 timeout 600 display boot.msg menu background splash.jpg #菜單的背景圖片 menu title Welcome to CentOS 6.8! #菜單欄上最上面的標語 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 #內核的文件的(cdrom:/isolinux/ivmlinuz) append initrd=initrd.img #內核的文件的(cdrom:/isolinux/initrd.img ) #append 關鍵字后面跟的是kenerl的參數選項 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 - [root@centos68 isolinux]#
※·系統安裝配置階段是如何提供的?
選擇對應的操作菜單后,啟動第一個程序,程序名稱為 anaconda程序,anaconda程序提供系統安裝的全套安裝界面的和選項,也是我們重點需要了解一下。
anaconda程序默認情況使用圖形界面,并且以交互式的方式安裝系統。
anaconda程序可實現通過配置文件自動化的安裝系統,不需要人為的參與,以下了解下 anaconda程序。
§·小結光盤安裝系統流程
※·Centos的安裝過程啟動流程:光盤為例:
1 . MBR : boot.cat(光盤上的引導加載器) /isolinux/boot.cat
2. stage2 : /isolinux/isolinux.bin
3. 配置文件: /isolinux/isolinux.cfg 提供菜單列表
每個對應的菜單選項:
kernel vmlinuz
append initrd=initrd.img
加載內核: isolinux/vmlinuz
向內核傳遞參數:append initrd=initrd.img
4. 裝載根文件系統,并啟動 anaconda
默認界面的圖形界面: 512M+內存空間
若需要顯示指定TUI接口:向啟動內核傳遞一個參數: text 即可;
通過label來指定需要哪個, 來調用傳遞內核參數:
ESC,
boot : linux text
※·注意:
·上述內容一般位于引導設備,例如可通過光盤,U盤或網絡等,后續的anacona及其安裝用的程序可以來至于程序包倉庫,此倉庫的位置可以為:
本地磁盤 本地硬盤 ftp server http server nfs server
如果想手動的指定安裝倉庫:
ESC
boot: linux method
·在此配置界面我們還可以指更多的配置:
#anacona配置文件的的文件路徑 ks=cdrom:/ks.cfg
#啟動網卡功能配置固定的IP地址 ip=172.16.200.91 netmask=255.255.0.0
boot: text 文本安裝方式
method : 手動指定使用的安裝方法
與網絡相關的引導選項: ip=IPADDR netmask=MASK gateway=GW dns=DNS_SERVER_IP
與遠程訪問功能相關的引導選項:vnc vncpassword=“PASSWORD”
啟動緊急救援模式: rescue
額外裝載驅動:dd
安裝引導選項:ks : 指明klckstart文件的位置:
ks=
DVD drive : ks=cdron:/PATH/TO/klckstart_FILE
Hard drive : ks=hd:/device/path/klckstart_FILE
http service : ks=http://host:port/path/to/klckstart_FILE
ftp service : ks=ftp://host:port/path/to/klckstart_FILE
查看幫助文件 紅帽官方幫助文檔(installtion guide)
系統安裝完成后:會在家目錄下生產 anaconda-ks.cfg 配置文件
§·anacona程序的介紹和相關命令
※·anaconda :安裝的界面有兩種
tui : 文本窗口,基于cureses的文本編輯窗口;(方法為: ESC boot: linux text )
gui : 圖形界面 (默認安裝界面)
※·anaconda 工作過程
·安裝前配置階段:
安裝過程中使用的語言;
鍵盤類型;
安裝目標的存儲設備:
basic storage : 本地磁盤
sperclal storage : ISCSI
設定主機名
設置網絡接口
時區
管理員密碼
設定分區及其Mbr的安裝位置
創建一個普通用戶
選定要安裝的程序包
·安裝階段:
在目標磁盤上創建分區并執行格式化
將選定的程序包安裝至目標目錄
安裝 bootloader;
(可以在安裝前設置安裝腳本,還可以在安裝后設置安裝腳本)
※·anaconda配置方式
(1)交互式配置方式;
圖形界面下一步,下一步即可。
(系統安裝完成在 /boot目錄下自動生成一個文件名為 )
[root@centos68 ~]# ll -h /root/anaconda-ks.cfg -rw-------. 1 root root 1.5K Jul 19 18:21 /root/anaconda-ks.cfg [root@centos68 ~]#
(2)可支持通過配置文件中事先定義好的配置項目自動完成配置;
遵循特性的語法特性,此文件即為klckstatr文件;
※·anaconda-ks.cfg 配置文件的結構
◎·命令段:
指定各種安裝前配置選項,如鍵盤類型等;
必備命令:
可選命令
*·必備命令:
1. 認證方式配置 :authconfig –enableshadow –passalgo=sha512
2. 定義bootloader的安裝位置及其相關配置:
bootloader –location=mbr –driveorder=sda –append="crashkernel=auto rhgb quiet"
3. 設定鍵盤類型: keyboard us
4. 語言類型:lang en_US.UTF-8
5 分區布局(默認單位為M):part /boot –fstype=ext4 –size=200
part pv.008002 –size=51200 (啟用邏輯卷)
6. 管理員密碼:
rootpw –iscrypted $6$E8EbPn1qzCb.2X3c$w8zyZZf.cDBsJkcRTr22Z2wCqtlA4Ae.OE7RfKvGZJSmN4/
生成加密密碼的命令: openssl passed -1 -salt `openssl rand -hex 4 `
7. 指定時區 :timezone Asia/Shanghai
8. 分區相關的命令:
clearpart –none –drives=sda :(清空磁盤分區)
vlgroup mvvg –pesize=4096 pv.008002 (創建卷組)
logvol /home –fstype=ext4 –name=lv_home –vgname=myvg –size=5120 (創建邏輯卷)
*·可選命令:
repo :指明安裝時使用的reposltory
repo –name="CentOS" –baseurl=cdrom:sr0 –cost=100
url :指明安裝時使用的reposltory ,但為url格式:
url –url=http://172.16.0.1/cobbler/ks_mirror/Centos-6.7-x86_64/
halt,poweroff或reboot :安裝完成之后的行為:
install OR upagade (安裝或升級,默認為 install)
text :文本接口 (默認為圖形接口)
network :網絡配置接口
network –onboot no –device eth0 –bootproto dhcp –noipv6
firewall :防火墻功能
firewall –disabled (關閉防火墻)
firewall –service=ssh (啟用防火墻,放行ssh)
selinux :
selinux –disabled (禁用防火墻)
#系統安裝后關閉iptables #Centos 6 : # service iptables stop # chkconfig iptables off #Centos 7 # systemctl stop firewalld.service # systemctl disable firewalld.service #系統安裝后關閉 selinux # 編輯配置文件 /etc/sysconfig/selinux或/etc/selinux/config,修改SELINUX參數的值為下面其中之一: # perrissicve # disabled # 立即生效: # getenforce # setenforce 0
◎·程序包段:
指明要安裝程序包,以及包組,也包括不安裝的程序包;
%packages (定義程序包安裝開始標志)
@group_name (安裝的包組)
package (需要安裝的包)
-package(不需要安裝的包)
%end (定義程序包安裝開始標志)
◎·腳本段:
%pre :安裝前腳本
運行環境,運行安裝介質上的微型linux系統環境
%post:安裝后腳本
運行環境:安裝完成的系統
※·定制 anaconda-ks.cfg 文件方法
·安裝system-config-kickstart 軟件,通過該軟件生成文件。
#yum install system-config-kickstart
# system-config-kickstart
(在圖形界面下使用該命令,可以打開一個圖形的字符界面配置anaconda-ks.cfg文件)
·檢測語法錯誤:
#ksvalidator anaconda-ks.cfg
使用Xshell 5的ssh可以使用圖形界面的方法:記得在隧道那一行勾上轉發 X11連接到即可
◎·啟動system-config-kickstart軟件并使用模板生成配置文件
在Xshell中直接運行 system-config-kickstart ,自動啟動圖形界面
[root@centos68 ~]# system-config-kickstart Xlib: extension "RANDR" missing on display "localhost:10.0". /usr/share/system-config-kickstart/kickstartGui.py:103: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart") Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile Failed to add groups file for repository: cdrom-tools - None Warning: Group client-mgmt-tools does not have any packages.
#system-config-kickstart啟動后
只需要在對應的項目中填寫事先設置好的內容,此文件為隨意找的一個配置文件,使用system-config-kickstart打開后,修改下,保存文件,文件內容為:
[root@centos68 ~]# cat isolinux/ks.cfg platform=x86, AMD64, or Intel EM64T #關于CPU類型設置 #version=DEVEL # Firewall configuration #關于防火墻設置 firewall --disabled # Install OS instead of upgrade #關于系統是安裝 還是升級 install # Use network installation url --url="http://10.1.0.1/cobbler/ks_mirror/CentOS-6-x86_64" repo --name="CentOS" --baseurl=http://10.1.0.1/cobbler/ks_mirror/CentOS-6-x86_64 --cost=100 # Root password rootpw --iscrypted $1$kmQOkOWg$MMg7IybCJOEu0UrOv0pJd. #設置root的用戶名和密碼 # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone Asia/Shanghai # Network information network --bootproto=static --device=eth0 --ip=10.1.16.250 --netmask=255.255.0.0 --onboot=on # System bootloader configuration bootloader --append="crashkernel=auto crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda" # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all # Disk partitioning information part /boot --fstype="ext4" --size=500 part / --fstype="ext4" --size=10000 part /home --fstype="ext4" --size=1000 %post echo -e 'Mage Education Learning Services\nhttp://www.magedu.com\n' >> /etc/issue #sed -i '1,$s@id:[0-9]:initdefault:@id:3:initdefault:@g' /etc/inittab [ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=--- /root/.ssh cat >> /root/.ssh/authorized_keys << EOF ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlmq1z0G/7wbGuSUewfXlFnwzqCg/myqTi/AwP8LP+JJ49xzIKMzpeWXHD8RWIf5RlDzo+6N7uPK5O22x/QtMosi0egz4shavEJeUkO0EH+KygXXgBIGuMWmAsL+yzbgWXT9H3zdzXi/qWcrBeBv2nYB5mpYSf7o0xqdhCst1MTfcYLD8qxvkwC8RiqBA/1u9N6jeDFbHO+UzZYYCr9zgk9uz4Rrhb9BU7c1GhjUCgRwBDAuo47IHw/OT6KS9lb8lT2R/ujVoDARy/eOhw8cAFXo+QcvzNSW2qKf/Qo21uR/wz2u9SRV0lvUDNSvC2PYtR+iPlDwHY81md430yiNf9w== root@server.magelinux.com EOF #ClientName=`ifconfig eth0 | awk '/inet addr:/{print $2}' | awk -F. '{print $NF}'` #sed -i "s@HOSTNAME=.*@HOSTNAME=client$ClientName.magelinux.com@g" /etc/sysconfig/networks # set hosts echo '10.1.0.1 server.magelinux.com server' >> /etc/hosts # yum repo %end %packages @base @basic-desktop @chinese-support @client-mgmt-tools @core @desktop-platform @fonts @general-desktop @graphical-admin-tools @legacy-x @network-file-system-client @perl-runtime @x11 %end
§·anaconda使用網絡中yum倉庫自動安裝系統
※·步驟一:準備簡版的ISO光盤文件和ks文件
1 把光盤中 isolinux目錄拷貝到/root/isolinux
[root@centos68 ~]# ll i solinux/ total 8 drwxr-xr-x. 2 root root 4096 Sep 11 20:37 isolinux #拷貝光盤上isolinux目錄到/root/isolinux -rw-r--r--. 1 root root 1249 Sep 11 22:19 ks.cfg #把制作好的ks文件放在/root/isolinux 2 修改啟動菜單選項
[root@centos68 isolinux]# cat grub.conf #修改grub.conf文件的部分內容 好像沒有需要修改的 #debug --graphics default=0 splashimage=@SPLASHPATH@ timeout 5 hiddenmenu title @PRODUCT@ @VERSION@ kernel @KERNELPATH@ initrd @INITRDPATH@ title Install system with basic video driver kernel @KERNELPATH@ nomodeset askmethod initrd @INITRDPATH@ title rescue kernel @KERNELPATH@ rescue askmethod initrd @INITRDPATH@
3 修改菜單文件 isolinux.cfg
[root@centos68 isolinux]# cat isolinux.cfg default vesamenu.c32 #prompt 1 timeout 10 #設置菜單等待時間,600為60秒,設置的10是不是太快了,1秒不到 display boot.msg menu background splash.jpg menu title www.megedu.com #設置菜單的標題欄顯示字符 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(install linux chenchenchen) #修改菜單顯示的內容 menu default kernel vmlinuz append initrd=initrd.img ks=cdrom:/ks.cfg #設置KS文件的路徑,注意路徑不要填寫有問題的 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 - [root@centos68 isolinux]#
4 查看ks.cfg文件內容
[root@centos68 ~]# cat isolinux/ks.cfg #安裝前環境配置階段 #platform=x86, AMD64, or Intel EM64T #CPU類型 #version=DEVEL # Firewall configuration firewall --disabled #關閉防火墻 # Install OS instead of upgrade install #是升級還是安裝系統(默認為安裝系統) # Use network installation url --url="http://10.1.0.1/cobbler/ks_mirror/CentOS-6-x86_64" #設置網絡倉庫 # Root password rootpw --iscrypted $1$63jPqtg3$bLyM53ziQtTP/Vu8IC.uD/ #管理員密碼加密 # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # System keyboard keyboard us #鍵盤設置 # System language lang en_US #語言設置 # SELinux configuration selinux --disabled #selinux關閉(只是關閉該功能,并不是不安裝此軟件,該功能在內核中) # Installation logging level logging --level=info #日志級別 # Reboot after installation reboot #安裝后重啟 # System timezone timezone Africa/Abidjan #時區設置 # Network information network --bootproto=static --device=eth0 --ip=10.1.16.250 --netmask=255.255.0.0 --onboot=on #配置網卡信息 # System bootloader configuration bootloader --location=mbr #安裝bootloader到MBR(可以選擇安裝到分區頭部) # Clear the Master Boot Record zerombr #分區前清空MBR信息 # Partition clearing information clearpart --all --initlabel #分區前刪除所有分區 # Disk partitioning information part /boot --asprimary --fstype="ext4" --size=500 #創建boot分區為 500M大小 part swap --fstype="swap" --size=512 #創建swap分區大小為 512M part / --fstype="ext4" --size=10000 #創建 / 分區為10G #程序包安裝階段 %packages @backup-client @base @compat-libraries @console-internet @debugging @dial-up @directory-client @hardware-monitoring @infiniband @storage-client-fcoe %end
小結:配置ks文件的時候一定要注意各項的配置,由于第一次沒有設置 SWAP的分區,系統無法啟動的。當系統無法啟動時,好好檢查是不是KS文件出了問題。
※·步驟二:通過命令mkisofs生成iso鏡像文件
[root@centos68 ~]# pwd /root [root@centos68 ~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "Centos 6 x86_64 boot " -c isolinux/boot.cat -b isolinux/isolinux.bin -o /root/boot.iso isolinux/ [root@centos68 ~]# ll boot.iso -rw-r--r--. 1 root root 45873152 Sep 11 22:20 boot.iso [root@centos68 ~]# 不要命令的具體的內容,記下來就好,關鍵的幾個參數介紹下: --boot-info-table -V "Centos 6 x86_64 boot " : 設置光盤的標簽 -c isolinux/boot.cat :MBR程序的文件路徑 -b isolinux/isolinux.bin : stage2 程序的文件路徑 -o /root/boot.iso : 生成的iso文路徑和名稱 isolinux/ :需要把那個目錄制作成iso文件 #注意:光盤的 isolinux里面的文件拷貝出來是只讀的,記得自己修改下目錄權限和下面的文件權限 chmod +w isolinux/*
※·步驟三:是用生成的 boot.iso文件做為啟動光盤啟動系統
1.查看下開機菜單畫面
2.配置IP地址
C:\Users\hasee>ping 10.1.16.250 -t 正在 Ping 10.1.16.250 具有 32 字節的數據: 來自 10.1.16.1 的回復: 無法訪問目標主機。 請求超時。 請求超時。 請求超時。 請求超時。 請求超時。 請求超時。 請求超時。 請求超時。 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間=2ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64 來自 10.1.16.250 的回復: 字節=32 時間<1ms TTL=64
3.自動分區
4.自動安裝包組
小結:
以上就是一個從簡裝光盤啟動,系統安裝的軟件包通過網絡yum倉庫獲取的的簡單實例。
案例要點:
1.自己簡版的光盤啟動文件,在菜單配置文件中需要指明ks文件的的存放路徑(本地和網絡都可以,如果需要使用網絡傳送ks文件,記得需要在傳遞內核參數的時候把IP地址配置好),由于自己是本地的光盤提供的ks文件,所以配置網絡地址這邊設置的是在anaconda 啟動以后。
2.KS文件的內容:
IP地址配置,網絡倉庫的位置,分區的規劃,等等一定要注意。
3.啟動后系統問題檢測:
系統自動安裝完成后,貌似么沒有自動掛載swap,得好好檢查下
原創文章,作者:linux_root,如若轉載,請注明出處:http://www.www58058.com/46381
總結的很完整,贊一個