Tuesday, September 18, 2012

Configure PXE install server on RHEL 6



Red Hat Enterprise Linux Server 6.2
How to configure PXE boot install server

The idea for the below set up, is to set up a PXE boot install server in a virtual environment. Additional virtual machines will boot immediately to the network and begin installation, therefore, some parts of this configuration may not be safe in a production environment.

Following the configuration will be an example bash script for deploying a KVM based virtual machine, which will then auto-install from the configured server.

First edit your networking configuration file.
vi /etc/sysconfig/network-scripts/ifcfg-eth0

Change ONBOOT="no" to ONBOOT="yes", then add ip address and subnet mask:
IPADDR="192.168.101.2"
NETMASK="255.255.255.0"

Save changes and restart network: service network restart

If the RHEL 6.2 installation disk is not mounted, ensure that it is
mount -t iso9660 /dev/sr0 /media
cp /media/media.repo /etc/yum.repos.d/
vi /etc/yum.repos.d/media.repo

Add the following lines to the file:

baseurl=file:///media/Server
enabled=1
Save changes and clean yum metadata
yum clean metadata

Install vsftp server:
yum install vsftpd
vi /etc/sysconfig/iptables-config
Change line IPTABLES_MODULES="", to read IPTABLES_MODULES="ip_conntrack_ftp"
vi /etc/syconfig/iptables
Add line -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
service iptables restart
chkconfig vsftpd on
service vsftpd start
mkdir /var/ftp/inst
cp /root/anaconda-ks.cfg /var/ftp/put/ks.cfg
chmod 755 /var/ftp/pub/ks.cfg
cp -var /media/. /var/ftp/inst/
chcon -R -t public_content_t /var/ftp/inst/
Change line in /etc/yum.repos.d from "basurl=file:///media/Server"
to "basurl=file:///var/ftp/inst/Server"
yum clean metadata
yum install dhcp
chkconfig dhcpd on
vi /etc/dhcp/dhcpd.conf
(This file will be mostly empty save a few comments - Sample config is below)
=================================================
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
subnet 192.168.101.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.101.127 192.168.101.254;
range 192.168.101.3 192.168.101.126;
option routers 192.168.101.2;
default-lease-time 6000;
max-lease-time 7200;
allow booting;
allow bootp;
class "pxeclients" {
match if substring(option vendor-class-identifier, 0,9) = "PXEClient";
next-server 192.168.101.2;
filename "pxelinux.0";
}
}
=================================================

service dhcpd start

Install and configure TFTP server
yum install tftp-server syslinux
vi /etc/sysconfig/iptables-config

Change line IPTABLES_MODULES="ip_conntrack_ftp", to readIPTABLES_MODULES="ip_conntrack_ftp ip_conntrac_tftp"
Add the following lines to /etc/sysconfig/iptables below the SSH entry
-A INPUT -m state --state NEW -m tcp -p tcp --dport 69 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT

Then:
chkconfig xinetd on
service xinetd start
chkconfig tftp on
service xinetd restart
mkdir /var/lib/tftpboot/rhel62
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /var/ftp/inst/images/pxeboot/* /var/lib/tftpboot/rhel62
touch /var/lib/tftpboot/pxelinux.cfg/default
vi /var/lib/tftpboot/pxelinux.cfg/default




Sample default file (Warning: clients are configured to autoInstall on PXE boot)
=================================================
timeout 3
default rhel62
label rhel62
kernel rhel62/vmlinuz
append initrd=rhel62/initrd.img noipv6 ks=ftp://192.168.101.2/pub/ks.cfg
=================================================
Modify /var/ftp/pub/ks.cfg
Sample file:
=================================================
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url ftp://192.168.101.2/inst
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp
rootpw --iscrypted $6$inQ.MXCTSuz356Ea$/7iq.74tyJSBU4uXagrJjtRGEk1OFGTNCgLttdMsJdstJgOPkBMWVfkyL/.Reaa2Bsu06.0aB8sa.sC3MTkUy0
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc America/North_Dakota/Center
bootloader --location=mbr --driveorder=vda --append=" rhgb crashkernel=auto quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
zerombr
part /boot --fstype=ext4 --size=500
part pv.253002 --grow --size=1

clearpart --all --drives=sda
volgroup VolGroup --pesize=4096 pv.253002
logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=VolGroup --grow --size=512 --maxsize=1024

#repo --name="Red Hat Enterprise Linux" --baseurl=cdrom:sr0 --cost=100

%packages --nobase
@core
%post
cat >/etc/yum.repos.d/media.repo <<EOF
[InstallMedia]
name=Red Hat Server Linux 6.2
baseurl=ftp://192.168.101.2/inst/Server
mediaid=1321544350.537856
enabled=1
gpgcheck=0
cost=500
EOF
%end
=================================================

Sample script for KVM virtual machine creation:

#!/bin/bash
VIRTNAME=$1

if [ -z "$VIRTNAME" ]; then
echo "No hostname was provided"
else
virt-install -n $VIRTNAME -r 512 --disk path=/var/lib/libvirt/images/$VIRTNAME,size=12 -w network=local --pxe --os-type=linux
fi

0 comments: