安裝時的流程
安裝centos系統的流程和系統啟動流程是有一些類似的, 我們以光盤安裝為例來看一下安裝的幾個幾段和他們分別對應的文件
- BIOS加電自檢,同啟動流程的加電自檢
- 讀取MBR,光盤中的isolinux/boot.cat文件就相當于MBR,由于硬盤中還沒有引導程序,所以會自動加載到光盤中的這個文件當做MBR
- boot loader,通過光盤的MBR程序,加載這個光盤目錄下面的isolinux.bin文件,他根據isolinux.cfg文件的選項來加載內核vmlinuz和initrd.img文件,而這個isolinux.cfg文件就是我們安裝時所看到的菜單了
- initrd.img文件中的/sbin/loader文件會探測安裝介質,如果探測到是cd安裝,就會運行images目錄中的stage2.img(安裝過程需要的所有鏡像)鏡像文件,這個文件中最重要的就是anaconda程序,我們看到的安裝過程中的向導圖就是這個anaconda程序的作用。
5.然后就是anaconda程序接管安裝過程了,這個過程可以使用交互的方式,也可以使用應答文件來自動安裝,這里我們就需要使用應答文件來實現自動安裝
安裝步驟
我們的環境為centos6.9,然后做6.9和7.3的啟動,所以需要有這兩個版本的光盤。之后先將selinux和iptables禁掉,這樣會少很多問題。
- 先安裝需要的服務和程序并啟用
[root@localhost ~]# yum -y install dhcp tftp-server httpd syslinux #安裝
[root@localhost ~]# service httpd start #啟動httpd服務
[root@localhost ~]# chkconfig httpd on #將httpd服務添加到開機啟動
[root@localhost ~]# vim /etc/xinetd.d/tftp #tftp服務為xinetd代理的,將tftp配置文件中的disable=yes改為no,這樣才能啟用tftp
[root@localhost ~]#service xinetd start
- 修改dhcp配置文件并啟用
[root@localhost ~]# mv /etc/dhcp/dhcpd.conf{,.bak} #將原文件做備份
[root@localhost ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample/etc/dhcp/dhcpd.conf #將模板文件設為dhcpd配置文件
然后到配置文件中添加一段subnet
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.120 192.168.200.150;
filename "pxelinux.0";
next-server 192.168.8.133;
}
然后重啟dhcp服務,如果出問題了就使用cat /var/log/messages |grep dhcpd
來查看問題
3.準備yum源和應答文件
準備yum源
[root@localhost ~]# mkdir /var/www/html/centos6
[root@localhost ~]# mkdir /var/www/html/centos7 #創建6和7的yum源的存放路徑
[root@localhost ~]# mount /dev/sr0 /var/www/html/centos6 #掛載光盤
[root@localhost ~]# mount /dev/sr1 /var/www/html/centos7
制作應答文件
使用system-config-kickstart
命令,最后點左上角file將文件保存為/root/centos6.cfg(注意,如果提示沒有X,就安裝x window 和desktop這兩個包組,然后在虛擬機里邊的終端執行,在xdhell中需要開啟哪個xstart才可以),這里為實驗生成的應答文件,可以直接使用,注意文件一定是要可以讀的,沒有讀權限就不能讀取,用chmod a+r file
來將文件添加讀權限
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.200.100/centos6"
# Root password
rootpw --iscrypted $1$OAs3My.7$aICEXwH28N4o37CAZkiUG/
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
#graphical
text
reboot
# System keyboard
keyboard us
# System language
lang zh_CN
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=500
part / --fstype="ext4" --size=5000
part swap --fstype="swap" --size=2000
part /app --fstype="ext4" --size=5000
%post
useradd feng
echo "123" |passwd --stdin feng
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=base
baseurl=http://172.16.0.1/centos/6
gpgcheck=0
EOF
%end
%packages
@base
@core
@server-policy
@workstation-policy
%end
然后將應答文件復制到/var/www/html/ks下
[root@localhost ~]# mkdir /var/www/html/ks
[root@localhost ~]# cp /root/centos6.cfg /var/www/html/ks
7的應答文件在7中同樣的步驟實現,將生成的7的應答文件放到/var/www/html/ks中名為centos7.cfg
4.準備boot loader階段文件
總共需要5個必要的文件,分別為vmlinuz內核文件,initrd.img虛擬磁盤文件,isolinux.cfg安裝菜單文件,pxelinux.0用來引導使用pxe,和背景文件menu.c32,其中,前三個文件在光盤的isolinux/目錄下直接可以復制過去,而后兩文件是通過安裝syslinux程序來生成的,步驟如下:
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@localhost ~]# mkdir /var/lib/tftpboot/centos6
[root@localhost ~]# mkdir /var/lib/tftpboot/centos7 #創建目錄
[root@localhost ~]# cp /var/www/html/centos6/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos6/
[root@localhost ~]# cp /var/www/html/centos7/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos7/ #復制對應系統的內核和虛擬磁盤到對應的目錄下
[root@localhost ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
[root@localhost pxelinux.cfg]# cp /var/www/html/centos6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #復制lsolinux.cfg菜單文件到指定目錄并改名為default文件
編輯安裝菜單
default menu.c32
#prompt 1
timeout 600
menu title Welcome to CentOS 6.9 or CentOS 7.3
label autocentos7
menu label ^Automatic Mini Install CentOS 7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.200.200/ks/centos7.cfg
label autocentos6
menu label Automatic ^Desktop Install CentOS 6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://192.168.200.200/ks/centos6.cfg
label manual
menu label ^Manual Install CentOS 6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img
label local
menu label Boot from ^local drive
localboot 0xffff
完成后,就可以去驗證了。