Skip to content

Instantly share code, notes, and snippets.

@pixie79
Forked from ereli/gist:e868fcaeb660e420d7a6
Last active August 29, 2015 14:16
Show Gist options
  • Save pixie79/ed018a28e6574e193c1d to your computer and use it in GitHub Desktop.
Save pixie79/ed018a28e6574e193c1d to your computer and use it in GitHub Desktop.

Installing Centos using DHCP, TFTP and Kickstart Files.

We want to deploy physical nodes before cluster installation, in order to speed up the deployment, we'd like to automate most of the process, requiring us only to enter hostnames and IP address. we will need:

  • A DHCP Server
  • TFTP Server
  • HTTP Server
  • Centos ISO file
  • Optionally: local repo server, local dns server, local ntp server.

here is s the boot menu, !

default menu.c32
prompt 0
timeout 70
ONTIMEOUT local

menu title ########## PXE Boot Menu ##########

label 1
menu label ^1) Install CentOS 6 x84 64 Edition
kernel centos6_x86_64/images/pxeboot/vmlinuz
append initrd=centos6_x86_64/images/pxeboot/initrd.img method=http://192.168.2.254/centos6_x86_64 devfs=nomount ks=http://192.168.2.254/ks.cfg ksdevice=bootif

label 2
menu label ^2) Boot from local drive localboot

here's a template for a core kickstart file. it prompts for the IP adress, hostname, and GW. if you make changes, make sure you use. you can create such file be manually editing this template, or by using a GUI tool called system-config-kickstart.

If you manually edit the file, use a tool called ksvalidator, which is part of the package pykickstart to validate your file. source on github

#Generated by Kickstart Configurator + https://github.com/swisstxt/cloudstack-centos-kickstart-iso/blob/master/CentOS-6.6-x86_64-swisstxt.ks https://github.com/CentOS/Community-Kickstarts
#platform=x86_64 http://www.areyouroot.com/2014/02/red-hat-kickstart-prompting-for-input.html 

%pre
#change to tty6 to get input
chvt 6
exec </dev/tty6 > /dev/tty6

#Get hostname
echo "What is my hostname?"
read NAME

#Get IP
echo "What is my IP?"
read ADDR 

#Get Gateway
echo "What is the Gateway?"
read GW


#build /etc/sysconfig/network
echo "NETWORKING=yes" > network
echo "HOSTNAME=${NAME}" >> network
echo "GATEWAY=${GW}" >> network

#build /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DEVICE=eth0" > ifcfg-eth0
echo "BOOTPROTO=none" >> ifcfg-eth0
echo "IPV6INIT=no" >> ifcfg-eth0
echo "MTU=1500" >> ifcfg-eth0
echo "NM_CONTROLLED=no" >> ifcfg-eth0
echo "ONBOOT=yes" >> ifcfg-eth0
echo "TYPE=Ethernet" >> ifcfg-eth0
echo "IPADDR=${ADDR}" >> ifcfg-eth0
echo "NETMASK=255.255.255.0" >> ifcfg-eth0

#change back to tty1 and continue script
chvt 1
exec < /dev/tty1 > /dev/tty1
%end

#System language
lang en_US
#System keyboard
keyboard us
#System timezone
timezone --utc Europe/London
#Root password
rootpw --iscrypted $1$XKl0wY97$nGMXTZwNuQj8L7cL5Gx9g1
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use Web installation
url --url http://192.168.2.254/centos6_x86_64
#System bootloader configuration
bootloader --location=mbr 
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel 
#Disk partitioning information
part swap --recommended 
part / --fstype ext4 --size 1 --grow 
#System authorization infomation
auth  --useshadow  --enablemd5 
#Network information
#network --bootproto=static --ip=192.168.2.240 --netmask=255.255.255.0 --gateway=192.168.2.1 --nameserver=8.8.8.8 --device=eth0
#Firewall configuration
firewall --disabled --ssh 
#Do not configure the X Window System
skipx


%packages
@core
@server-policy
e4fsprogs
irqbalance
man-pages
mlocate.x86_64
openssh-clients.x86_64
vim-enhanced.x86_64
curl.x86_64
wget.x86_64
nano.x86_64
%end

%post --nochroot
/usr/sbin/ntpdate -sub europe.pool.ntp.org
chkconfig ntpd on

# bring in hostname collected from %pre
cp network /mnt/sysimage/etc/sysconfig/network
. /mnt/sysimage/etc/sysconfig/network
# force hostname change
/mnt/sysimage/bin/hostname $HOSTNAME

#copy prebuilt ifcfg-eth0 script to set IP
cp ifcfg-eth0 /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-eth0

%end

helpful links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment