RHEL/CentOS 7: Deploying a System Using PXE

0
38

PXE, or Preboot eXecution Environment, allows you to instruct computers to boot using network resources. This allows you to control a single source to install servers without the need to physically insert cumbersome DVDs or USB sticks.

For this tutorial, you will need a fully working RHEL 7 repository.

In this tutorial, we’ll install and configure PXE boots from the RHEL 7 installation media, as follows:

  1. Install the necessary packages using the following command:
    ~]# yum install -y dnsmasq syslinux tftp-server
    
  2. Configure the DNSMASQ server by editing /etc/dnsmasq.conf, as follows:
    # interfaces to bind to
    interface=eno1,lo
    # the domain for this DNS server
    domain=rhel7.lan
    # DHCP lease range
    dhcp-range= eno1,192.168.0.3,192.168.0.103,255.255.255.0,1h
    # PXE – the address of the PXE server
    dhcp-boot=pxelinux.0,pxeserver,192.168.0.1
    # Gateway
    dhcp-option=3,192.168.0.254
    # DNS servers for DHCP clients(your internal DNS servers, and one of Google's DNS servers)
    dhcp-option=6,192.168.1.1, 8.8.8.8
    # DNS server to forward DNS queries to
    server=8.8.4.4
    # Broadcast Address
    dhcp-option=28,192.168.0.255
    pxe-prompt="Press F1 for menu.", 60
    pxe-service=x86_64PC, "Install RHEL 7 from network", pxelinux
    enable-tftp
    tftp-root=/var/lib/tftpboot
  3. Enable and start dnsmasq using the following:
    ~]# systemctl enable dnsmasq
    ~]# systemctl start dnsmasq
    
  4. Now, enable and start the xinet daemon by running the following:
    ~]# systemctl enable xinetd
    ~]# systemctl start xinetd
    
  5. Enable the tftp server’s xinet daemon, as follows:
    ~]# sed -i '/disable/ s/yes/no/' /etc/xinetd.d/tftp
    
  6. Copy the syslinux boot loaders to the tftp server’s boot directory by executing the following command:
    ~]# cp -r /usr/share/syslinux/* /var/lib/tftpboot
    
  7. Next, create the PXE configuration directory using this command:
    ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
    
  8. Then, create the PXE configuration file, as follows: /var/lib/tftpboot/pxelinux.cfg/default.
    default menu.c32
    prompt 0
    timeout 300
    ONTIMEOUT local
    menu title PXE Boot Menu
    label 1
      menu label ^1 - Install RHEL 7 x64 with Local http Repo
      kernel rhel7/vmlinuz
      append initrd=rhel7/initrd.img method=http://repo.critter.be/rhel/7/os/x86_64/ devfs=nomount ks=http://kickstart.critter.be/kickstart.ks
    label 2
      menu label ^2 - Boot from local media
  9. Copy initrd and kernel from the RHEL 7 installation media to /var/lib/tftpboot/rhel7/, and run the following commands:
    ~]# mkdir /var/lib/tftpboot/rhel7
    ~]# mount -o loop /dev/cdrom /mnt
    ~]# cp /mnt/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/rhel7/
    ~]# umount /mnt
    
  10. Open the firewall on your server using these commands (however, this may not be necessary):
    ~]# firewall-cmd --add-service=dns --permanent
    ~]# firewall-cmd --add-service=dhcp --permanent
    ~]# firewall-cmd --add-service=tftp --permanent
    ~]# firewall-cmd --reload
    
  11. Finally, launch your client, configure it to boot from the network, and select the first option shown in the following figure:

deploying-system-using-pxe

DNSMASQ takes care of pointing booting systems to the tftp server by providing the enable-tftp option in the dnsmasq configuration file.

Syslinux is needed to provide the necessary binaries to boot from the network.

The tftp server itself provides access to the syslinux files, RHEL 7 kernel, and initrd for the system to boot from.

The PXE configuration file provides the necessary configuration to boot a system, including a kickstart file that automatically installs your system.

This tutorial base premise is that you do not have a DHCP server installed. In most companies, you already have DHCP services available.

If you have an ISC-DHCP server in place, this is what you need to add to the subnet definition(s) you want to allow in PXE:

  next-server <ip address of TFTP server>;
  filename "pxelinux.0";

LEAVE A REPLY

Please enter your comment!
Please enter your name here