天天看點

Centos PXE無人值守安裝作業系統

PXE無人值守安裝作業系統

安裝包

yum install -y httpd syslinux xinetd tftp-server dhcp-server
           

挂載

# 建立挂載鏡像目錄
mkdir /mnt/iso  && mkdir /var/www/html/cdrom       
# 把源挂載到/mnt/iso
mount /dev/cdrom /mnt/iso
# 複制
cp -prv /mnt/iso/* /var/www/html/cdrom/
           

http

# 複制自動應答檔案
cp ~/anaconda-ks.cfg /var/www/html/ks.cfg   
# 編輯/var/www/html/ks.cfg   
vim /var/www/html/ks.cfg  
#version=RHEL8
# Use text mode install 
text                                                #文本安裝
url     --url="http://10.10.10.101/cdrom"           #http提供鏡像
repo --name="AppStream" --baseurl=http://10.10.10.101/cdrom/AppStream/  #自動設定需要的配置

%packages
@^minimal-environment                              #最小化安裝
kexec-tools

%end

# System language                                                             
lang en_US.UTF-8                                   #語言格式

# Network information
network  --hostname=localhost.localdomain

# Use CDROM installation media                  
#cdrom                                              #安裝媒體cdrom方式安裝,注釋掉

# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx

ignoredisk --only-use=nvme0n1                      #注意硬碟名字
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=nvme0n1 #注意硬碟名字
autopart
# Partition clearing information
clearpart --all --initlabel --drives=nvme0n1           #清空硬碟所有資料 

# System timezone
timezone America/New_York --isUtc                     #時間地區

# Root password
rootpw --iscrypted      		                       #密碼 
$6$b0y28.qHTD3b0E/L$L9Wpc50bN5.cjiYhvFGRd6JwwVJ6zr.Xknzz0GbIwaoj2pnRYagNVpx./fr9y3Z3Ij0SC090djnoqX
HiipRje.

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot                        #加載完需要點選回車,添加後直接就自動重新開機了
           

tftp

# 主要複制的是pxelinux.0但由于缺少檔案全複制,pxe引導程式檔案
cp -prfv /usr/share/syslinux/ /var/lib/tftpboot/    
# 初始化鏡像檔案和核心檔案
cp -pr /var/www/html/cdrom/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/ 
# 建立菜單目錄
mkdir /var/lib/tftpboot/pxelinux.cfg/  
# 複制啟動菜單檔案
cp -pr /var/www/html/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default  
# 配置啟動菜單檔案
vim /var/lib/tftpboot/pxelinux.cfg/default
default linux                     #啟動菜單改為linux為了節省時間 
timeout 600					     #逾時時間

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Rocky Linux 8
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line
#64行預設  隻需要更改第一行和最後一行,ks就可以了。
label linux                            #圖形化安裝,自定義啟動選項
  menu label ^Install Rocky Linux 8    #啟動菜單名字
  kernel vmlinuz                       #加載核心
  append initrd=initrd.img ks=http://10.10.10.101/ks.cfg  quiet #加載初始化引導檔案和ks.cfg自動應答檔案  
           

DHCP

#複制dhcp配置檔案
cp  /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
vim /etc/dhcp/dhcpd.conf 
subnet 10.10.10.10.0 netmask 255.255.255.0 {        # 位址網段範圍和掩碼
  range 10.10.10.10 10.10.20.19;                    # 位址池
  option domain-name-servers skills.com;            # 域名
  option routers 10.10.10.254;                      # 路由位址就是官關
        filename        "pxelinux.0";  		       # 指定pxe引導程式檔案
        next-server     10.10.10.101;		       # 指定tfpt伺服器位址
}
           

權限

chmod 777 -R  /var/lib/tftpboot /var/www/html/ks.cfg 
           

防火牆放行

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=tftp
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload
setenforce 0								#臨時關閉selinux
           

重新開機服務

systemctl enable --now httpd tftp.socket xinetd dhcpd
systemctl restart httpd tftp.socket xinted dhcpd
           

測試:

記憶體選擇2G以上

繼續閱讀