Saturday, September 6, 2008

PXE Booting and Installing CentOS Linux

This describes a very simple PXE boot setup on CentOS Linux. If machine A has no CD or DVD drive how can we install an operating system? Well, have machine B store a separate kernel and an installation repository (the install CD/DVD) then tell machine A to boot from this kernel on B and install an OS using the install data on B. This setup is “simple” in the sense that it will not have extensive options and/or menus at boot time - it is intended for installations and/or recovery of one version of the OS only. PXELinux has many options for menu configuration, for e.g. you could offer CentOS version 4.4 or 5.0 or even different Linux distributions. This was done using CentOS 5.0.

Setup on the client (machine A) is very simple and is done via the BIOS menus - just enable PXE booting on your network card and then put the network card first in boot priority order listing.

On the server (machine B) you will need the following (this is the order in which the client talks to the various server daemons)

  1. DHCP server to assign an IP address to the client, tell it that a TFTP server exists and where to find it.
  2. TFTP server to provide a kernel (and options) to the client so that it can boot.
  3. HTPP, FTP or NFS server to offer up the installation repository.

DHCP Server

  1. Install the DHCP server (package name is simply “dhcp”).
  2. Edit /etc/dhcpd.conf to allow network booting and tell clients where they can find the TFTP server (the next-server option) and the name of the file it should load

    ddns-update-style interim;
    ignore client-updates;
    allow booting;
    allow bootp;
    subnet 192.168.0.0 netmask 255.255.255.0 {
    # --- default gateway
    option routers 192.168.0.1;
    option subnet-mask 255.255.255.0;
    option domain-name "yourDomainName.com";
    option domain-name-servers 192.168.0.1;
    range dynamic-bootp 192.168.0.128 192.168.0.254;
    default-lease-time 21600;
    max-lease-time 43200;
    next-server 192.168.0.8;
    filename "/pxelinux.0";
    }
  3. Open port UDP 67 in the firewall and restart the DHCP server (service dhcpd restart)

TFTP Server

  1. Install the TFTP server (package name = tftp-server).
  2. The TFTP server is a “on-demand” network service and is thus managed by xinetd. Set “disable=no” in /etc/xinetd.d/tftp and restart xinetd (service xinted restart)
  3. Install syslinux and copy pxelinux.0 to the TFTP server’s root

    cp /usr/lib/syslinux/pxelinux.0 /tftpboot
  4. From the installation sources (on disk #1 one if you are using CDs) copy the kernel and ramdisk image to the TFTP server’s root

    cp location/of/installation/disks/images/pxeboot/vmlinuz /tftpboot
    cp location/of/installation/disks/images/pxeboot/initrd.img /tftpboot
  5. Make a directory to hold the PXE boot configuration files (mkdir /tftpboot/pxelinux.cfg)
  6. The name of the configuration file is tricky and depends on your local setup - the tftp client will look for config files (in this order) that are named after the NIC’s GUID, the NICs MAC address, a hexadecimal representation of the client’s IP address, truncated versions of the hexadecimal IP address (details here). This is a problem - often you don’t know the client’s GUID or MAC address until you can boot it but you can’t boot it because the TFTP server configuration is not complete. I suggest using WireShark or tcpdump on the server to capture requests from the client and thus learn it’s MAC address. Once you know the MAC address, create a configuration file whose name is “01″ concatenated with the MAC address (use dashes to replace colons). For example, my MAC address is 00:13:72:0d:ee:f1 and my config file is named /tftpboot/pxelinux.cfg/01-00-13-72-0d-ee-f1. Older versions (<3.20)>
  7. Edit this config file to tell the client where to find a kernel (and options to the kernel)

    echo "DEFAULT vmlinuz initrd=initrd.img ramdisk_size=100000" >> /tftpboot/pxelinux.cfg/name-of-config-file
  8. Open port UDP 69 in the firewall.

Installation Repository on FTP Server

  1. Install vsftpd, open port TCP 21 in the firewall and start the service (default settings will allow anonymous ftp so there is no need to configure anything else)
  2. Mount or copy the installion sources into the public FTP directory (/var/ftp/pub). If using ISO images use the “-o loop” option to the mount command mount -o loop /location/installation/disks/CentOS5_dvd.iso /var/ftp/pub/

Doing the Installtion

Now boot up the client and everything should work perfectly ;-) Use WireShark or tcpdump on the server the first time to help debug any network/daemon issues. During the install on the client select the “FTP” option when asked for the source of installation the files, enter the name or IP address of the FTP server and the directory of the installation sources (simply /pub in this example).

No comments: