What is PXE?
PXE stands Preboot Execution Environment. Usually, to install a computer, you would make use of an installation CD, or a bootable USB drive, but in a datacenter, where you have hundreds of computers/servers, it is not very viable to install each server individually using a USB drive. This is where PXE comes in. A PXE boot allows computers to be installed via a network. PXE makes use of DHCP and TFTP protocols, which are standard across all devices. On the client side, the only requirement is a PXE enabled NIC. One can also customize the operating system that is installed on the clients with a few changes on the PXE servers, and that is why it is one of the most popular choices for mass-installation and deployments of operating systems on servers.
Step-by-step guide
Assumption: You already have a DHCP server on your network which allows you to set PXE boot parameters. If not, you can install a DHCP server on the PXE server using a guide online.
- Install the required packages
sudo apt-get install inetutils-inetd tftpd-hpa apache2
- Edit the
/etc/default/tftpd-hpa
file and add the following lines at the bottom to enable the TFTP server:RUN_DAEMON="yes" OPTIONS="-l -s /var/lib/tftpboot"
- Edit the
/etc/inetd.conf
file and add the following line at the bottom:udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
If you are using IPv6, change udp to upd4
4. Restart the TFTP service
sudo systemctl restart tftpd-hpa
5. Make a Ubuntu directory in your Apache root
mkdir /var/www/html/ubuntu
6. Mount the Server Image
mount -o loop /path/to/ubuntu/iso
7. Copy all the netboot file to the TFTP root
sudo cp -fr /mnt/install/netboot/* /var/lib/tftpboot/
8. Copy all the Ubuntu image files to the Ubuntu directory
sudo cp -fr /mnt/* /var/www/html/ubuntu/
9. Change permission of the default menu file, just in case (I experienced issues)
chown root:root /var/lib/tftpboot/pxelinux.cfg/default
chmod 777 /var/lib/tftpboot/pxelinux.cfg/default
- Add the following lines to the
/var/lib/tftpboot/pxelinux.cfg/default
file
label <Enter your label here>
kernel ubuntu-installer/amd64/linux
append ks=http://<IP Address>/ks.cfg vga=normal initrd=ubuntu-installer/amd64/initrd.gz
ramdisk_size=16432 root=/dev/rd/0 rw --
- To generate a kickstart file, you can use
system-config-kickstart
package, which offers a GUI to create a customized kickstart file, or you can find documentation online - Ensure that on our DHCP server, bootp options are enabled, the PXE server is set to the next-server, and the file name is
pxelinux.0
You should now have a working PXE Server serving an Ubuntu image!