PXE介紹
1)Preboot Excution Environment 預啟動執行環境 2)Intel公司研發 3)基於Client/Server的網絡模式,支持遠程主機通過網絡從遠端服務器下載映像,並由此支持通過網絡啟動操作系統 4)PXE可以引導和安裝Windows,linux等多種操作系統
PXE工作原理
- Client向PXE Server上的DHCP發送IP地址請求消息,DHCP檢測Client是否合法(主要是檢測Client的網卡MAC地址),如果合法則返回Client的IP地址,同時將啟動文件pxelinux.0的位置信息一並傳送給Client
- Client向PXE Server上的TFTP發送獲取pxelinux.0請求消息,TFTP接收到消息之后再向Client發送pxelinux.0大小信息,試探Client是否滿意,當TFTP收到Client發回的同意大小信息之后,正式向Client發送pxelinux.0 Client執行接收到的pxelinux.0文件
- Client向TFTP Server發送針對本機的配置信息文件(在TFTP 服務的pxelinux.cfg目錄下),TFTP將配置文件發回Client,繼而Client根據配置文件執行后續操作。
- Client向TFTP發送Linux內核請求信息,TFTP接收到消息之后將內核文件發送給Client
- Client向TFTP發送根文件請求信息,TFTP接收到消息之后返回Linux根文件系統
- Client啟動Linux內核
- Client下載安裝源文件,讀取自動化安裝腳本
操作系統安裝的流程
1)通用流程:首先,bios啟動,選擇操作系統的啟動(安裝)模式(此時,內存是空白的),然后根據相關的安裝模式,尋找操作系統的引導程序(不同的模式,對應不同的引導程序當然也對應着不同的引導程序存在的位置),引導程序加載文件系統初始化(initrd)程序和內核初始鏡像(vmlinuz),完成操作系統安裝前的初始化;接着,操作系統開始安裝相關的系統和應用程序。 2)硬盤安裝的流程:bios啟動——MBR尋找grub——grub程序讀取menu.list等配置文件,找到內核啟動鏡像和相關初始化程序,安裝(或者啟動)。 3)PXE(Pre-boot Execution Environment)是由Intel設計,可以使計算機通過網絡啟動的協議。協議分為client和server兩端,PXE client在網卡的ROM中,當計算機啟動時,BIOS把PXE client調入內存執行,並顯示出命令菜單,經用戶選擇后,PXE client將放置在遠端的操作系統通過網絡下載到本地運行。 4)pxe網絡安裝的流程:bios啟動——pxe client中的程序進入內存,顯示命令菜單——此程序開始尋找網絡引導程序(bootstrap文件,這個文件的名字隨着發行版的不同而不同,在centos中,它是pxelinux.0)——引導程序讀取配置文件pxelinux.cfg, 獲得系統初始化的相關文件信息——系統啟動,開始進行安裝。
PXE自動化安裝CentOS 7
安裝前准備:關閉防火牆和SELINUX,DHCP服務器靜態IP
安裝軟件包
yum install tftp-server (安裝服務端TFTP包) yum install dhcp 安裝dhcp yum install http 安裝http
centos7啟動tftp服務:
[root@centos7~]#systemctl start tftp 啟動tftp [root@centos7~]#systemctl enable tftp [root@centos7~]#ss -nultp users:(("rpc.statd",pid=6655,fd=10)) udp UNCONN 0 0 :::69 tftp默認端口是69
centos6啟動tftp服務:
[root@centos6~]#chkconfig tftp on 啟動tftp,下次默認開機啟動 [root@centos6~]#service xinetd start Starting xinetd:
TFTP從服務器上上傳下載文件功能,下載時需要知道對方的文件名,下載下來的文件會在/var/lib/tftpboot目錄里(tftp獲取文件部分):
[root@centos7data]#cp /etc/fstab /var/lib/tftpboot/f1 將服務器的文件放在/var/lib/tfpboot/目錄下,起名叫f1 [root@centos6~]#tftp 192.168.34.101 通過連接tftp服務在/var/lib/tftpboot/目錄下下載必要的文件 tftp> status Connected to 192.168.34.101. Mode: netascii Verbose: off Tracing: off Literal: off Rexmt-interval: 5 seconds, Max-timeout: 25 seconds tftp> get f1 在tftp服務上下載文件 tftp> q 按q可以退出
安裝http服務:
[root@centos7~]# yum install http 安裝完http服務后 [root@centos7~]# systemctl start httpd 啟動http服務 [root@centos7~]# systemctl enable httpd 啟動http服務,默認下次開啟啟動
創建網頁版yum源 :
[root@centos7~]#mkdir -pv /var/www/html/centos/{6,7}/os/x86_64/ 創建一個centos6/7的文件 [root@centos7html]#mount /dev/sr0 centos/7/os/x86_64/ 將光盤掛載到cnetos7文件夾下 mount: /dev/sr0 is write-protected, mounting read-only
將應答文件放到http服務上:
[root@centos7~]#mkdir /var/www/html/ksdir 新建了一個應答文件夾 [root@centos7~]#cp anaconda-ks.cfg /var/www/html/ksdir/ks7_mini.cfg 將現有的家目錄文件anaconda-ks.cfg文件復制到ksdir文件夾下面,起名叫ks7_mini.cfg [root@centos7ksdir]#vim ks7_mini.cfg 修改里邊的應答文件信息 #version=DEVEL # Use CDROM installation media url --url=http://192.168.34.101/centos/7/os/x86_64/ 將網頁掛載的光盤路徑寫上 # Use graphical install text 文本格式安裝 # 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 --ipv6=auto --activate network --hostname=centos7.localdomain # Root password rootpw --iscrypted $6$zQd4v6GjKalpnj.h$uutceFNO9vO0H2mJoBQYgpW5iNUrmKNHWulIKrSFfPJtpu4f.llg6rm9veeswxYrFXOpXV5M9MPqMBv/DGjdj. # System services firewall --disabled 防火牆關掉 selinux --disabled selinux關掉 # System timezone timezone Asia/Shanghai --isUtc --nontp user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu" # X Window System configuration information # System bootloader configuration bootloader --location=mbr --boot-drive=sda # Partition clearing information clearpart --all --initlabel 磁盤全部格式化 zerombr mbr磁盤清空 reboot 安裝完重啟 # Disk partitioning information part /boot --fstype="xfs" --ondisk=sda --size=1024 part / --fstype="xfs" --ondisk=sda --size=102400 part swap --fstype="swap" --ondisk=sda --size=3072 part /data --fstype="xfs" --ondisk=sda --size=51200 %packages @core 只安裝一個核文件 %end [root@centos7ksdir]#ll total 4 -rw------- 1 root root 1906 Oct 30 20:19 ks7_mini.cfg 由於應答文件在root模式下有讀權限,需要全部加讀權限 [root@centos7ksdir]#chmod +r ks7_mini.cfg 將應答文件加讀權限
安裝和配置DHCP服務
[root@centos7~]#yum install dhcp 安裝dhcp服務
[root@centos7~]#vim /etc/dhcp/dhcpd.conf 配置dhcp服務 # dhcpd.conf # # Sample configuration file for ISC dhcpd # # option definitions common to all supported networks... option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 86400; max-lease-time 864000; # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 192.168.34.0 netmask 255.255.255.0 { 聲明當前的IP地址段和子網掩碼 range 192.168.34.10 192.168.34.200; 設置地址池:192.168.34.10-200 option routers 192.168.34.1; 設置當前的網關地址 option domain-name-servers 8.8.8.8; 設置DNS next-server 192.168.34.101; 指明引導所在的服務主機的IP地址 filename "pxelinux.0"; 指明引導文件名稱 } # This is a very basic subnet declaration.
[root@centos7~]#systemctl enable dhcpd 配置好dhcp服務后,啟動dhcp服務,默認下次開機啟動
安裝syslinux 里邊有pxelinux.0包文件
[root@centos7~]#yum install syslinux -y 安裝syslinux包 Loaded plugins: fastestmirror, langpacks Repository 'development' is missing name in configuration, using id Repository 'ELPL' is missing name in configuration, using id Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package syslinux.x86_64 0:4.05-15.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================== Package Arch Version Repository Size ====================================================================================================================== Installing: syslinux x86_64 4.05-15.el7 development 990 k Transaction Summary ====================================================================================================================== Install 1 Package Total download size: 990 k Installed size: 2.3 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : syslinux-4.05-15.el7.x86_64 1/1 Verifying : syslinux-4.05-15.el7.x86_64 1/1 Installed: syslinux.x86_64 0:4.05-15.el7 Complete!
syslinux配置文件相關的安裝包:
[root@centos7~]#rpm -ql syslinux /usr/share/syslinux/menu.c32 開機啟動的藍色背景 /usr/share/syslinux/pxelinux.0 pxelinux.0包位置
[root@centos7~]#mkdir /var/lib/tftpboot/pxelinux.cfg 創建一個pxelinux.cfg相關文件夾 [root@centos7~]#cp /usr/share/syslinux/{menu.c32,pxelinux.0} /var/lib/tftpboot 將syslinux下的兩個配置文件放到tftpboot目錄下,其中menu.c32 開機時作為藍色背景。 [root@centos7~]#cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot 將光盤下的內核啟動文件vmlinuz和initrd.img文件放到tftpboot目錄下 [root@centos7~]#cd /var/lib/tftpboot [root@centos7tftpboot]#cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 將isolinux.cfg文件復制到pxelinux.cfg文件夾下,起名叫default,作為啟動菜單。 [root@centos7tftpboot]#tree 查看已經創建的文件信息,一個文件都不能少 . ├── initrd.img ├── menu.c32 ├── pxelinux.0 ├── pxelinux.cfg │ └── default └── vmlinuz
修改pxelinux.cfg下的default配置文件的信息:
[root@centos7tftpboot]#vim /var/lib/tftpboot/pxelinux.cfg/default 修改配置文件信息 default menu.c32 開機藍色背景 timeout 100 超時時長改為10秒 menu title PXE CentOS 開機顯示的抬頭信息 label mini 最小化安裝名稱 menu label ^Auto Install mini CentOS 7 自動化安裝名稱 kernel vmlinuz append initrd=initrd.img ks=http://192.168.34.101/ksdir/ks7_mini.cfg 寫入引導文件路徑 label desktop 備用的桌面安裝 menu label ^Auto Install desktop CentOS 7 書寫相關備用桌面格式 kernel vmlinuz append initrd=initrd.img ks=http://192.168.34.105/ksdir/ks7_mini.cfg label local menu default 默認的本地安裝 menu label Boot from ^local drive localboot 0xffff
在新開一台機器開始安裝系統,將網卡模式設置為僅主機模式,將VMnet1對勾去掉,保證與服務端的網卡在一個網卡上:
開機通過ARP廣播開始尋找同一網卡的配置文件信息,進而找到以上寫入的相關配置文件,實現自動化安裝:
注意:centos7系統的內存盡量設置1.2G以上,否則會提示內存空間不足,導致無法安裝。
centos6系統安裝過程:
准備工作:
[root@centos6~]#chkconfig tftp on 啟動tftp服務 [root@centos6~]#service xinetd start Starting xinetd: [root@centos6~]#service httpd start 啟動http服務 Starting httpd:
將光盤掛載到網頁上:
[root@centos6html]#mkdir -pv centos/6/os/x86_64 新建文件夾 mkdir: created directory `centos' mkdir: created directory `centos/6' mkdir: created directory `centos/6/os' mkdir: created directory `centos/6/os/x86_64' [root@centos6html]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64 將新建的文件掛載到網頁上 mount: block device /dev/sr0 is write-protected, mounting read-only
制作應答文件:
[root@centos6tftpboot]#cp /root/anaconda-ks.cfg ks6_mini.cfg 將系統中自帶的文件復制一份到/var/lib/tftpboot目錄下 [root@centos6tftpboot]#vim ks6_mini.cfg 修改當前的應答文件信息 url --url=http://192.168.34.105/centos/6/os/x86_64 指定掛載光盤路徑 lang en_US.UTF-8 keyboard us text 以文本形式安裝 reboot 安裝完重啟 network --onboot yes --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$6pdd/ulLIO5IoQ2u$EKDznPOR19rWTeBjVVTYGay3PbNd3t0v9.Ae.jOsxP9i3T8khOMhDxDwTzfa9E3gqirD7qD3Pw6qK1QKf2pDE0 firewall --disabled 關閉防火牆 authconfig --enableshadow --passalgo=sha512 selinux --disabled 關閉selinux 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 clearpart --all 格式化磁盤 zerombr 情況mbr分區 part /boot --fstype=ext4 --size=1024 boot分區 part / --fstype=ext4 --size=100000 根分區 part /data --fstype=ext4 --size=50000 data分區 part swap --size=2048 swap 分區 %packages @core 只安裝核包 %end [root@centos6tftpboot]#chmod +r ks6_mini.cfg 因為應答文件只有root有讀權限,將全部屬組都加有讀權限
安裝dhcp服務,並修改相關配置信息:
[root@centos6~]#yum install dhcp 安裝dhcp服務
[root@centos6html]#vim /etc/dhcp/dhcpd.conf 修改dhcp配置信息 default-lease-time 84600; 申請默認租期 max-lease-time 86400; 最大申請租期 # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 192.168.34.0 netmask 255.255.255.0 { 聲明地址段和子網掩碼 range 192.168.34.10 192.168.34.200; 設置地址池:192.168.34.10-200 option domain-name-servers 8.8.8.8; 設置NDS next-server 192.168.34.105; 指明引導服務主機所在的IP地址 filename "pxelinux.0"; 指明引導的文件名稱 }
[root@centos6html]#service dhcpd start 重新啟動dhcp服務
將相關的配置文件放在/var/lib/tftpboot目錄下:
[root@centos6html]#cd /var/lib/tftpboot [root@centos6tftpboot]#mkdir pxelinux.cfg [root@centos6tftpboot]#yum install syslinux-nonlinux [root@centos6tftpboot]#cp /misc/cd/isolinux/{initrd.img,boot.msg,vmlinuz,splash.jpg,vesamenu.c32} . [root@centos6tftpboot]#cp /misc/cd/isolinux//isolinux.cfg pxelinux.cfg/default
修改當前pxelinux.cfg下面的default配置文件信息:
[root@centos6tftpboot]#vim pxelinux.cfg/default default vesamenu.c32 #prompt 1 timeout 100 超時時長修改至10s label linux menu label ^Auto Install Mini centos 6 system 修改為自動安裝 menu default kernel vmlinuz append initrd=initrd.img ks=http://192.168.34.105/ksdir/ks6_mini.cfg 指定當前的應答文件路徑 label local menu default 設置一個默認安裝 menu label Boot from ^local drive localboot 0xffff
至此,相關的配置文件設置完成,打開一個新的虛擬機進行安裝系統,將網卡默認設置成僅主機模式,將vmnet1的DHCP功能關掉,開機后按esc,選擇網卡啟動安裝,開始安裝系統,結束。
選擇網卡啟動,然后按F10保存,就會自動重啟,新裝的主機就會通過廣播獲取DHCP相關的安裝配置信息,就會啟動進行安裝,至此,cnetos6安裝結束。
在centos7基於PXE安裝centos6/7系統實驗:(此安裝適用於BIOS模式安裝)
在centos7上新加一塊ISO鏡像:
准備工作:
啟動三個服務:
[root@centos7tftpboot]#systemctl start dhcpd [root@centos7tftpboot]#systemctl start tftp [root@centos7tftpboot]#systemctl start httpd
掛載光盤:
[root@centos7~]#mkdir /var/www/html/centos/{6,7}/os/x86_64 [root@centos7~]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/ [root@centos7~]#mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
復制centos7之前制作的應答文件或者(也可以復制家目錄的anaconda-ks.cfg里的相關應答文件)和內核啟動文件
[root@centos7ksdir]#cp /root/anaconda-ks.cfg ks7_mini.cfg
[root@centos7ksdir]#scp /root/anaconda-sks.cfg /var/www/html/ksdir/ks6_mini.cfg 將centos6的默認應答文件復制到centos7目錄里,命令為ks6_mini.cfg,然后對其稍加修改即可。
[root@centos7ksdir]#ll
total 8
-rw-r--r-- 1 root root 1400 Oct 31 09:21 ks6_mini.cfg
-rw-r--r-- 1 root root 1400 Oct 30 20:29 ks7_mini.cfg
[root@centos7tftpboot]#mkdir linux{6,7}
[root@centos7tftpboot]#mv vmlinuz initrd.img linux7/ 將本地的內核啟動文件復制在新建的linux7下
[root@centos7tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} linux6/ 將掛載的iso光盤的啟動文件復制到新建的linux6下
[root@centos7tftpboot]#cp /usr/share/syslinux/{menu.c32,pxelinux.0}
[root@centos7tftpboot]#cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg 將啟動菜單復制到pxelinu.cfg目錄下
[root@centos7tftpboot]#tree
.
├── linux6
│ ├── initrd.img
│ └── vmlinuz
├── linux7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default 修改此配置文件信息
修改引導文件信息:
vim pxelinux.cfg/default default menu.c32 timeout 100 menu title PXE Insall CentOS label mini7 menu label ^Auto Install mini7 CentOS 7 修改啟動顯示的信息 kernel linux7/vmlinuz 由於新建了linux7,啟動文件路徑在此目錄下,需要指定啟動文件在linux7下面 append initrd=linux7/initrd.img ks=http://192.168.34.101/ksdir/ks7_mini.cfg 指定應答文件路徑 label mini6 menu label ^Auto Install mini6 CentOS 6 修改顯示的信息 kernel linux6/vmlinuz 由於新建了一個linux6,啟動文件路徑在此目錄下,因此需要添加linux6路徑指定應答文件 append initrd=linux6/initrd.img ks=http://192.168.34.101/ksdir/ks6_mini.cfg 指定應答文件路徑 label local menu default menu label Boot from ^local drive localboot 0xffff
修改centos6的應答文件內容:
[root@centos7tftpboot]#vim /var/www/html/ksdir/ks6_mini.cfg url --url=http://192.168.34.101/centos/6/os/x86_64 指定centos6光盤掛載路徑 text 以文本方式安裝 # System services firewall --disabled 防火牆關掉 selinux --disabled selinux關掉 # System timezone timezone Asia/Shanghai --isUtc --nontp user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu" # X Window System configuration information #xconfig --startxonboot # System bootloader configuration bootloader --location=mbr --boot-drive=sda # Partition clearing information clearpart --all --initlabel 格式化磁盤 zerombr 清空mbr磁盤 reboot 重啟 # Disk partitioning information part /boot --fstype="xfs" --ondisk=sda --size=1024 part / --fstype="xfs" --ondisk=sda --size=102400 part swap --fstype="swap" --ondisk=sda --size=3072 part /data --fstype="xfs" --ondisk=sda --size=51200 %post mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak cat > /etc/yum.repos.d/base.repo << EOF [base] basurl=http://192.168.34.100/centos/6/os/x86_64 gpgckeck=0 EOF useradd wang echo centos |passwd --stdin wang mkdir /root/.ssh 生產公鑰腳本 cat > /root/.ssh/authorized.keys << EOF 將已經安裝好的centos6的id_rsa.pub公鑰信息寫入。 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5hEv1/BQLBftA/tK5h+cF+zop59zMlpsMpXdaww8j3zktwSywDHhJI1cpWHS+rbUD1BKnapSL3Lfvi7o03rFAauAECgFjrJkAHX53Q1eh2ORfMpScaSPQ78CALSQ3pWN6Elgs6xwAAIc2MUXyoG5TTOJ0PSekzKrTww5xHuNsitXgrKfD2dBIAWFk7vwekk4kvRLBT3rbG19fYc0cTv9u+b6+Xi8EhpwR+v4BAN3eE+CFvEIsZDrp0ul566B9NZBBUBe8EJkr+H/dPRA4PR5Hctyhd27uE9hQ70QzBGBuhrL+NKxi3hRTWuLWoSUs3pP99x9km02FjzDDVOHWS7MVQ== root@centos6.10.localdomain EOF chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized.keys %end %packages @core 安裝內核包 %end
修改centos7的應答文件配置信息:
[root@centos7tftpboot]#vim /var/www/html/ksdir/ks7_mini.cfg url --url=http://192.168.34.101/centos/7/os/x86_64/ 指定centos7掛載光盤路徑 # Use graphical install text 文本方式安裝 # 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 --ipv6=auto --activate network --hostname=centos7.localdomain # Root password rootpw --iscrypted $6$zQd4v6GjKalpnj.h$uutceFNO9vO0H2mJoBQYgpW5iNUrmKNHWulIKrSFfPJtpu4f.llg6rm9veeswxYrFXOpXV5M9MPqMBv/DGjdj. # System services firewall --disabled 關閉防火牆 selinux --disabled 關閉selinux # System timezone timezone Asia/Shanghai --isUtc --nontp user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu" # X Window System configuration information #xconfig --startxonboot # System bootloader configuration bootloader --location=mbr --boot-drive=sda # Partition clearing information clearpart --all --initlabel 清空磁盤分區 zerombr 清空mbr磁盤 reboot 重啟 # Disk partitioning information part /boot --fstype="xfs" --ondisk=sda --size=1024 part / --fstype="xfs" --ondisk=sda --size=102400 part swap --fstype="swap" --ondisk=sda --size=3072 part /data --fstype="xfs" --ondisk=sda --size=51200 %post mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak cat > /etc/yum.repos.d/base.repo << EOF [base] basurl=http://192.168.34.100/centos/6/os/x86_64 gpgckeck=0 EOF useradd wang echo centos |passwd --stdin wang mkdir /root/.ssh 生產公鑰腳本 cat > /root/.ssh/authorized.keys << EOF 將已經安裝好的centos6的id_rsa.pub公鑰信息寫入。 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5hEv1/BQLBftA/tK5h+cF+zop59zMlpsMpXdaww8j3zktwSywDHhJI1cpWHS+rbUD1BKnapSL3Lfvi7o03rFAauAECgFjrJkAHX53Q1eh2ORfMpScaSPQ78CALSQ3pWN6Elgs6xwAAIc2MUXyoG5TTOJ0PSekzKrTww5xHuNsitXgrKfD2dBIAWFk7vwekk4kvRLBT3rbG19fYc0cTv9u+b6+Xi8EhpwR+v4BAN3eE+CFvEIsZDrp0ul566B9NZBBUBe8EJkr+H/dPRA4PR5Hctyhd27uE9hQ70QzBGBuhrL+NKxi3hRTWuLWoSUs3pP99x9km02FjzDDVOHWS7MVQ== root@centos6.10.localdomain EOF chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized.keys %end %packages @core 安裝最小的核包 %end
上面的相關配置文件已經全部做完,現在可以打開一個主機,將網卡設置為僅主機模式,開機后按esc,設置為Network boot from Intel E1000引導進入,進不了這個界面可以在開機界面設置“打開電源時進入固件”,修改boot界面進入:
按+將網卡設置第一項啟動,然后按F10保存就會重啟,下來新安裝的主機就會通過DHCP獲取相關信息安裝系統:
顯示要安裝的界面,選擇上面兩個任意一個,對應的安裝centos6/7的系統,選擇后等待安裝結束。