How to configure ‘PXE Network Boot Server’ for Multiple Linux Distribution
Setting up a ‘ PXE Network Boot Server’ for Multiple Linux Distribution Installations
PXE Server &ndash Preboot eXecution Environment &ndash instructs a client computer to boot or install an operating system from a network interface, this avoids the need of burn a CD/DVD or use a physical medium, and can ease the job of installing Linux distributions on your infrastructure on multiple machines the same time.
This article will explain how to install and configure a PXE Server on CentOS 7 x64-bit with local installation repositories, CentOS 7 DVD ISO image, with the help of DNSMASQ Server.
DNSMASQ server provides DNS and DHCP services, Syslinux package provides bootloaders for network booting, TFTP-Server makes bootable images available to be downloaded through network using Trivial File Transfer Protocol (TFTP) and VSFTPD Server will host the local mounted DVD image files &ndash which will act as an official CentOS 7 installation repository from where the installer will extract its required packages.
Requirements
- CentOS 7 minimal installation
- Configure static ip address in CentOS 7
Install and configure DNSMASQ server
To install DNSMASQ server, use the following command
[root@linuxhelp ~]# yum install dnsmasq
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* epel: mirror.rise.ph
* extras: centos.webwerks.com
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package dnsmasq.x86_64 0:2.66-12.el7 will be updated
.
.
.
Updated:
dnsmasq.x86_64 0:2.66-14.el7_1
Complete!
After the installation is completed, configure the DNSMASQ server, first take backup of the DNSMASQ server configuration file and then create a new configuration file
[root@linuxhelp ~]# mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
[root@linuxhelp ~]# nano /etc/dnsmasq.conf
Add the following lines in the DNSMASQ configuration file
interface=eno16777736,lo #bind-interfaces domain=linuxhelp # DHCP range-leases dhcp-range= eno16777736,192.168.5.3,192.168.5.214,255.255.255.0,1h # PXE dhcp-boot=pxelinux.0,pxeserver,192.168.5.214 # Gateway dhcp-option=3,192.168.5.1 # DNS dhcp-option=6,192.168.5.1, 8.8.8.8 server=8.8.4.4 # Broadcast Address dhcp-option=28,192.168.5.255 # NTP Server dhcp-option=42,0.0.0.0 pxe-prompt=" Press F8 for menu." , 60 pxe-service=x86PC, " Install CentOS 7 from network server 192.168.5.214" , pxelinux enable-tftp tftp-root=/var/lib/tftpboot
interface : replace with your network interface name
domain : replace with your domain name
dhcp-range : replace with your ip address range in this segment
dhcp-boot : replace with your network interface ip address
dhcp-option=3 : replace with your network gateway
dhcp-option=6 : replace with your DNS server IP addresses
dhcp-option=28 : replace with your network broadcast address (optional)
dhcp-option=42 : replace with your network time servers
pxe prompt : don’ t change,leave it as default
pxe=service : Use x86PC for 32-bit/64-bit architectures and enter a menu description prompt under string quotes. Other values types can be: PC98, IA64_EFI, Alpha, Arc_x86, Intel_Lean_Client, IA32_EFI, BC_EFI, Xscale_EFI and X86-64_EFI.
enable-tftp : enables the tftp server
tftp-root : location of all netbooting files
Install SYSLINUX Bootloaders
To install the syslinux bootloader, use the following command
[root@linuxhelp ~]# yum install syslinux
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* epel: ftp.cuhk.edu.hk
* extras: centos.webwerks.com
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package syslinux.x86_64 0:4.05-12.el7 will be installed
.
.
.
Installed:
syslinux.x86_64 0:4.05-12.el7
Complete!
Install TFTP server
To install the tftp server,use the following command
[root@linuxhelp ~]# yum install tftp-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* epel: ftp.cuhk.edu.hk
* extras: centos.webwerks.com
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package tftp-server.x86_64 0:5.2-12.el7 will be installed
.
.
.
Installed:
tftp-server.x86_64 0:5.2-12.el7
Complete!
Now copy the bootloader files to the tftp server path
cp -r /usr/share/syslinux/* /var/lib/tftpboot
PXE configuration file
Create a directory pxelinux.cfg under tftpboot directory
[root@linuxhelp ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
Now create a pxe configuration file under pxelinux.cfg directory
[root@linuxhelp ~]# touch /var/lib/tftpboot/pxelinux.cfg/default
Now open the configuration file and add the following lines
[root@linuxhelp ~]# nano /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 CentOS 7 x64 with Local Repo
kernel centos7/vmlinuz
append initrd=centos7/initrd.img method=ftp://192.168.5.214/pub devfs=nomount
label 2
menu label ^2) Install CentOS 7 x64 with http://mirror.centos.org Repo
kernel centos7/vmlinuz
append initrd=centos7/initrd.img method=http://mirror.centos.org/centos/7/os/x86_64/ devfs=nomount ip=dhcp
label 3
menu label ^3) Install CentOS 7 x64 with Local Repo using VNC
kernel centos7/vmlinuz
append initrd=centos7/initrd.img method=ftp://192.168.5.214/pub devfs=nomount inst.vnc inst.vncpassword=password
Adding CentOS 7 boot images to PXE boot server
Mount a pendrive with CentOS 7 files
[root@linuxhelp ~]# mount -o loop /dev/sdb1 /mnt
Create a directory CentOS 7 within tftpboot directory
[root@linuxhelp ~]# mkdir /var/lib/tftpboot/centos7
Copy the CentOS 7 bootable kernel and initrd images from the pendrive mounted location to the CentOS 7 directory
[root@linuxhelp ~]# cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7
[root@linuxhelp ~]# cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/centos7
Create CentOS 7 local mirror Installation source
First install vsftpd daemon and then copy all the pendrive mounted OS files to the default vsftpd server path (/var/ftp/pub) and set 755 permissions for the directory
[root@linuxhelp ~]# yum install vsftpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* epel: ftp.cuhk.edu.hk
* extras: centos.webwerks.com
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-11.el7_2 will be installed
.
.
.
Installed:
vsftpd.x86_64 0:3.0.2-11.el7_2
Complete!
[root@linuxhelp ~]# cp -r /mnt/* /var/ftp/pub/
[root@linuxhelp ~]# chmod -R 755 /var/ftp/pub
Start and enable services
Start and enable the dnsmasq and vsftpd services.
[root@linuxhelp ~]# systemctl start dnsmasq
[root@linuxhelp ~]# systemctl status dnsmasq
dnsmasq.service - DNS caching server.
Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service disabled)
Active: active (running) since Tue 2016-05-10 10:03:03 IST 6s ago
Main PID: 4176 (dnsmasq)
CGroup: /system.slice/dnsmasq.service
??4176 /usr/sbin/dnsmasq -k
May 10 10:03:03 client systemd[1]: Started DNS caching server..
May 10 10:03:03 client dnsmasq[4176]: started, version 2.66 cachesize 150
May 10 10:03:03 client dnsmasq[4176]: compile time options: IPv6 GNU-getopt DBus no-i18n...uth
May 10 10:03:03 client dnsmasq[4176]: reading /etc/resolv.conf
May 10 10:03:03 client dnsmasq[4176]: using nameserver 8.8.4.4#53
May 10 10:03:03 client dnsmasq[4176]: using nameserver 8.8.8.8#53
May 10 10:03:03 client dnsmasq[4176]: read /etc/hosts - 3 addresses
Hint: Some lines were ellipsized, use -l to show in full.
[root@linuxhelp ~]# systemctl start vsftpd
[root@linuxhelp ~]# systemctl status vsftpd
vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service disabled)
Active: active (running) since Tue 2016-05-10 10:03:37 IST 7s ago
Process: 4186 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 4187 (vsftpd)
CGroup: /system.slice/vsftpd.service
??4187 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
May 10 10:03:37 client systemd[1]: Starting Vsftpd ftp daemon...
May 10 10:03:37 client systemd[1]: Started Vsftpd ftp daemon.
[root@linuxhelp ~]# systemctl enable dnsmasq
ln -s ' /usr/lib/systemd/system/dnsmasq.service' ' /etc/systemd/system/multi-user.target.wants/dnsmasq.service'
[root@linuxhelp ~]# systemctl enable vsftpd
ln -s ' /usr/lib/systemd/system/vsftpd.service' ' /etc/systemd/system/multi-user.target.wants/vsftpd.service'
To allow the services in Firewall
[root@linuxhelp ~]# firewall-cmd --add-service=ftp --permanent ## Port 21
[root@linuxhelp ~]# firewall-cmd --add-service=dns --permanent ## Port 53
[root@linuxhelp ~]# firewall-cmd --add-service=dhcp --permanent ## Port 67
[root@linuxhelp ~]# firewall-cmd --add-port=69/udp --permanent ## Port for TFTP
[root@linuxhelp ~]# firewall-cmd --add-port=4011/udp --permanent ## Port for ProxyDHCP
[root@linuxhelp ~]# firewall-cmd --reload ## Apply rules
[root@client ~]# firewall-cmd --list-services
dhcp dhcpv6-client dns ftp proxy-dhcp ssh
Test the FTP installation source
ftp://192.168.5.214/pub
Unmount the pendrive
[root@linuxhelp ~]# umount /mnt
Configure the clients to boot from network
Press F8 and then press enter to go the PXE menu and select the option that you need to go on with CentOS 7 installation.
If you want to add both Ubuntu15.10 and Debian 8 to the PXE Network Boot Server configuration, follow this link: https://www.linuxhelp.com/add-ubuntu-15-10-debian-8-pxe-setup-centos-7/
# /etc/dnsmasq.conf
# 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
dnsmasq, syslinux, tftp-server, vsftpd
# /usr/share/syslinux/