Your Mobile Number please
Your Brief Introduction
Select the Course you will teach. If not listed. No Problem. Just Select "Not Listed".
Facebook profile link
Twitter profile link
Your Linkedin Profile URL
In this Lab Assignment (A part of RHCSA Training Course), you will configure and use Automated Installations of RHEL/CentOS 7 using PXE Server and Kickstart File. The Complete course is available here. Course Contents for the RHCSA Trainings are available here. The Lab assignment is divided in two sections as follows:
Subscribe to the Youtube Channel for Live Demo
PXE Server (Preboot eXecution Environment) instructs a client computer to boot, run or install an operating system directly form a network interface, eliminating the need to burn a CD/DVD or use a physical medium, or, can ease the job of installing Linux distributions on your network infrastructure on multiple machines the same time.
I will explain how you can install and configure a PXE Server on RHEL/CentOS 7 x64-bit with ftp and http installation repositories, sources provided by CentOS 7 DVD ISO image using libvirtd and DNSMASQ Server (service provided by libvirted. No separate installation required) Which provides DNS and DHCP services, Syslinux package which provides bootloaders for network booting, TFTP-Server, which makes bootable images available to be downloaded via network using Trivial File Transfer Protocol (TFTP) and VSFTPD Server which will host the local mounted mirrored DVD image – which will act as an official RHEL/CentOS 7 mirror installation repository from where the installer will extract its required packages.
In the second part, I will focused on how you can perform Automatic Installations of RHEL/CentOS 7, without the need for user intervention, on headless machines using a Kickstart file read from a local FTP server.
The simplest way to create a customize Kickstart file that you can use it further for multiple installations is to manually perform an installation of RHEL/CentOS 7 and copy, after installation process finishes, the file /root/anaconda-ks.cfg, to an accessible network location, and specify the initrd boot parameter inst.ks=protocol://path/to/kickstart.file to PXE Menu Configuration File.
On linux host servers, libvirtd uses dnsmasq to service the virtual networks, such as the default network. A new instance of dnsmasq is started for each virtual network, only accessible to guests in that specific network.
If you are running your own “global” dnsmasq, then this can cause your own dnsmasq to fail to start (or for libvirtd to fail to start its dnsmasq and the given virtual network). This happens because both instances of dnsmasq might try to bind to the same port number on the same network interfaces. Therefore ensure that you are not running dnsmasq as independent service.
# virsh net-edit default
(This will open /var/lib/libvirt/dnsmasq/default.conf in xml format as given below)
<bridge name=’virbr0′ stp=’on’ delay=’0’/>
<ip address=’192.168.122.1′ netmask=’255.255.255.0′>
<range start=’192.168.122.128′ end=’192.168.122.254’/>
# virsh net-destroy default
# virsh net-start default
# vi /var/lib/libvirt/dnsmasq/default.conf
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
## dnsmasq conf file created by libvirt
Verify the “dhcp-boot” Option. If the option is still missing, restart the machine and verify again.
# yum install syslinux
# ls /usr/share/syslinux
# yum install tftp-server
# systemctl enable tftp.service
# systemctl start tftp.service
# systemctl status tftp.service
# cp -r /usr/share/syslinux/* /var/lib/tftpboot
Create the required directory pxelinux.cfg and populate it with a default file:
# mkdir /var/lib/tftpboot/pxelinux.cfg
Here is a an example configuration file that you can use it, but modify the installation images (kernel and initrd files), protocols (FTP, HTTP, HTTPS, NFS) and IPs to reflect your network installation source repositories and paths accordingly.
# vi /var/lib/tftpboot/pxelinux.cfg/default
Add the following whole excerpt to the file.
menu title ########## PXE Boot Menu – The Skill Pedia ##########
menu label ^1) Install CentOS 7 x64 from FTP Server
append initrd=/centos7/initrd.img method=ftp://192.168.122.1/pub/inst
menu label ^2) Install CentOS 7 x64 from Web Server & Kickstart File
append initrd=/centos7/initrd.img method=http://192.168.122.1/inst inst.ks=http://192.168.122.1/inst/ks.cfg
devfs=nomount inst.vnc inst.vncpassword=password
As you can see CentOS 7 boot images (kernel and initrd) reside in a directory named centos7 relative to /var/lib/tftpboot and the installer repositories can be reached by using ftp://192.168.122.1/pub/inst or http://192.168.122.1/inst network location.
The reason for using the DVD and not a Minimal CD Image is the fact that this DVD content would be used to create the locally installer repositories for FTP and HTTP Sources.
# mount -o loop /dev/cdrom /mnt
# ls /mnt
If your machine has no DVD drive you can also download CentOS 7 DVD ISO.
# cd ~/Downloads
# wget http://mirrors.xservers.ro/centos/7.4.1708/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
# mount -o loop CentOS-7-x86_64-DVD-1708.is /mnt
# mkdir /var/lib/tftpboot/centos7
# cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7
# cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7
The reason for using this approach is that, later you can create new separate directories in /var/lib/tftpboot path and add other Linux distributions to PXE menu without messing up the entire directory structure.
# yum install vsftpd
# cp -ar /mnt/* /var/ftp/pub/inst/
# chmod -R 755 /var/ftp/pub/inst
Ensure that you have copied two files starting with “.” ( .diskinfo and .treeinfo)
# systemctl restart libvirtd
# systemctl status libvirtd
# systemctl start vsftpd
# systemctl status vsftpd
# systemctl enable libvirtd
# systemctl enable vsftpd
# systemctl restart tftp.service
# netstat -tulpn
# firewall-cmd –add-service=ftp –permanent ## Port 21
# firewall-cmd –add-service=dns –permanent ## Port 53
# firewall-cmd –add-service=dhcp –permanent ## Port 67
# firewall-cmd –add-port=69/udp –permanent ## Port for TFTP
# firewall-cmd –add-port=4011/udp –permanent ## Port for ProxyDHCP
# firewall-cmd –reload ## Apply rules
# tail -f /var/log/ messages
# umount /mnt
Please note down that using variant 2 from this menu requires a kickstart file is created and available as discussed in the next Sequence.
In this lab I have used the Kikstart file resulted from the previous Installation procedure of RHEL/CentOS 7.
If you need a Kickstart file that covers GUI Installation and a specific partition table, I suggest that you first perform a customizable Graphical Installation of RHEL/CentOS 7 in a virtualized environment and use that resulted Kickstart file for future GUI installations.
# mount -o loop /path/to/centos-dvd.iso /mnt
# yum install httpd*
# cp -ar /mnt/* /var/www/html/inst/
# chmod -R 755 /var/www/html/inst
Ensure that you have copied two files starting with “.” ( .diskinfo and .treeinfo)
# systemctl restart httpd
# systemctl status httpd
# systemctl enable httpd
# cp anaconda-ks.cfg /var/www/html/inst/ks.cfg
# chmod 755 /var/www/html/inst/ks.cfg
# vi /var/www/html/inst/ks.cfg
An excerpt on how a Kickstart file might look like is presented below. You can use it as it is. The Password is “redhat” in encrypted form.
(If you have successfully completed Lab 5, you should have you’re your own Kickstart file at ftp server, that is, ftp://192.168.122.1/pub/inst/ks.cfg. You can use same or create a new one as given below)
#platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard –vckeymap=us –xlayouts=’us’
# Root password
# Use network installation
# System language
# Firewall configuration
# System authorization information
auth –useshadow –passalgo=sha512
# Use graphical install
# Run the Setup Agent on first boot
# SELinux configuration
# System services
# Network information
network –bootproto=dhcp –device=eth0
# Reboot after installation
# System timezone
# System bootloader configuration
bootloader –append=”crashkernel=auto” –location=mbr –boot-drive=vda
# Clear the Master Boot Record
# Partition clearing information
clearpart –all –initlabel
# Disk partitioning information
part / –fstype=”xfs” –size=5000
part /boot –fstype=”xfs” –size=500
part swap –fstype=”swap” –size=2000
# yum install pykickstart
# ksvalidator /var/www/html/inst/ks.cfg
———–PXE Menu Label excerpt—————-
As you can see from this example the automatically installation can be supervised via VNC with password (replace VNC password accordingly) and the Kickstart file is located locally on PXE server and is specified by the initrd boot parameter inst.ks= http network location
That’s all! Automatic Kickstart installations offer a great deal of benefits for system administrators in environments that they have to perform system installations on multiple machines the same time, in a short period of time, without the need to manually interfere with the installation process.
This will give you time to do other things, or perhaps some leisure time if you’re lucky.
Your email address will not be published. Required fields are marked *