PXE (Preboot eXecution Environment) Server allows unattended or automated OS installation over the Network.The main benefit of pxe is that we don’t need any bootable drive to boot OS(Operating system) and we do not need to to burn any ISO file into DVD or usb device.
Once the PXE server is configured we can install hundreds of System at the same time over the network.As it works on Client-Server architecture, to get the OS installation on clients, boot the clients via PXE option.
In this article i am going to setup PXE Server on CentOS 7.x and then will try to install OS on the client using pxe boot.
Below are details of my Setup :
- Server IP = 172.168.1.11
- Host name = pxe.example.com
- OS = CentOS 7.x
- SELinux = enabled
- Firewall = enabled
Step:1 Install required packages for PXE Setup
To install and Configure pxe server on centos 7.x we need the following packages “dhcp, tftp-server, ftp server(vsftpd), xinted”. Open the terminal execute beneath command :
[root@pxe ~]# yum install dhcp tftp tftp-server syslinux vsftpd xinetd
Step:2 Configure DHCP Server for PXE
When we install dhcp package then a sample configuration file of dhcp server is created at “/usr/share/doc/dhcp*/dhcpd.conf.example“, though the configuration file of dhcp is at ‘/etc/dhcp/dhcpd.conf’.
Copy the following lines into the file ‘/etc/dhcp/dhcpd.conf’, replace the ip subnet and other details as per your environment.
[root@pxe ~]# vi /etc/dhcp/dhcpd.conf # DHCP Server Configuration file. ddns-update-style interim; ignore client-updates; authoritative; allow booting; allow bootp; allow unknown-clients; # internal subnet for my DHCP Server subnet 172.168.1.0 netmask 255.255.255.0 { range 172.168.1.21 172.168.1.151; option domain-name-servers 172.168.1.11; option domain-name "pxe.example.com"; option routers 172.168.1.11; option broadcast-address 172.168.1.255; default-lease-time 600; max-lease-time 7200; # IP of PXE Server next-server 172.168.1.11; filename "pxelinux.0"; }
Step:3 Edit and Config tftp server (/etc/xinetd.d/tftp)
TFTP (Trivial File Transfer Protocol ) is used to transfer files from data server to its clients without any kind of authentication. In case of PXE server setup tftp is used for bootstrap loading. To config tftp server, edit its configuration file ‘ /etc/xinetd.d/tftp’, change the parameter ‘disable = yes‘ to ‘disable = no’ and leave the other parameters as it is.
[root@pxe ~]# vi /etc/xinetd.d/tftp service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4 }
All the network boot related files are to be placed in tftp root directory “/var/lib/tftpboot”
Run the following commands to copy required network boot files in ‘/var/lib/tftpboot/’
[root@pxe ~]# cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot [root@pxe ~]# cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot [root@pxe ~]# cp -v /usr/share/syslinux/memdisk /var/lib/tftpboot [root@pxe ~]# cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot [root@pxe ~]# cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot [root@pxe ~]# [root@pxe ~]# mkdir /var/lib/tftpboot/pxelinux.cfg [root@pxe ~]# mkdir /var/lib/tftpboot/networkboot root@pxe ~]#
Step:4 Mount CentOS 7.x ISO file and copy its contents to local ftp server
In my case i have already downloaded CentOS 7.x iso file on my PXE Server. Run the beneath commands to mount iso file and then copy its contents in ftp server’s directory ‘/var/ftp/pub’
[root@pxe ~]# mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/ mount: /dev/loop0 is write-protected, mounting read-only [root@pxe ~]# cd /mnt/ [root@pxe mnt]# cp -av * /var/ftp/pub/
Copy Kernel file (vmlimz) and initrd file from mounted iso file to ‘/var/lib/tftpboot/networkboot/’
[root@pxe ~]# cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/networkboot/ [root@pxe ~]# cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/networkboot/ [root@pxe ~]#
Now you can unmount the iso file using ‘umount’ command
[root@pxe ~]# umount /mnt/ [root@pxe ~]#
Step:5 Create kickStart & PXE menu file.
Before creating kickstart file, let’s first create the root password in an encrypted string because we will using that encrypted password string in kickstart file.
[root@pxe ~]# openssl passwd -1 Pxe@123# $1$e2wrcGGX$tZPQKPsXVhNmbiGg53MN41 [root@pxe ~]#
System default kickstart file is placed under /root with name ‘anaconda-ks.cfg’. We will be creating a new kickstart under the folder /var/ftp/pub with the name ‘centos7.cfg’
Copy the following content into the new kickstart file. Please modify the kickstart file as per your needs.
[root@pxe ~]# vi /var/ftp/pub/centos7.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use FTP installation media url --url="ftp://172.168.1.11/pub/" # Root password rootpw --iscrypted $1$e2wrcGGX$tZPQKPsXVhNmbiGg53MN41 # System authorization information auth useshadow passalgo=sha512 # Use graphical install graphical firstboot disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux disabled # Installation logging level logging level=info # System timezone timezone Europe/Amsterdam # System bootloader configuration bootloader location=mbr clearpart --all --initlabel part swap --asprimary --fstype="swap" --size=1024 part /boot --fstype xfs --size=300 part pv.01 --size=1 --grow volgroup root_vg01 pv.01 logvol / --fstype xfs --name=lv_01 --vgname=root_vg01 --size=1 --grow %packages @^minimal @core %end %addon com_redhat_kdump --disable --reserve-mb='auto' %end
Create a PXE menu file (/var/lib/tftpboot/pxelinux.cfg/default), copy the following contents into the pxe menu file.
[root@pxe ~]# vi /var/lib/tftpboot/pxelinux.cfg/default default menu.c32 prompt 0 timeout 30 MENU TITLE LinuxTechi.com PXE Menu LABEL centos7_x64 MENU LABEL CentOS 7_X64 KERNEL /networkboot/vmlinuz APPEND initrd=/networkboot/initrd.img inst.repo=ftp://172.168.1.11/pub ks=ftp://172.168.1.11/pub/centos7.cfg
Step:6 Start and enable xinetd, dhcp and vsftpd service.
Use the beneath commands to start and enable xinetd, dhcp and vsftpd.
[root@pxe ~]# systemctl start xinetd [root@pxe ~]# systemctl enable xinetd [root@pxe ~]# systemctl start dhcpd.service [root@pxe ~]# systemctl enable dhcpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service. [root@pxe ~]# [root@pxe ~]# systemctl start vsftpd [root@pxe ~]# systemctl enable vsftpd Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service. [root@pxe ~]#
In Case SELinux is enabled, then set the following selinux rule for ftp server.
[root@pxe ~]# setsebool -P allow_ftpd_full_access 1 [root@pxe ~]#
Open the ports in the OS firewall using following firewall-cmd commands
[root@pxe ~]# firewall-cmd --add-service=ftp --permanent success [root@pxe ~]# firewall-cmd --add-service=dhcp --permanent success [root@pxe ~]# firewall-cmd --add-port=69/tcp --permanent success [root@pxe ~]# firewall-cmd --add-port=69/udp --permanent success [root@pxe ~]# firewall-cmd --add-port=4011/udp --permanent success [root@pxe ~]# firewall-cmd --reload success [root@pxe ~]#
Up to this point, PXE server installation and configuration is completed now.
Step:7 Boot the clients with pxe boot option.
As can see above that installation has been started with any human interaction. I hope you enjoy the installation and configuration of PXE server. Please share your feedback and comments.
Great article! Do you make could a tutorial about LTSP on the CentOS 7? Please, I can’t find anything that’s works. Will be a big help for me!
Peace!
Hello Eriston ,
Thanks for the comments, i will try to write a tutorial about LTSP on CentOS 7.x soon
Thank you for this! I have a quick question,
I have that working but I recently did a kernel update via yum and it seems like ‘uname -r’ still shows the old version. I believe I have to update the vmlinuz and initrd files on the tftp server, is that correct? How do I do that?
Hello , One has to reboot the system when the new kernel is installed. In case after reboot if ‘uname -r’ still shows old kernel version then recheck the grub config file and make the changes so that system boots with new kernel.
It is not recommended to update the kernel one should always install new kernel .
its great article thank you
I have followd your kickstart/pxe installation step by step but i have an error message:
fail to fetch kickstart from ftp://192.168.1.203/pub/ks.cfg
I need help please
Please check the selinux status, if it is enabled, write selinux rule for ftp. Apart from this also verify the firewall status.
I am also getting the same error (fail to fetch kickstart from ftp://192.168.1.102/pub/centos7.cfg) and I have selinux disabled. Please advise. Thank you
Resolved. centos7.cfg needs to have 755 permissions…
you didn’t do this step ?
[root@pxe ~]# openssl passwd -1 your_root_password goes here…
$1$e2wrcGGX$tZPQKPsXVhNmbiGg53MN41
[root@pxe ~]#
Thanks, its great article and also easy to understand !
How about showing us how to install different OS versions of Linux or even different OS distro’s using the method in this article. Not bad at all.
Also show how to do this without any human intervention. Besides that the whole idea of kickstart so you can do 100’s of servers or even VM’s at once. 🙂
Two issue
1)I am getting below error in message of vmware in linux 6 while boot pxe
sending nak (1 file not found) to 10.0.0.9
RRQ from 10.0.0.9 filename pxelinux/pxelinux.cfg/01-23-35-ao-cd-09
2)FTP server configure in windows 7 and getting error 550 file unavailable and the system cannot find the specified.
I captured the traffic nic of my windows 7 system and got this error in pcap.
someone can me help me.
Thanks for the simple, effective tutorial. If you are creating a VM, it needs to have more that 1GB (2GB works) of memory or you get a “no space left on device error”.
thanks a lot – spent hours on this “out of memory” problem.
After installing centos7 on the client machines, i had to reboot the client for it to completely install. However, it brought me back to the PXE boot up menu again. How do i stop this loop
Is it fixed now? I am also hitting the same issue.
I have followd your kickstart/pxe installation step by step after selecting PXE menu i am getting Blank white screen that not got process
I am having an issue that when I do this, the pxe menu displays, but I am unable to enter any keyboard input, the menu just freezes.
Good instructions and easy to follow. I would add a bit of description about the TFTP setup, as the permissions of the /var/lib/tftpboot directory can be problematic.
Hi ,
I followed the documentation , i can see the centos bluescreen and after that , it throws syntax error with kickstart file /var/ftp/pub/centos7.cfg in number 38 stating ( no such option –disable )
%addon com_redhat_kdump –disable –reserve-mb=’auto’
%end
is there any alternative syntax for this ??
thanks .. i have done
I have used these steps got successful
I was getting a Connection Timed Out when connecting to my PXE server. The instructions don’t specify to start and enable tftp. Doing that fixed that issue!
Hi. I need your help, I have the following problem when enabling a pxe client.
[15.477199] dracut-mount[1168]: Warning: Can’t mount root filesystem
[15.497028] dracut-mount[1168]: Warning: /dev/root does not exist
[15.501094] dracut-mount[1168]: /lib/dracut-lib.sh: line 1049: echo: write error: No space left on device
Starting Dracut Emergency Shell
Warning: /dev/root does not exist
Hi Rodrigo,
Please make sure the virtual machine or physical server has been assigned at least 2 GB of RAM.
hi pradeep
Thank you very much for your prompt response. The previous error has been fixed but now I have another problem.
The client pxe remains in the option to choose language. Then, I must press “continue” manually, and I must select hard drive and install.
Can you help me to make it automatic?
increasing to 3GB fixed this issue…:)
Hello,
This is works for me thanks for this, now I need to setup ubuntu-18.04 in same server.
for centos7 I coped :- /var/ftp/pub/centos7
for ubuntu-18.04 i coped :- /var/ftp/pub/ubuntu-18.04
allow this in selinux via :- semanage fcontext -a -t public_content_t “/var/ftp/pub/centos7(/.*)?”
restorecon -Rv /var/ftp/pub/centos7
semanage fcontext -a -t public_content_t “/var/ftp/pub/ubuntu-18.04(/.*)?”
restorecon -Rv /var/ftp/pub/ubuntu-18.04
I copy ubuntu kernel and initrd file in :- /var/lib/tftpboot/ubuntu-18.04
filesystem.manifest filesystem.manifest-remove filesystem.squashfs initrd.lz
filesystem.manifest-minimal-remove filesystem.size filesystem.squashfs.gpg vmlinuz
And My Default file entries : – /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 30
MENU TITLE MASTER HYDRA PXE Menu
LABEL CENTOS-7 INSTALLATION
MENU LABEL CentOS 7
KERNEL /centos7/vmlinuz
APPEND initrd=/centos7/initrd.img inst.repo=ftp://192.168.95.1/pub/centos7
LABEL UBUNTU-18.04 INSTALLATION
MENU LABEL UBUNTU-18.04
KERNEL /ubuntu-18.04/vmlinuz
APPEND initrd=/ubuntu-18.04/initrd.lz inst.repo=ftp://192.168.95.1/pub/ubuntu-18.04
Kindly tell me where I am Wrong
Hi there.
Tutorial is very usefeul, but… Does anyone know how to force PXE to work with HTTPS with no check certificate? I have used something like that:
APPEND (…) inst.repo=https://server.with.local.mirror
And curl complies that cert is unknown. In fact it is and cannot be another. I know i can use “-k” option to curl but where to place it? Is there any other option id PZE menu file, that allows https connections with no-check-certificate.
I’m asking here, because I’ve found nothing about that. I someone knows the answer, please help me.
Regards
Heh… good way to find solution for me is to ask someone the question. Nobody may answer but I _always_ find solution by myself 🙂
In this case solution is to add: `inst.noverifyssl’ option to APPEND row.
Maybe will be useful for next PXE warriors 🙂
Sorry for noise in ether.
Regards
dracut-initqueue[706]: Warning: dracut-initqueue timeout – starting timeout scripts
dracut-initqueue[706]: Warning: Could not boot.
dracut-initqueue[706]: Warning: /dev/root does not exist
Starting Dracut Emergency Shell….
Warning: /dev/root does not exist.
Did excatly what he did but adding live: after the ks= and inst.repo= .
Someone knows why ?
Thanks a lot!