Why?


Search This Blog

Sunday, July 31, 2016

Centos 7 setup PXE kickstart dhcpd tftpd httpd Server

Centos 7 setup PXE kickstart dhcpd tftpd httpd Server

First install Centos 7 minimal install CentOS-7-x86_64-Minimal-1511.iso.

I am using IP=10.10.10.20/24 gateway=10.10.10.254 DNS=192.168.10.10 for my server setup.

Disable selinux.

vi /etc/sysconfig/selinux

selinux=disabled


reboot

Login.

systemctl disable firewalld
systemctl stop firewalld

yum -y update

reboot


Login.

Create text file of /root/list with package list below in it.
Do not include the --begin list or the --end list lines in the file.

vi /root/list

--begin list   
bind-utils
traceroute
net-tools
ntp*
gcc
glibc
glibc-common
gd
gd-devel
make
net-snmp
openssl-devel
xinetd
unzip
libtool*
make
patch
perl
bison
flex-devel
gcc-c++
ncurses-devel
flex
libtermcap-devel
autoconf*
automake*
autoconf
libxml2-devel
cmake
sqlite*
wget
ntp*
lm_sensors
ncurses-devel
qt-devel
hmaccalc
zlib-devel
binutils-devel
elfutils-libelf-devel
wget
bc
gzip
uuid*
libuuid-devel
jansson*
libxml2*
sqlite*
openssl*
lsof
NetworkManager-tui
mlocate
yum-utils
kernel-devel
nfs-utils
tcpdump

--end list

yum -y install $(cat /root/list)

yum -y groupinstall "Development Tools"

yum -y update

reboot


Login.

Install reguired packes for PXE kickstart dhcpd tftpd httpd Server.

yum -y install dhcp tftp-server tftp syslinux httpd

Create your dhcpd.conf file.
Im using 10.10.10.20/24 for my PXE kickstart dhcpd tftpd httpd server.
Do not include the ---copy txt below or the ---end copy txt below lines in the file.

vi /etc/dhcp/dhcpd.conf

---copy txt below
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server 10.10.10.20;
filename "/pxelinux.0";

# specify domain name
option domain-name "whittenberg.domain";

# specify name server's hostname or IP address
option domain-name-servers 192.168.10.1;

# default lease time
default-lease-time 600;

# max lease time
max-lease-time 7200;

# this DHCP server to be declared valid
authoritative;

# specify network address and subnet mask
subnet 10.10.10.0 netmask 255.255.255.0 {
    # specify the range of lease IP address

    range dynamic-bootp 10.10.10.100 10.10.10.200;
    # specify broadcast address

    option broadcast-address 10.10.10.255;
    # specify default gateway

    option routers 10.10.10.254;
}

---end copy txt below

Start the service and check status.

systemctl enable dhcpd
systemctl start dhcpd
systemctl status dhcpd



You should now be able to PXE boot a machine and get an IP for this.
Just an IP though. Now we have to set it up to boot and install the ISO.

Setup PXE Server tftp-server.

mkdir -p /tftpboot
chmod 777 /tftpboot


vi /etc/xinetd.d/tftp and change to

server_args             = -s /tftpboot
disable                 = no


Start your tftp-server and check status.

systemctl enable xinetd.service
systemctl start xinetd.service
systemctl status xinetd.service


Copy syslinux files to tftp-server root directory of /tftpboot.

cp -v /usr/share/syslinux/pxelinux.0 /tftpboot
cp -v /usr/share/syslinux/menu.c32 /tftpboot
cp -v /usr/share/syslinux/memdisk /tftpboot
cp -v /usr/share/syslinux/mboot.c32 /tftpboot
cp -v /usr/share/syslinux/chain.c32 /tftpboot


Verify files are there.

ls -lsa /tftpboot

Start and check your httpd service.

systemctl enable httpd
systemctl start httpd
systemctl status httpd


FTP the Centos 7 CentOS-7-x86_64-Minimal-1511.iso to /root

mkdir /var/www/html/CentOS-7-x86_64-Minimal-1511

mount /root/CentOS-7-x86_64-Minimal-1511.iso /var/www/html/CentOS-7-x86_64-Minimal-1511


Verify files are there.

ls -lsa /var/www/html/CentOS-7-x86_64-Minimal-1511

Make netboot directory and place boot files in it.

mkdir -p /tftpboot/netboot/
cp /var/www/html/CentOS-7-x86_64-Minimal-1511/images/pxeboot/vmlinuz /tftpboot/netboot/
cp /var/www/html/CentOS-7-x86_64-Minimal-1511/images/pxeboot/initrd.img /tftpboot/netboot/


Verify files are there.

ls -lsa /tftpboot/netboot/

Now create the kickstart cfg file in the /var/www/html/ directory.

vi /var/www/html/ks.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use NFS installation media
url --url="http://10.10.10.20/CentOS-7-x86_64-Minimal-1511/"
# Root password [i used here 000000]
rootpw 000000
# Reboot after installation
reboot
# System authorization information
auth  useshadow  passalgo=sha512
# Use graphical install
graphical
firstboot disabled
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux disabled
# Installation logging level
logging level=info
# System timezone
timezone America/Phoenix
# System bootloader configuration
bootloader location=mbr
clearpart --all --initlabel
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 xfs --name=lv01 --vgname=rootvg01 --size=1 --grow

%packages
@core
%end
%post
%end


Now create directory for our PXE menu and create menu.

mkdir /tftpboot/pxelinux.cfg

vi /tftpboot/pxelinux.cfg/default

default menu.c32
prompt 5
timeout 20
MENU TITLE CentOS-7-x86_64-Minimal-1511 PXE Menu

LABEL CentOS-7-x86_64-Minimal-1511
MENU LABEL CentOS-7-x86_64-Minimal-1511
KERNEL /netboot/vmlinuz
APPEND  initrd=/netboot/initrd.img  inst.repo=http://10.10.10.20/CentOS-7-x86_64-Minimal-1511/ ks=http://10.10.10.20/ks.cfg


I now reboot for grins :) and after backup remount the ISO.

mount /root/CentOS-7-x86_64-Minimal-1511.iso /var/www/html/CentOS-7-x86_64-Minimal-1511

Or add this to your  /etc/fstap file. Be sure and not leave any extra lines/spaces after the entry.

/root/CentOS-7-x86_64-Minimal-1511.iso /var/www/html/CentOS-7-x86_64-Minimal-1511 iso9660 loop,ro,auto 0 0

You can test your fstab file with.

mount -a

That's it. You can change hostname, password, and use static IP, add additonal packages, etc. after its rebooted.



1 comment: