Setup Net Boot / DHCP Server with IPXE boot enable

assume ip address of this server 10.10.4.22.

install dnsmasq and nginx package for enable ipxe boot

yum install dnsmasq.x86_64 nginx -y

configuration

config /etc/dnsmasq.conf

dhcp-range=10.10.4.100,10.10.4.200,30m
dhcp-option=3,10.10.4.1
dhcp-option=6,8.8.8.8

enable-tftp
tftp-root=/opt/tftp

# iPXE - chainload to matchbox ipxe boot script
dhcp-userclass=set:ipxe,iPXE
#1
dhcp-boot=centos6.ipxe
#2
#dhcp-boot=centos7.ipxe
#3
#dhcp-boot=coreos.ipxe

# verbose
log-queries
log-dhcp

create file centos6.ipxe at /opt/tftp for centos 6:

#!ipxe
set base-url http://10.10.4.22
kernel -n img ${base-url}/centos6/vmlinuz ks=${base-url}/centos6/kickstart.desktop
initrd ${base-url}/centos6/initrd.img
boot img

centos7.ipxe for centos 7:

#!ipxe
set base-url http://10.10.4.22
kernel -n img ${base-url}/centos7/vmlinuz ks=${base-url}/centos7/ks7.desktop
initrd ${base-url}/centos7/initrd.img
boot img

coreos.ipxe for core os:

#!ipxe
set base-url http://10.10.4.22
kernel ${base-url}/coreos/coreos_production_pxe.vmlinuz initrd=coreos_production_pxe_image.cpio.gz rootfstype=btrfs console=tty0 console=ttyS0 coreos.autologin=tty1 coreos.autologin=ttyS0 coreos.first_boot=1 coreos.config.url=http://10.10.4.22/coreos/preconf.ign
initrd ${base-url}/coreos/coreos_production_pxe_image.cpio.gz
boot

mkdir centos6,centos7,coreos for repositories file:

mkdir -p /var/www/html/{centos6,centos7,coreos}

Requierements

Download requiered files for kernel and initrd:

for centos 6:

cd /var/www/html/centos6/
wget -c "http://mirror.centos.org/centos/6.9/os/x86_64/images/pxeboot/vmlinuz"
wget -c "http://mirror.centos.org/centos/6.9/os/x86_64/images/pxeboot/initrd.img"

for centos 7:

cd /var/www/html/centos7/
wget -c "http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/vmlinuz"
wget -c "http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/initrd.img"

for core os:

cd /var/www/html/coreos/
wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe.vmlinuz
wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_pxe_image.cpio.gz

Kickstart

create Kickstart files:

for centos 6 (no gui):

text
skipx
install

url --url http://mirror.cogentco.com/pub/linux/centos/6.9/os/x86_64/
repo --name=epel --baseurl=http://download.fedoraproject.org/pub/epel/6/x86_64/
repo --name=updates --baseurl=http://mirror.cogentco.com/pub/linux/centos/6.9/updates/x86_64/

lang en_US.UTF-8
keyboard us
rootpw 123456
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Jakarta
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype ext4 --fsoptions="noatime" --size=200
part pv.1 --size 1 --grow
volgroup vg0 --pesize=4096 pv.1
logvol / --fstype ext4 --fsoptions="noatime" --name=root --vgname=vg0 --size=8192
logvol swap --fstype swap --name=swap --vgname=vg0 --size 2048
logvol /var --fstype ext4 --fsoptions="noatime,nodev" --name=var --vgname=vg0 --size=4096
logvol /home --fstype ext4 --fsoptions="noatime,nodev" --name=home --vgname=vg0 --size=2048

services --enabled=network,ntpd,ntpdate

reboot
%packages --nobase
epel-release
openssh-clients
openssh-server
yum
at
acpid
vixie-cron
cronie-noanacron
crontabs
logrotate
ntp
ntpdate
tmpwatch
rsync
which
wget
curl
%end

for centos 6 kickstart.desktop (with gui):

text
skipx
install

# Use NFS installation media
##nfs --server=172.16.240.50 --dir=/work/admin/boot/centos6.5/

#url --url http://mirror.centos.org/centos/6.9/os/x86_64/
#repo --name=epel --baseurl=http://download.fedoraproject.org/pub/epel/6/x86_64/
#repo --name=updates --baseurl=http://mirror.centos.org/centos/6.9/updates/x86_64/

url --url http://10.10.4.22/centos-mirror/6.9/os/x86_64/
repo --name=epel --baseurl=http://10.10.4.22/epel-mirror/6/x86_64/
repo --name=updates --baseurl=http://10.10.4.22/centos-mirror/6.9/updates/x86_64/

lang en_US.UTF-8
keyboard us
rootpw F5d9k2lg6
user --name=asd --password=1231213
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Jakarta
bootloader --location=mbr
zerombr
clearpart --all --initlabel
autopart


#part /boot --fstype ext4 --fsoptions="noatime" --size=200
#part pv.1 --size 1 --grow
#volgroup vg0 --pesize=4096 pv.1
#logvol / --fstype ext4 --fsoptions="noatime" --name=root --vgname=vg0 --size=0
#logvol swap --fstype swap --name=swap --vgname=vg0 --size 2048
#logvol /var --fstype ext4 --fsoptions="noatime,nodev" --name=var --vgname=vg0 --size=4096

xconfig --startxonboot
services --enabled=network,ntpd,ntpdate

reboot

%packages                                                                                                                                  
@base                                                                                                                                      
@core                                                                                                                                       
@basic-desktop                                                                                                                              
@desktop-platform    
@fonts
@general-desktop
@internet-browser
@legacy-x
@network-file-system-client
@perl-runtime
@print-client
@remote-desktop-clients
@x11
device-mapper-persistent-data
systemtap-client
jpackage-utils
xorg-x11-xdm
libXmu
perl-DBD-SQLite
rdesktop
compat-libstdc++-33
epel-release
openssh-clients
openssh-server
yum
at
acpid
vixie-cron
cronie-noanacron
crontabs
logrotate
ntp
ntpdate
tmpwatch
rsync
which
wget
curl
%end

%post
chmod a+x /etc/rc.d/rc.local

echo '
if ! (which catalina.sh > /dev/null 2>&1); then


##install java
export JAVA_HOME=/opt/java
export JRE_HOME=$JAVA_HOME/jre
mkdir -p $JAVA_HOME
cd $JAVA_HOME
wget -c "http://ftp.heanet.ie/mirrors/funtoo/distfiles/oracle-java/jdk-7u80-linux-x64.tar.gz" -O jdk.tar.gz
tar -xvf jdk.tar.gz --strip-components=1
alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 2
alternatives --install /usr/bin/jar jar $JAVA_HOME/bin/jar 2
alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 2
alternatives --set jar $JAVA_HOME/bin/jar
alternatives --set javac $JAVA_HOME/bin/javac
alternatives --set java $JAVA_HOME/bin/java

        export CATALINA_HOME=/opt/tomcat
        export PATH=$CATALINA_HOME/bin:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

        mkdir -p "$CATALINA_HOME"
        cd $CATALINA_HOME

        export TOMCAT_MAJOR=7
        export TOMCAT_VERSION=7.0.84
        export TOMCAT_TGZ_URL=https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz

        curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz
        tar -xvf tomcat.tar.gz --strip-components=1
        $CATALINA_HOME/bin/catalina.sh start
fi' >> /etc/rc.d/rc.local
echo '
export JAVA_HOME=/opt/java
export JRE_HOME=$JAVA_HOME/jre
export CATALINA_HOME=/opt/tomcat

export PATH=$CATALINA_HOME/bin:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH


' >> /etc/profile


%end

for centos 7 (no gui):

install
lang en_GB.UTF-8
keyboard us
timezone Asia/Jakarta
auth --useshadow --enablemd5
selinux --disabled
firewall --disabled
services --enabled=NetworkManager,sshd
eula --agreed
ignoredisk --only-use=sda
reboot

bootloader --location=mbr
zerombr
clearpart --all --initlabel
autopart
#part swap --asprimary --fstype="swap" --size=1024
#part /boot --fstype xfs --size=200
#part pv.01 --size=1 --grow
#volgroup rootvg01 pv.01
#logvol / --fstype ext4 --name=lv01 --vgname=rootvg01 --size=1 --grow

rootpw 123456

repo --name=base --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/
url --url="http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/"

#url --url http://mirror.centos.org/centos/7/os/x86_64/
#repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/
repo --name=epel --baseurl=http://download.fedoraproject.org/pub/epel/7/x86_64/
repo --name=updates --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/updates/x86_64/

%packages --nobase --ignoremissing
@core
epel-release
openssh-clients
openssh-server
yum
at
cronie-noanacron
crontabs
logrotate
ntp
ntpdate
tmpwatch
rsync
which
wget
curl
%end

for centos 7 ks7.desktop (with gui + docker + symmetricDS):

install
lang en_GB.UTF-8
keyboard us
timezone Asia/Jakarta
auth --useshadow --enablemd5
selinux --disabled   
firewall --disabled  
services --enabled=NetworkManager,sshd
#services --disabled=initial-setup-text
#initial-setup-text --disabled
firstboot --disable  
eula --agreed
ignoredisk --only-use=sda
reboot

xconfig  --startxonboot
bootloader --location=mbr
zerombr
clearpart --all --initlabel
autopart
#part swap --asprimary --fstype="swap" --size=1024
##part /boot --fstype ext4 --size=200
#part pv.01 --size=1 --grow
#volgroup rootvg01 pv.01
#logvol / --fstype ext4 --name=lv01 --vgname=rootvg01 --size=1 --grow

rootpw 123456
user --name=asd --password=123123

repo --name=base --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/
url --url="http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/"

#url --url http://mirror.centos.org/centos/7/os/x86_64/
#repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/
repo --name=epel --baseurl=http://download.fedoraproject.org/pub/epel/7/x86_64/
repo --name=updates --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/updates/x86_64/


%packages
@^graphical-server-environment
@base
@core
@desktop-debugging   
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@multimedia
@print-client
@x11
chrony
kexec-tools

%end

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

%end

%post

systemctl disable initial-setup-graphical.service
chmod a+x /etc/rc.d/rc.local

echo '
if ! (which docker > /dev/null 2>&1); then

        curl "https://gitlab.com/symmetric-ds.tar" > /opt/symmetric-ds.tar
        cd /opt/;tar -xvf symmetric-ds.tar;
        mkdir -p /opt/webapps/jspapps;
        echo "jspapps put here" >> /opt/webapps/jspapps/index.jsp;
        curl "http://url/install-docker-centos7.sh" > /usr/src/install-docker.sh
        /bin/bash -x /usr/src/install-docker.sh 2>&1 | tee /usr/src/debug-install.log
fi
' >> /etc/rc.d/rc.local

%end

for core os preconf.ign (with tomcat container):

{
  "ignition": {
    "config": {},
    "timeouts": {},
    "version": "2.1.0"
  },
  "networkd": {},
  "passwd": {},
  "storage": {
    "disks": [
      {
        "device": "/dev/sda",
        "partitions": [
          {
            "label": "ROOT"
          }
        ],
        "wipeTable": true
      }
    ],
    "filesystems": [
      {
        "mount": {
          "device": "/dev/disk/by-partlabel/ROOT",
          "format": "ext4",
          "label": "ROOT",
          "wipeFilesystem": true
        }
      }
    ],
    "files": [
      {
        "filesystem": "root",
        "path": "/opt/installer",
        "mode": 755,
        "contents": {
          "source": "http://10.10.4.22/coreos/installer.sh"
        }
      },
      {
        "filesystem": "root",
        "path": "/etc/hostname",
        "mode": 420,
        "contents": {
          "source": "data:,installer"
        }
      }
    ]
  },
  "systemd": {
    "units": [
      {
        "name": "installer.service",
        "enabled": true,
        "contents": "[Unit]\nRequires=network-online.target\nAfter=network-online.target\n[Service]\nType=simple\nExecStart=/opt/installer\n[Install]\nWantedBy=multi-user.target"
      }
    ]
  }
}

put installer.sh to /var/www/coreos/:

#!/bin/bash -ex

#curl --retry 10 --fail "{{.ignition_endpoint}}?{{.request.raw_query}}&os=installed" -o ignition.json

curl http://10.10.4.22/coreos/install.ign -o /tmp/install.ign
coreos-install -d /dev/sda -C stable -i /tmp/install.ign
#{{.coreos_channel}} -V {{.coreos_version}} -i ignition.json {{if index . "baseurl"}}-b {{.baseurl}}{{end}}
udevadm settle
systemctl reboot

put install.ign to /var/www/coreos/:

{
  "ignition": {
    "config": {},
    "timeouts": {},
    "version": "2.1.0"
  },
  "networkd": {},
  "passwd": {
    "users": [
      {
        "groups": [
          "sudo",
          "docker"
        ],
        "name": "asd",
        "passwordHash": "$6$pk78SVN.I$veAoRIG9GZkstvrVLY0aIRAvOoqOqz3r4YZdZoQ5aZTFD2jrDlF1.GCzLuU.h274MyYmu1KFnuss51SPARMQv."
      }
    ]
  },
  "storage": {
    "files": [
      {
        "filesystem": "root",
        "path": "/etc/hostname",
        "mode": 420,
        "contents": {
          "source": "data:,coreos-asd"
        }
      },
        {
        "filesystem": "root",
        "path": "/opt/tomcat-install",
        "mode": 755,
        "contents": {
          "source": "http://10.10.4.22/coreos/tomcat-install.sh"
         }
        }
    ]
  },
  "systemd": {    "units": [
  {
    "name": "tomcat-install.service",
    "enabled": true,
    "contents": "[Unit]\nRequires=network-online.target\nAfter=network-online.target\n[Service]\nType=simple\nExecStart=/opt/tomcat-install\n[Install]\nWantedBy=multi-user.target"
  }
]}
}

put tomcat-install.sh to /var/www/html/coreos/:

#!/bin/bash

docker run -id --rm -p 8888:8080 tomcat:7

start dnsmasq for turn on dhcp services plus ipxe:

/etc/init.d/dnsmasq start

Done

and try boot with ipxe.

photo6296124071561242608