How to automate the RHEL installation remotely using PXE boot Server

How to automate the RHEL installation remotely using PXE boot Server

linux_pxeboot

Test Environment

RHEL8

Here in this article we will how we can PXE Boot a remote server with the minimal iso rhel8 base image. This article is a continuation of the article – https://novicejava1.blogspot.com/2019/05/how-to-boot-minimal-iso-rhel-8-image.html shared previously.

Procedure

Step1: Install tftp-server

[root@rhelser8 ~]# yum install tftp-server
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                                              499  B/s | 4.5 kB     00:09
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                                                 2.8 kB/s | 4.0 kB     00:01
Dependencies resolved.
======================================================================================================================================
 Package                     Arch                   Version                    Repository                                        Size
======================================================================================================================================
Installing:
 tftp-server                 x86_64                 5.2-24.el8                 rhel-8-for-x86_64-appstream-rpms                  50 k

Transaction Summary
======================================================================================================================================
Install  1 Package

Total download size: 50 k
Installed size: 67 k
Is this ok [y/N]: y
Downloading Packages:
tftp-server-5.2-24.el8.x86_64.rpm                                                                      36 kB/s |  50 kB     00:01
--------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                  36 kB/s |  50 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                              1/1
  Installing       : tftp-server-5.2-24.el8.x86_64                                                                                1/1
  Running scriptlet: tftp-server-5.2-24.el8.x86_64                                                                                1/1
  Verifying        : tftp-server-5.2-24.el8.x86_64                                                                                1/1
Installed products updated.

Installed:
  tftp-server-5.2-24.el8.x86_64

Complete!

Step2: Enable incoming connection to tftp server

[root@rhelser8 ~]# firewall-cmd --add-service=tftp --permanent
success
[root@rhelser8 ~]# firewall-cmd --reload
success
[root@rhelser8 ~]# firewall-cmd --list-services
cockpit dhcpv6-client ssh tftp

Step3: Install the DHCP server

[root@rhelser8 dhcp]# yum install dhcp-server
Updating Subscription Management repositories.
Last metadata expiration check: 0:07:17 ago on Fri 17 May 2019 11:20:19 PM IST.
Dependencies resolved.
======================================================================================================================================
 Package                    Arch                  Version                          Repository                                    Size
======================================================================================================================================
Installing:
 dhcp-server                x86_64                12:4.3.6-30.el8                  rhel-8-for-x86_64-baseos-rpms                529 k


Transaction Summary
======================================================================================================================================
Install  1 Package


Total download size: 529 k
Installed size: 1.2 M
Is this ok [y/N]: y
Downloading Packages:
dhcp-server-4.3.6-30.el8.x86_64.rpm                                                                   260 kB/s | 529 kB     00:02
--------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                 260 kB/s | 529 kB     00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                              1/1
  Running scriptlet: dhcp-server-12:4.3.6-30.el8.x86_64                                                                           1/1
  Installing       : dhcp-server-12:4.3.6-30.el8.x86_64                                                                           1/1
  Running scriptlet: dhcp-server-12:4.3.6-30.el8.x86_64                                                                           1/1
  Verifying        : dhcp-server-12:4.3.6-30.el8.x86_64                                                                           1/1
Installed products updated.


Installed:
  dhcp-server-12:4.3.6-30.el8.x86_64


Complete!

Step4: Configure the DHCP Server

[root@rhelser8 dhcp]# pwd
/etc/dhcp
[root@rhelser8 dhcp]# cat dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;


subnet 192.168.91.0 netmask 255.255.255.0 {
  option routers 192.168.91.1;
  range 192.168.91.145 192.168.91.253;


  class "pxeclients" {
      match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
      next-server 192.168.91.145;


      if option architecture-type = 00:07 {
        filename "uefi/shim.efi";
      } else {
        filename "pxelinux/pxelinux.0";
      }
  }
}

Step5: Extract the DVD ISO

[root@rhelser8 mountpoint]# pwd
/mountpoint
[root@rhelser8 rhel8-install]# mount -t iso9660 /rhel8-install/rhel-8.0-x86_64-dvd.iso /mountpoint -o loop,ro
[root@rhelser8 rhel8-install]# cd /mountpoint
[root@rhelser8 mountpoint]# ls -ltr
total 48
-r--r--r--. 1 root root  5134 Mar  1 20:47 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1669 Mar  1 20:47 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root 18092 Mar  1 20:47 GPL
-r--r--r--. 1 root root  8266 Mar  1 20:47 EULA
-r--r--r--. 1 root root   103 Apr  4 14:07 media.repo
-r--r--r--. 1 root root  1455 Apr  4 14:07 extra_files.json
-r--r--r--. 1 root root  1796 Apr  4 14:09 TRANS.TBL
dr-xr-xr-x. 2 root root  2048 Apr  4 14:09 isolinux
dr-xr-xr-x. 3 root root  2048 Apr  4 14:09 images
dr-xr-xr-x. 3 root root  2048 Apr  4 14:09 EFI
dr-xr-xr-x. 4 root root  2048 Apr  4 14:09 BaseOS
dr-xr-xr-x. 4 root root  2048 Apr  4 14:09 AppStream
[root@rhelser8 mountpoint]# cp -pr BaseOS/Packages/syslinux-tftpboot-6.04-1.el8.noarch.rpm /home/admin/
[root@rhelser8 /]# umount /mountpoint
[root@rhelser8 /]# cd /home/admin/
[root@rhelser8 admin]# ls -ltr
total 464
-r--r--r--. 1 root root 473360 Dec 15 06:45 syslinux-tftpboot-6.04-1.el8.noarch.rpm
[root@rhelser8 admin]# rpm2cpio syslinux-tftpboot-6.04-1.el8.noarch.rpm | cpio -dimv
./tftpboot
./tftpboot/cat.c32
./tftpboot/chain.c32
./tftpboot/cmd.c32
./tftpboot/cmenu.c32
./tftpboot/config.c32
./tftpboot/cptime.c32
./tftpboot/cpu.c32
./tftpboot/cpuid.c32
./tftpboot/cpuidtest.c32
./tftpboot/debug.c32
./tftpboot/dhcp.c32
./tftpboot/dir.c32
./tftpboot/disk.c32
./tftpboot/dmi.c32
./tftpboot/dmitest.c32
./tftpboot/elf.c32
./tftpboot/ethersel.c32
./tftpboot/gfxboot.c32
./tftpboot/gpxecmd.c32
./tftpboot/hdt.c32
./tftpboot/hexdump.c32
./tftpboot/host.c32
./tftpboot/ifcpu.c32
./tftpboot/ifcpu64.c32
./tftpboot/ifmemdsk.c32
./tftpboot/ifplop.c32
./tftpboot/kbdmap.c32
./tftpboot/kontron_wdt.c32
./tftpboot/ldlinux.c32
./tftpboot/lfs.c32
./tftpboot/libcom32.c32
./tftpboot/libgpl.c32
./tftpboot/liblua.c32
./tftpboot/libmenu.c32
./tftpboot/libutil.c32
./tftpboot/linux.c32
./tftpboot/lpxelinux.0
./tftpboot/ls.c32
./tftpboot/lua.c32
./tftpboot/mboot.c32
./tftpboot/memdisk
./tftpboot/meminfo.c32
./tftpboot/menu.c32
./tftpboot/pci.c32
./tftpboot/pcitest.c32
./tftpboot/pmload.c32
./tftpboot/poweroff.c32
./tftpboot/prdhcp.c32
./tftpboot/pwd.c32
./tftpboot/pxechn.c32
./tftpboot/pxelinux.0
./tftpboot/reboot.c32
./tftpboot/rosh.c32
./tftpboot/sanboot.c32
./tftpboot/sdi.c32
./tftpboot/sysdump.c32
./tftpboot/syslinux.c32
./tftpboot/vesa.c32
./tftpboot/vesainfo.c32
./tftpboot/vesamenu.c32
./tftpboot/vpdtest.c32
./tftpboot/whichsys.c32
./tftpboot/zzjson.c32
2189 blocks
[root@rhelser8 admin]#

Step6: Copy the required files

[root@rhelser8 admin]# mkdir /var/lib/tftpboot/pxelinux
[root@rhelser8 admin]# cp /home/admin/tftpboot/pxelinux.0 /var/lib/tftpboot/pxelinux
[root@rhelser8 admin]# mkdir /var/lib/tftpboot/pxelinux/pxelinux.cfg
[root@rhelser8 admin]# cat /var/lib/tftpboot/pxelinux/pxelinux.cfg/default
default vesamenu.c32
prompt 1
timeout 600


display boot.msg


label linux
  menu label ^Install system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ip=dhcp inst.repo=nfs:192.168.91.143:/rhel8-install/
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img ip=dhcp inst.xdriver=vesa nomodeset inst.repo=nfs:192.168.91.143:/rhel8-install/
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff


[root@rhelser8 mountpoint]# cp /mountpoint/images/pxeboot/vmlinuz /var/lib/tftpboot/pxelinux/
[root@rhelser8 mountpoint]# cp /mountpoint/images/pxeboot/initrd.img /var/lib/tftpboot/pxelinux/
[root@rhelser8 pxelinux]# cp /mountpoint/isolinux/vesamenu.c32 /var/lib/tftpboot/pxelinux/
[root@rhelser8 pxelinux]# cp /home/admin/tftpboot/libutil.c32 /var/lib/tftpboot/pxelinux/
[root@rhelser8 pxelinux]# cp /home/admin/tftpboot/ldlinux.c32 /var/lib/tftpboot/pxelinux/
[root@rhelser8 pxelinux]# cp /home/admin/tftpboot/libcom32.c32 /var/lib/tftpboot/pxelinux/
[root@rhelser8 pxelinux]# ls -ltr
total 67116
drwxr-xr-x. 2 root root       21 May 17 23:50 pxelinux.cfg
-rwxr-xr-x. 1 root root  7872864 May 17 23:54 vmlinuz
-rwxr-xr-x. 1 root root 60447004 May 17 23:54 initrd.img
-rwxr-xr-x  1 root root   116064 May 19 05:30 ldlinux.c32
-rwxr-xr-x  1 root root   180668 May 19 05:30 libcom32.c32
-rwxr-xr-x. 1 root root    42819 May 19 05:30 pxelinux.0
-rwxr-xr-x. 1 root root    26788 May 19 05:30 vesamenu.c32
-rw-r--r--  1 root root    22836 May 19 05:38 libutil.c32

Step7: Start the DHCP service and TFTP service as below

[root@rhelser8 ~]# systemctl start dhcpd
[root@rhelser8 ~]# systemctl status dhcpd
? dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-05-17 23:57:23 IST; 9s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 2745 (dhcpd)
   Status: "Dispatching packets..."
    Tasks: 1 (limit: 11368)
   Memory: 8.1M
   CGroup: /system.slice/dhcpd.service
           +-2745 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid


May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Database file: /var/lib/dhcpd/dhcpd.leases
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: PID file: /var/run/dhcpd.pid
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Source compiled to use binary-leases
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Wrote 0 class decls to leases file.
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Wrote 0 leases to leases file.
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Listening on LPF/ens33/00:0c:29:55:04:28/192.168.91.0/24
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Sending on   LPF/ens33/00:0c:29:55:04:28/192.168.91.0/24
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Sending on   Socket/fallback/fallback-net
May 17 23:57:23 rhelser8.stack.com dhcpd[2745]: Server starting service.
May 17 23:57:23 rhelser8.stack.com systemd[1]: Started DHCPv4 Server Daemon.
[root@rhelser8 ~]# systemctl enable dhcpd
Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd.service ? /usr/lib/systemd/system/dhcpd.service.
[root@rhelser8 ~]# systemctl start tftp
[root@rhelser8 ~]# systemctl status tftp
? tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: active (running) since Fri 2019-05-17 23:59:07 IST; 6s ago
     Docs: man:in.tftpd
 Main PID: 2773 (in.tftpd)
    Tasks: 1 (limit: 11368)
   Memory: 216.0K
   CGroup: /system.slice/tftp.service
           +-2773 /usr/sbin/in.tftpd -s /var/lib/tftpboot


May 17 23:59:07 rhelser8.stack.com systemd[1]: Started Tftp Server.
[root@rhelser8 ~]# systemctl enable tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket ? /usr/lib/systemd/system/tftp.socket.

Now we are all set with the PXE server to boot the RHEL remotely.

Let us create a VM without setting any DVD ISO or Boot ISO to load as shown below.

Start the VM and validate if its able to communicate with DHCP and TFTP server to get the PXEBoot files.

Once the boot files are loaded the RHEL 8 installation should trigger automatically without any intervention as per the kickstart file present in the NFS export location.

In case the kickstart file is not complete, the installation screen will prompt for updating those components.

Hope you enjoyed reading this article. Thank you..