Saturday, 28 April 2012

How To Build a PXE Server

So you've created some kickstart files (here) now wouldn't it be nice to have the client net boot and the installation served up over the network to create a fully automated build.

This is how to be a build a PXE server on RHEL 6. I'm assuming the server has been setup for anonymous FTP to serve out the install media from /pub/inst and the kickstart files from /pub/ks. You could also use HTTP.

Install packages tftp-server & dhcp.

Enable TFTP server in /etc/xinetd.d/tftp
disable=no
And turn it on
service xinetd start

chkconfig xinetd on

Configure a DHCP subnet in /etc/dhcp/dhcpd.conf
( PXE specific stuff in red; next-server is the PXE server)

# Global Options
Allow booting;
Allow bootp;
authoritative;
# Subnet definition
subnet 192.168.122.0 netmask 255.255.255.0 {
option routers 192.168.122.2;
option subnet-mask 255.255.255.0;
option domain-name “example.com”;
option domain-name-servers 192.168.122.2;
default-lease-time 21600;
max-lease-time 43200;
range dynamic-bootp 192.168.122.100 192.168.122.200;
filename “pxelinux.0”;
next-server 192.168.122.2;

}
And turn it on
service dhcpd start

chkconfig dhcpd on 

Create TFTP directories and copy files
mkdir /var/lib/tftpboot/rhel6
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/ftp/pub/inst/images/pxeboot/vmlinuz /var/lib/tftpboot/rhel6
cp /var/ftp/pub/inst/images/pxeboot/initrd.img /var/lib/tftpboot/rhel6
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/

We'll create a default client config file which is served to everyone. You can make client specific ones and place them in the same directory.
Create /var/lib/tftpbook/pxelinux.cfg/default

timeout 100
default menu.c32
menu title Boot Menu
label 1
   menu label ^ 1) Boot next available boot device
   localboot
label 2
   menu label ^ 2) RHEL 6 (with kickstart)
   kernel rhel6/vmlinuz
   append initrd=rhel6/initrd.img ks=ftp://192.168.122.2/pub/ks/server1.cfg
label 3
   menu label ^ 3) RHEL 6 (interactive)
   kernel rhel6/vmlinuz
   append initrd=rhel6/initrd.img ip=dhcp repo=ftp://192.168.122.2/pub/inst

By placing localboot as the first option we avoid an accidental build if the first boot device is set to network as we default to booting the next available device.
Option 2 is an example of a fully automated install with a kickstart file
Option 3 will deliver an interactive installation
If it's all working you'll see something like this from a PXE booting client.

No comments:

Post a Comment