在centos7實現PXE支持centos5,6,7的系統安裝
本博主要目的為實現自定義頁面自動化安裝系統,基於PXE支持的網卡,目前實現環境為VMware虛擬機。
所用鏡像為CentOS6.9,CentOS7.3及rhel5.4。支持中小規模自動化系統統一安裝。
另:如果最近常見到pxe相關博文,多半為阿拉的同期,還請不要在意內容的重復性。不同人眼中的pxe自動化安裝,如此理解吧。
環境準備
1.網絡環境:獨立網絡環境配備
實驗中需要配置dhcp服務器,所以多余的網絡會和本地dhcp服務器造成沖突。
阿拉的虛擬機裏僅選用了一個獨立網卡,同時主機配置靜態IP。
2.外部環境:這裏主要指防火墻和SElinux,二者會對實驗造成影響,所以這裏,關掉會省去很多麻煩。
3.安裝必要軟件包:這裏syslinux包裏的幾個文件是必須的,dhcpd包提供dhcp服務器環境配置,tftp-server是輕文本傳輸用到的。httpd和ftpd選裝一個就OK,主要是我們從網站或ftp服務器上獲取數據使用。
yum install httpd dhcp tftp-server syslinux --skip-broken
原理及過程
從網絡獲取鏡像文件,並獨立配置安裝菜單選項,網絡引導。
當某機使用完成後的環境安裝系統時,首先網卡啟動,然後向本機,即dhcp服務器申請IP。IP獲得後,tftp負責文本傳輸,得到網站上的pxe啟動文檔等信息,並根據引導文件安裝系統。
這裏為了簡便,dhcp服務器及http網站等均由本機擔任。
實現步驟
1.dhcpd文件配置
[[email protected] ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf #上面的第一個文件是模板,第二個是配置文件 [[email protected] ~]# vim /etc/dhcp/dhcpd.conf #查照此文件中的模板添加下信息,此段信息最好放在原文件中第一個subnet上方。 subnet 192.168.23.0 netmask 255.255.255.0{ range 192.168.23.10 192.168.234.100; option routes 192.168.23.7; next-server 192.168.23.7; #此處為本機IP filename "pxelinux.0"; #pxe啟動文檔 }
2.開啟服務
systemctl enable dhcpd httpd tftp 將服務設為開機啟動
systemctl start dhcpd httpd tftp 啟動服務
systemctl status dhcpd httpd tftp 查看服務狀態
3.掛載鏡像文件到http
確保三個鏡像都已連接,然後按順序掛好。不要弄錯了。
cd /var/www/html/
mkdir centos{6,7}
mkdir rhel5
echo ‘- - -‘ > /sys/class/scsi_host/host2/scan
mount /dev/sr0 /var/www/html/centos7
mount /dev/sr1 /var/www/html/centos6
mount /dev/sr2 /var/www/html/rhel5
也可以把掛載寫入/etc/fstab文件。
4.編輯安裝引導文件ks.cfg
可以簡單編輯root家目錄下的anaconda-ks.cfg,然後把三個系統的引導文件復制到本機的/var/html/www/下。並註意此文件權限為644。
centos7的.cfg文件參考如下:
[[email protected] ~]# cat /var/www/html/ks7.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media url --url=http://192.168.23.7/centos7 # Use graphical install #graphical text reboot # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=us --xlayouts=‘us‘ # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate network --hostname=centos7.magedu.com # Root password rootpw --iscrypted $6$/BVcMpadhqgy0l4J$FQ1fqYddKm1zqjxEkXn3XctFXiJ2LLWnVfRPi1u1oF6Wx5ebfKwe.8W0wHfF7oxeqDLJbkJJYTnry7W9o/6KP/ # System services services --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp # X Window System configuration information xconfig --startxonboot # System bootloader configuration zerombr bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda # Partition clearing information clearpart --all --initlabel --drives=sda # Disk partitioning information part / --fstype="xfs" --ondisk=sda --size=47683 part /boot --fstype="xfs" --ondisk=sda --size=953 part swap --fstype="swap" --ondisk=sda --size=3814 part /app --fstype="xfs" --ondisk=sda --size=47683 %packages @base @core @dial-up @fonts @guest-agents @network-file-system-client @networkmanager-submodules @x11 %end %addon com_redhat_kdump --disable --reserve-mb=‘auto‘ %end %anaconda pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty %end
centos6的.cfg參考如下:
[[email protected] html]# cat /var/www/html/ksdir/ks6.cfg # Kickstart file automatically generated by anaconda. #version=DEVEL install url --url=http://httpsrv/centos/6 lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$CxpwSUg0oCIQZX52$0yfD8CXU4Q.60uYDqSHWz5.1enxwnhrv9esPRYSix4U1cWoaN.hOpgSLqCd22yjRdEhAwwUdxAIbn.mxMn.kx/ firewall --disable authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # 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 zerombr clearpart --all reboot text part /boot --fstype=ext4 --size=1000 part / --fstype=ext4 --size=100000 part /app --fstype=ext4 --size=50000 part swap --size=2048 %packages @base @core @basic-desktop @desktop-platform @fonts @general-desktop @graphical-admin-tools @input-methods @internet-applications @internet-browser @network-file-system-client @office-suite @print-client @remote-desktop-clients @server-policy @workstation-policy @x11 mtools pax %end
rhel5的.cfg文件如下:
# Kickstart file automatically generated by anaconda. install url --url=http://192.168.23.7/rhel5 key --skip lang zh_CN.UTF-8 keyboard us xconfig --startxonboot network --device eth0 --bootproto dhcp --hostname rhel5.4.centos.com rootpw --iscrypted $1$YntMaKAR$vXCZ6J8hGwcRtfso7lk9o. firewall --enabled --port=22:tcp authconfig --enableshadow --enablemd5 selinux --disabled timezone Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="rhgb quiet" # 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 --linux zerombr clearpart --all reboot text part /boot --fstype ext3 --size=100 part / --fstype ext3 --size=51200 part /app --fstype ext3 --size=10240 part swap --size=1024 %packages @admin-tools @base @core @dialup @editors @graphical-internet @graphics @legacy-software-support @office @printing @text-internet @base-x kexec-tools fipscheck sgpio emacs libsane-hpaio xorg-x11-utils xorg-x11-server-Xnest
5.準備相關文件,必備文件如下:
pxelinux.0(pex引導文件),menu.c32(圖形菜單),vmlinuz內核文件,initrd.img初始根文件系統
配置文件:isolinux.cfg改名為pxelinux.cfg/default
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
mkdir /var/lib/tftpboot/centos{6,7}
mkdir /var/lib/tftpboot/rhel5
cp /var/www/html/rhel5/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/rhel5
cp /var/www/html/centos6/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos6
cp /var/www/html/centos7/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos7
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /var/www/html/centos/7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
此環節準備的文件均在/var/lib/tftpboot下,以便通過tftp獲取文件。
[[email protected] tftpboot]# tree /var/lib/tftpboot . |-- centos6 | |-- initrd.img | `-- vmlinuz |-- centos7 | |-- initrd.img | `-- vmlinuz |-- menu.c32 |-- pxelinux.0 |-- pxelinux.cfg | `-- default `-- rhel5 |-- initrd.img `-- vmlinuz 4 directories, 9 files
6.編輯自動化安裝頁面菜單
即編輯/var/lib/tftpboot/pxelinux.cfg/default文件。其基本信息如下:
[[email protected] ~]# vim /var/lib/tftpboot/pxelinux.cfg/default default menu.c32 timeout 600 menu title CentOS Linux 7 label centos7 menu label ^Auto Install CentOS Linux 7 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://httpsrv/ksdir/ks7.cfg label centos6 menu label Auto install CentOS Linux ^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=http://httpsrv/ksdir/ks6.cfg label manualcentos6 menu label ^Manual install CentOS Linux 6 kernel centos6/vmlinuz append initrd=centos6/initrd.img inst.repo=http://httpsrv/centos/6/ label local menu default menu label Boot from ^local drive localboot 0xffff menu end
這樣制作過程便OK了。期間可能出現小的錯誤導致服務不能正常重啟。還要就事論事,一項項排除。主要步驟就是這些了。
安裝測試
設置網卡與服務器(即上面配置的主機)為同一網段,即僅能連接到服務器端,不能連接到其他網絡環境。
如果是沒有裝過操作系統的新機開機就會自動裝載系統,不過,需要你手動選擇要安裝的系統哦。默認可是按本地磁盤啟動的。
安裝過操作系統的若想覆蓋安裝,則要在bios裏調整啟動順序,將網絡引導調至最上面。
阿拉測試後,centos6與rhel5都能成功安裝,centos7還有些小bug。麻煩知道問題所在的親們略微指點了。或者阿拉找出解決辦法後會再來更新的。
對了,rhel5的中文包沒裝,圖形化可能不舒服,需要的暫自行解決下。十一快樂哦。命令行沒事的哦。
鳥哥的linux私房菜有提及與本博相似的目的達成。對實驗步驟不甚理解的可以查閱http://linux.vbird.org/linux_enterprise/0120installation.php#pxe_dhcp
本文出自 “RightNow” 博客,請務必保留此出處http://amelie.blog.51cto.com/12850951/1970047
在centos7實現PXE支持centos5,6,7的系統安裝