My posts about issues concerning Linux OS and network administration

Automatic server installation via PXE (examples from Centos) – Part 1

In this post I would like to share with you the way I am doing automatic server installation within different network subnets. I mean everybody install server at least once from CD/DVD which is the most common way. This is the easy way when you have just few servers to manage (maybe they woudn’t even be from the same vendor so every such installation is be very unique). In this case any effort to build up some automatic installation process woudn’t be the right way to go.

But this should be the right way whenever more servers in the same HW configuration are considered to be installed. And it is very probable that each server will be configured the very same way as the previous one including disk space layout etc..

There are of course lots of projects that can be used to duplicate or clone (also virtualization could be mentioned at this point) server installations etc..but this is not the topic. I would like to present automatic PXE network installation of RHEL/Centos server the way I am successfully using it and which became my “best practice”. This solution is also very flexible and I am using it to install different servers in different subnets including production servers as well as virtual servers for developers.

Whole concept is based on PXE server which can then serve an installation menu to server booting from network card. From this menu you can select things concerning server hostname, domain and such and the rest of installation process is fully automatic. To manage this you will need a server which will provide PXE menu thru TFTP and configuration templates to perform automatic Centos installation. I’d also recommend to setup own mirror of Centos base/update repositories as automatic installation will be much faster when installing from local network.

Let’s assume you already have a server prepared and configured as 192.168.1.254 which can be further configured as PXE server.

To configure your own “admin” server you’ll need to install tftp-server and syslinux packages. TFTP will create a directory /tftp where you copy few files from syslinux package:


cp /usr/lib/syslinux/pxelinux.0 /tftpboot
cp /usr/lib/syslinux/menu.c32 /tftpboot
cp /usr/lib/syslinux/memdisk /tftpboot
cp /usr/lib/syslinux/mboot.c32 /tftpboot
cp /usr/lib/syslinux/chain.c32 /tftpboot

You’ll also need to install dhcp server package and configure DHCP server to make PXE work. /etc/dhcpd.conf should look like this:

authoritative;
ddns-update-style none;
subnet 192.168.1.0 netmask 255.255.255.0
{

range 192.168.1.100 192.168.1.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name-servers 192.168.1.254;
option routers 192.168.1.254;
next-server 192.168.1.254;
filename “/pxelinux.0”;

}

let’s say you also have another subnet for testing servers (at this point no matter if on different interface or configured as VLAN) beside 192.168.1.0/24. So put it to dhcpd.conf:

subnet 192.168.2.0 netmask 255.255.255.0
{

range 192.168.2.100 192.168.1.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.2.255;
option domain-name-servers 192.168.2.254;
option routers 192.168.2.254;
next-server 192.168.2.254;
filename “/pxelinux.0”;

}

Start DHCP and TFTP on your server (now DHCP should listen on both IP addresses 192.168.1.254 and 192.168.2.254) .
The whole process of network boot should now work this way:

  • new machine is configured to boot from network card using so-called PXE boot
  • machine is powered up and searches for a DHCP server
  • DHCP server assign an IP address to booting machine along with other boot options
  • machine tries to connect to TFTP server specified in next-server parameter
  • machine searches the config file using the hardware type, IP address or default filename (see here for more information)
  • Now we are at the interesting point where we can send a remote machine specific PXE menu based on its IP or even its MAC address. I am using this tricky feature to have a different PXE menu for production servers and different PXE menu for testing servers.

    To find out what configuration file the machine will be look for (based on assigned IP address) you can use gethostip command.


    gethostip 192.168.1.1
    192.168.1.1 192.168.1.1 C0A80101
    gethostip 192.168.1.2
    192.168.1.2 192.168.1.2 C0A80102

    to be continued…

    Posted in Server administration


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Bad Behavior has blocked 728 access attempts in the last 7 days.