Kickstart and PXELinux
Friday, December 22nd, 2006As part of a vertical consolidation and virtualization project, I had set up a Kickstart configuration in order to boot x86 servers and install the VMWare ESX Server software. While I wrote this document specifically for ESX installations, the underlying OS was a modified Redhat 7.x distro (or something that seemed awfully similar). So here are the steps to implement and use a PXEBooting Kickstart environment.
Prerequisites
- Linux server (can use a manually built ESX server for this purpose) with dhcpd (dhcp daemon), tftpd (tftp daemon) and nfs server services turned on.
- Have the dump of the ESX installation media CD in a directory/filesystem large enough to hold it.
mkdir –p /images/install
cp –pra /mnt/* /images/install
umount /mnt
cd /images/ install/images
mount –o loop ./bootnet.img /mnt
cd /mnt
mkdir –p /tftpboot/pxelinux.cfg
cp boot.msg initrd.img syslinux.cfg vmlinuz /tftpboot
cd /tftpboot
umount /mnt
cp syslinux.cfg pxelinux.cfg/default
Details
- Having copied these files over, now make a copy of the /tftpboot/pxelinux.cfg/default to /tftpboot/pxelinux.cfg/bootnet
- Edit /tftpboot/pxelinux.cfg/bootnet to make it look like this:
default ks
prompt 0
timeout 0
display boot.msg
F1 boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label ks
kernel vmlinuz
append apic ks=nfs:10.165.214.160:/vmimages/kickstart/ks.cfg ramdisk_size=10240 initrd=initrd.img
- Get a copy of the “syslinux” distribution (run the commands listed below):
http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.07.tar.gz
Explode the tarball like this:
# cp syslinux-3.07.tar.gz /tmp
# tar zxvf /tmp/syslinux-3.07.tar.gz
# cd /tmp/syslinux-3.07
# cp syslinux.0 /tftpboot
- Edit the dhcp configuration file like this:
# vi /etc/dhcpd.conf
# ddns-update-style none;
ignore client-updates;
allow bootp;
allow booting;
option ip-forwarding false;
option mask-supplier false;
get-lease-hostnames off;
use-host-decl-names off;
option routers 10.165.214.1;
subnet 10.165.214.0 netmask 255.255.255.0 {
default-lease-time 1800;
max-lease-time 3600;
option subnet-mask 255.255.255.0;
}
host hostA {
hardware ethernet 00:AA:BB:CC:DD:EE;
fixed-address 10.165.214.164;
#option option-214 “0AA5D6A4″;
#next-server 10.165.214.160;
filename “/tftpboot/pxelinux.0″;
}
NOTE: Choose the correct subnet (that your servers will reside in).
- Make sure that the tftpd daemon is installed and edit the file /etc/xinetd.d/tftp to look like this:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = /tftpboot
disable = no
per_source = 11
cps = 100 2
}
- It is to be noted that the default ESX server install comes with gcc (2.96) and make (GNU Make version 3.79.1). But the tftp daemon and the dhcp daemon (server-side) aren’t installed by default.
- Download the latest versions of the dhcp sources (can obtain the software by following instructions at this url: http://www.isc.org/index.pl?/sw/dhcp/) and build it by following the instructions in the README file or INSTALL file of the distribution (usually it is a standard method of ./configure; make; make install)
- Similarly, obtain a copy of the latest tftp source from (ftp://ftp.kernel.org/pub/software/network/tftp/). Following the build instructions will result in the installation of the tftpd binary on the system.
- Start the dhcp daemon by running:
dhcpd -cf /etc/dhcpd.conf
- Start the tftp daemon by sending a SIGHUP to the xinetd daemon
kill -HUP `ps -ef|grep xinetd|grep -v grep|awk ‘{print $2}’`
- The NFS server services need to be started up after creating the appropriate NFS shares in /etc/exports. The contents of the /etc/exports file should look like this:
#
/vmimages/install *(ro,no_root_squash)
/vmimages/kickstart *(ro,no_root_squash)
/tftpboot *(ro,no_root_squash)
- Start NFS services by running the following commands:
# cd /etc/rc.d/init.d
# ./portmap start
# ./nfs start
# ./nfslock start
- After ensuring that the target ESX server (hardware) is plugged into the right subnet, boot the server and choose the PXE boot option. The booting from the PXE Ethernet ROM happens like this:
- Server boots and the PXE ROM loads, tries to acquire an IP address from the DHCP server (bootp).
- Once the IP address is obtained, the pxelinux.0 binary loads and obtains the vmlinuz kernel image via tftp.
- The initial ramdisk image (initrd, also acquired via tftp) is loaded into memory (to create the root filesystem in RAM).
- The kickstart configuration (ks.cfg) is acquired via NFS and used by the installer to do the “hands-free” installation.
Using the ks-config.pl script
use File::Copy; use Getopt::Std; my %Args;
my $dhcp_config = “/etc/dhcpd.conf”;
my $null = “/dev/null”;
my $tftpdir = “/tftpboot”;
my $pxedir = “$tftpdir/pxelinux.cfg”;
my $netboot_cfg = “$pxedir/netboot.1″;
#**************
# Main
#**************
getopts( “m:s:i:h”, \%Args );
if ($Args{h}) {
printUsage() && exit 0;
}
$mac = $Args{m} || printUsage() && die “Unable to continue without a mac address \n”; $hostname = $Args{s} || printUsage() && die “Unable to continue without a server name \n”;
$ip = $Args{i} || printUsage() && die “Unable to continue without an IP address \n”;
copy(”$dhcp_config”, “$dhcp_config.$$”) or die “Unable to backup $dhcp_config: $! n”;
open(DHCP, “>> $dhcp_config”) or die “Unable to write to $dhcp_config : $! \n”; print DHCP “\n”;
print DHCP “host $hostname\{ \n”;
print DHCP “hardware ethernet $mac; \n”;
print DHCP “fixed-address $ip; \n”;
print DHCP “filename \”$tftpdir/pxelinux.0\”; \n”;
print DHCP “\} \n”;
close(DHCP);
print “Killing dhcp daemon…\n”;
system(”/usr/bin/pkill dhcpd”);
print “Starting dhcp daemon….\n”;
$start_cmd = “/usr/sbin/dhcpd -cf $dhcp_config”;
system(”$start_cmd”);
sub printUsage {
print “Correct Usage: $0 -m \”
Using the script (modify to your heart’s content) , one could set up the dhcpd entries (knowing well that our friendly vi editor isn’t necessarily the most user-friendly (especially to the UNIX un-initiates..)) rather quickly/easily.
Here’s how:
# chmod +x ks-config.pl
# ./ks-config.pl –m “11:22:33:44:55:66” –s buildserver01 –i “10.165.214.55”
Would set up entries in dhcpd.conf like this:
[root@ksserver bin]# ./ks-config.pl -m “11:22:33:44:55:66″ -s buildserver01 > -i “10.165.214.55″
Killing dhcp daemon…
Starting dhcp daemon….
Internet Systems Consortium DHCP Server V3.0.1
Copyright 2004 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 0 leases to leases file.
Listening on LPF/eth0/00:11:0a:53:e8:98/10.165.214.0/24
Sending on LPF/eth0/00:11:0a:53:e8:98/10.165.214.0/24
Sending on Socket/fallback/fallback-net
Take a look at the /etc/dhcpd.conf file later:
[root@ksserver bin]# tail /etc/dhcpd.conf
hardware ethernet 00:11:AA:BB:CC:DD;
fixed-address 10.165.214.174;
filename “/tftpboot/pxelinux.0″;
}
host buildserver01{
hardware ethernet 11:22:33:44:55:66;
fixed-address 10.165.214.55;
filename “/tftpboot/pxelinux.0″;
}