How to Setup a PXE Server on Ubuntu

Published: 22 Mar 2013

This post shows you how to setup a PXE (Preboot execution environment) server on Ubuntu. It assumes a fresh install of Ubuntu 12.04 and at least two machines. One acting as the PXE server and another as the client with a PXE-supported firmware. The following will be installed on the server:

  1. tftp-hpa - (trivial file transfer protocol) is used in conjunction with dhcp for the automated transfer of bootstrap/configuration files.
  2. dhcp - used to locate the appropriate boot server
  3. nginx - serves the kickstart file and install files for one or more client(s)

tftp-hpa setup


sudo apt-get update
sudo apt-get -y install tftpd-hpa
sudo /etc/init.d/openbsd-inetd stop
sudo update-rc.d -f openbsd-inetd remove
sudo sed -i s/no/yes/ /etc/default/tftpd-hpa
sudo /etc/init.d/tftpd-hpa start

add the following to /etc/default/tftpd-hpa:

OPTIONS="-l -s /var/lib/tftpboot" 

now restart tftpd-hpa

sudo /etc/init.d/tftpd-hpa restart

dhcp setup

install dhcp server:

sudo apt-get -y install dhcp3-server

edit /etc/dhcp/dhcpd.conf and add the following:

subnet netmask {
  filename "pxelinux.0";

For the purposes of this tutorial, the following are used:

start the dhcp server:

sudo service isc-dhcp-server start

inetd setup


sudo apt-get install inetutils-inetd

edit /etc/inetd.conf and add the following:

tftp    dgram   udp    wait    root    /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot

You may need to change udp to udp4 above if you're using IPv6.

copy install files

Now it's time to copy the files from the Ubuntu install disk. In my case, I'm using a thumb drive so I install the usbmount package in order to have the thumb drive automatically mounted with I plug it in:

sudo apt-get install usbmount

At this point, I plug in the thumb drive and it should be available at /media/usb.

sudo cp -r /media/usb/install/netboot/* /var/lib/tftpboot/



sudo apt-get install nginx

I had an issue with installs until I commented the following line in the nginx configuration:

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    # comment this --> try_files $uri $uri/ /index.html;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules

By commenting the try_files $uri $url/ /index.html; line above, nginx will return a 404 instead of falling back to /index.html.

The default document root will be: /usr/share/nginx/www.

Create a directory for ubuntu and copy the install files from the thumb drive:

mkdir -p /usr/share/nginx/www/ubuntu
cp -r /media/usb/* /usr/share/nginx/www/ubuntu/

customizing via kickstart

create /usr/share/nginx/www/ks.cfg with the following contents:

url --url

The above is a minimal kickstart configuration and you can augment it to fully automate installs.

create/edit /var/lib/tftpboot/pxelinux.cfg/default and add the following:

default linux
prompt 0
timeout 60

label linux
    menu default
    menu label Linux
    kernel ubuntu-installer/amd64/linux
    append ks= vga=normal initrd=ubuntu-installer/amd64/initrd.gz ramdisk_size=16432 root=/dev/rd/0 rw  --

You should now be able to start a client machine up, hit something like F12 to boot via PXE and be on your way!