PXE is “Preboot eXecution Environment”.
To construct PXE, you need construct tftp-server dhcp-server first.
If you have no bare metal system, you can use virt-install to install a vm through pxe, and you don’t need a dhcp server if do this.
# install tftp,dhcp,syslinux
yum install -y tftp-server dhcp-server syslinux
# setup dhcp-server
# if you use virt-install to install vm, dhcp is not required.
# 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 600;
max-lease-time 7200;
# 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;
class "class1" {
#match if substring(hardware, 1, 8) = "9e:d9:36";
match if binary-to-ascii(16,8,":",substring(hardware, 1, 3)) = "9e:d9:36";
}
subnet 172.20.0.0 netmask 255.255.0.0 {
allow members of "class1";
range 172.20.0.1 172.20.0.10;
next-server 172.20.0.254;
filename "pxelinux.0";
}
host veth1 {
hardware ethernet d6:c9:2b:3b:c5:15;
fixed-address 172.20.0.11;
next-server 172.20.0.254;
filename "pxelinux.0";
}
# setup tftp-server
# download isolinux files to tftpboot directory
[root@mlxsw-sn2100-01 dhcp]# cd /var/lib/tftpboot/
[root@mlxsw-sn2100-01 tftpboot]# ll
total 70176
-rw-r--r--. 1 root root 84 Nov 20 11:56 boot.msg
-rw-r--r--. 1 root root 325 Nov 20 11:56 grub.conf
-rw-r--r--. 1 root root 63026896 Nov 20 11:56 initrd.img
-rw-r--r--. 1 root root 38912 Nov 20 11:56 isolinux.bin
-rw-r--r--. 1 root root 3159 Nov 20 11:57 isolinux.cfg
-rw-r--r--. 1 root root 116096 Sep 25 09:18 ldlinux.c32
-rw-r--r--. 1 root root 180700 Sep 25 09:18 libcom32.c32
-rw-r--r--. 1 root root 22804 Sep 25 09:18 libutil.c32
-rw-r--r--. 1 root root 182704 Aug 12 2018 memtest
-rw-r--r--. 1 root root 42821 Dec 3 05:28 pxelinux.0
drwxr-xr-x. 2 root root 41 Dec 8 00:53 pxelinux.cfg
-rw-r--r--. 1 root root 186 Aug 16 09:30 splash.png
-rw-r--r--. 1 root root 26788 Sep 25 09:18 vesamenu.c32
-rw-r--r--. 1 root root 8188560 Nov 15 13:59 vmlinuz
# create pxelinux.cfg directory
# cp isolinux.cfg to pxelinux.cfg/default
[root@mlxsw-sn2100-01 tftpboot]# mkdir pxelinux.cfg/
[root@mlxsw-sn2100-01 tftpboot]# cp isolinux.cfg pxelinux.cfg/default
[root@mlxsw-sn2100-01 tftpboot]# ll pxelinux.cfg/
total 8
-rw-r--r--. 1 root root 3233 Dec 8 00:46 default
# set kernel image, initrd, kickstart file in pxelinux.cfg/default
kernel vmlinuz
append initrd=initrd.img console=ttyS0 ks=http://10.73.128.15/ks.cfg
# ks.cfg is provided by http server
[root@mlxsw-sn2100-01 tftpboot]# cd /var/www/html/
[root@mlxsw-sn2100-01 html]# cat ks.cfg
#url --url http://192.168.122.1:80/rhel8.iso
url --url http://download.eng.pek2.xxx.com//rhel-8/rel-eng/RHEL-8/RHEL-8.2.0-20191120.0/compose/BaseOS/x86_64/os/
reboot
rootpw --plaintext foobar
services --enabled="sshd,chronyd"
zerombr
clearpart --all
autopart --type lvm
%packages
@core
%end
#%post
#cat <<"EOF" > /etc/yum.repos.d/yum.repo
#[rhel8.2]
#name=rhel8.2
#baseurl=http://10.73.2.112/rhel-8/rel-eng/RHEL-8/RHEL-8.2.0-20191120.0/compose/BaseOS/x86_64/os/
#enabled=1
#baseurl=http://download.eng.pek2.xxx.com/rhel-8/rel-eng/RHEL-8/RHEL-8.2.0-20191120.0/compose/BaseOS/x86_64/os/
#gpgcheck=0
#EOF
#%end
# I have no bare metal system, so i use virt-install to install vm
# virsh net-destroy default
# virsh net-edit default
<network>
<name>default</name>
<uuid>356e5daf-3b06-49d5-98fd-178e847cf559</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:aa:da:73'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<tftp root='/var/lib/tftpboot'/>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
<bootp file='pxelinux.0'/>
</dhcp>
</ip>
</network>
# virt-install --pxe --network network=default --name pxe --memory 2048 --disk size=10 --nographics --boot menu=on,useserial=on
with virt-install, you even don’t need a tftp server, just use a http server, and put all relevant files into the http server. reference
PXE load pxelinux.0(bootloader) through dhcp server ->
bootloader get “initrd”,”kernel”,”ks file loaction” from config file(pxelinux.cfg/default) ->
bootloader load initrd ->
bootloader load kernel and pass ks file loaction to kernel cmdline ->
kernel start anaconda to begin a ks installation