How to install PXE Server on Ubuntu 16.04

If you’re a System administrator, you happen to install many operating systems very often on your lab or workplace. Sometimes, you might fed up with installing OS on multiple systems everyday. Wouldn’t be better if you could install OS on multiple systems at a time?  This is where PXE server comes in handy. PXE, abbreviation of preboot execution environment, allows us to deploy operating systems on multiple systems automatically at a time in the network. Also PXE server helps you to install an OS in a remote system that doesn’t have any options for CD/DVD or USB drives.

In this tutorial, we will see how to install PXE Server on Ubuntu 16.04 LTS server, and how to configure it to deploy operating systems in the pxe client systems.

Install PXE Server on Ubuntu 16.04 LTS server

I tested this guide on Ubuntu 16.04 LTS 64 bit server. However, the steps might work on Debian and its derivatives.

In order to setup PXE server, you need to have a working DHCP and TFTP servers. DHCP server is used to distribute the IP addresses for the network systems, so that the client systems can communicate with PXE server. And, TFTP server is used to download the installation files from PXE server and send them to the PXE clients. We can deploy PXE, and DHCP servers on the same system or use different systems for each server. Due to lack of resources, I have tested this on a single system. You can either use a separate system or single machine for all servers. Choice is yours.

Let’s get started. First, we need to setup DHCP server.

To install DHCP server on Ubuntu, refer the following link.

Once you installed DHCP server, install PXE server along with TFTP and other dependencies using command:

sudo apt-get install apache2 tftpd-hpa inetutils-inetd
Install PXE server

Install PXE server

PXE server has been installed. Let us go ahead and configure it.

Configuring PXE server

Edit file /etc/default/tftpd-hpa file using your favourite editor:

sudo nano /etc/default/tftpd-hpa

Add the following lines at the end of the file to enable TFTP server.

OPTIONS="-l -s /var/lib/tftpboot"
Configure PXE server

Configure PXE server

Edit /etc/inetd.conf file:

sudo nano /etc/inetd.conf

Add or modify the following line at the end:

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

Please note that If you use IPv6, you need to change the word udp to udp4.

Save and close the file.

Finally restart tftp service to take effect all changes.

sudo systemctl restart tftpd-hpa

Check if tftp service is running or not with command:

sudo systemctl status tftpd-hpa

Sample output:

● tftpd-hpa.service - LSB: HPA's tftp server
 Loaded: loaded (/etc/init.d/tftpd-hpa; bad; vendor preset: enabled)
 Active: active (running) since Mon 2016-08-08 14:49:30 IST; 1min 47s ago
 Docs: man:systemd-sysv-generator(8)
 Process: 3867 ExecStop=/etc/init.d/tftpd-hpa stop (code=exited, status=0/SUCCE
 Process: 3879 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUC
 Tasks: 1
 Memory: 152.0K
 CPU: 63ms
 CGroup: /system.slice/tftpd-hpa.service
 └─3890 /usr/sbin/in.tftpd --listen --user tftp --address [::]:69 --se

Aug 08 14:49:30 ubuntuserver systemd[1]: Stopped LSB: HPA's tftp server.
Aug 08 14:49:30 ubuntuserver systemd[1]: Starting LSB: HPA's tftp server...
Aug 08 14:49:30 ubuntuserver tftpd-hpa[3879]: * Starting HPA's tftpd in.tftpd
Aug 08 14:49:30 ubuntuserver tftpd-hpa[3879]: ...done.
Aug 08 14:49:30 ubuntuserver systemd[1]: Started LSB: HPA's tftp server.

ostechnix@ubuntuserver: ~_003

As you see in the above output, tftp service is running.

Copying Ubuntu Installation files to the PXE Server

The configuration part is over. Next we need to copy the installation files to the PXE server.

Mount the Ubuntu installation ISO that you want to deploy on the client systems. Or, If you have installation DVD, copy all contents of the media to the PXE server.

For the purpose of this tutorial, we are going to deploy Ubuntu 16.04 LTS 64 bit version in our PXE clients. To do so, mount the Ubuntu 16.04 ISO in any location of your choice. I am going to mount it on /mnt/ directory.

sudo mount -o loop ubuntu-16.04-server-amd64.iso /mnt/

Now, go to the location where you mounted the (/mnt/ in our case) and copy the bootable installation files to /var/lib/tftpboot/ directory of our PXE server.

cd /mnt/
sudo cp -fr install/netboot/* /var/lib/tftpboot/

ostechnix@ubuntuserver: -mnt_004

We have copied all necessary bootable files. Next create a directory called ubuntu in the apache root document folder.

sudo mkdir /var/www/html/ubuntu

Now, copy all the files from the Ubuntu ISO using command:

sudo cp -fr /mnt/* /var/www/html/ubuntu/

ostechnix@ubuntuserver: -mnt_005

Next edit /var/lib/tftpboot/pxelinux.cfg/default file:

sudo nano /var/lib/tftpboot/pxelinux.cfg/default

Add the following contents at the end depending upon the distribution architecture you use.

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  --

ostechnix@ubuntuserver: -mnt_006

Here is my PXE server’s IP address. Replace this IP address with your pxe server’s address.

For 32bit PXE clients, you need to add the following lines:

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

Again, replace the IP address with your own.

Save and close the file.

Configuring DHCP Server settings

Go to your DHCP server and do the following changes. Remember I use the same server for PXE and DHCP server.

Edit /etc/dhcp/dhcpd.conf file:

sudo nano /etc/dhcp/dhcpd.conf

Add the following lines at the end:

allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
filename "pxelinux.0";

ostechnix@ubuntuserver: -mnt_008

Replace the IP address with your own.

Save and close the file.

Restart DHCP server to take effect the changes.

sudo systemctl restart isc-dhcp-server

If you have come this far, congratulations! Your PXE server is ready to use.

Install OS on PXE clients

It is time to deploy OS on pxe clients. Make sure you have enabled PXE boot option in your client system’s BIOS settings.

For the demo purpose, I will show you how to deploy OS on pxe client in Virtualbox. You can use either physical system or virtual machine.

Open Oracle VirtualBox, and Click New to create a guest machine.

Enter the Virtual machine name and select architecture.

Create Virtual Machine_010

Specify the virtual machine’s RAM size.

Create Virtual Machine_011

Select “Create a virtual hard drive now” to create hard disk for our virtual machine.

Create Virtual Machine_012

Select the type of file that you would like to use for the new virtual hard disk.

Create Virtual Hard Disk_013

Choose whether the new virtual hard drive file should grow as it is used or if it should be created as fixed size.

Create Virtual Hard Disk_014

Enter the name of the virtual hard disk file and specify the size of the virtual hard disk.

Create Virtual Hard Disk_015

Our Virtual Client machine has been created now.

Next, go to the newly created virtual machine’s settings and chnage the boot order.

To do so, select the virtual machine and click Settings icon on the menu bar.

Oracle VM VirtualBox Manager_016

From the System tab, choose Network as first boot device.

Ubuntu 16.04 LTS pxe client - Settings_017

Next, click Network tab on the left, and select “Bridged Adapter” from the “Attached to” drop down box.

Ubuntu 16.04 LTS pxe client - Settings_018

Finally, click OK and start the virtual machine.

Ubuntu 16.04 LTS pxe client [Running] - Oracle VM VirtualBox_019

That’s it. Start installing Ubuntu in your pxe client just like you do in the normal system.


I hope this guide will give a basic idea about what is PXE server, how to install and configure it in a local area network, and how to deploy OS on the PXE clients. For your information, I have covered only the basic part. PXE server is vast topic. We can’t cover all details in a single tutorial. Also, I have only tested Ubuntu PXE client. As you might know, using a single PXE server, we can deploy different flavours of Linux distros. I will write about multi-distribution deployment using a single PXE server in the days to come.

That’s all for today. I will be here soon with another interesting article. Until then, stay tuned with OSTechNix.



You may also like...

  • Think Strategy

    I do have some questions regarding this tutorial.

    1. My router is handling the ip addresses. Can i install the PXE-Server without DHCP on my Linux Ubuntu Server?

    2. I have couple of months ago installed Windows Server 2012 in Virtualbox (using PHPVirtualbox) for the reason to have WDS. In case of wanting to install a Linux distro there is no problem because i would have Windows Server 2012 offline. However if i want to have a Windows version installed using WDS, will this collide with PXE-Server? If so which i ASSUME, i just have to shutdown PXE-Server for the time being right?

    sudo systemctl stop tftpd-hpa

    In the back of my mind, i know the answer to the second question, but i want to be sure of the answer. Regarding question 1 i seriously do not know if this is the case.

  • SK

    For the question number 1, I didn’t check PXE server with router. However, I assume we can do this by replacing the next-server IP address with your router IP. Check the “Configuring DHCP Server settings” section. I have mentioned the DHCP server IP as “next-server;”. May be you should replace this value to your router address and try.

    And for the question number 2, PXE server and WDS won’t collide with each other if you use different IP address. This is also my assumption. I am not sure, because I really have no idea about Windows. I couldn’t help you. Sorry.

    If you find any solutions, please share them here. I will update the tutorial with your points. SO that other users can also benefit. Thank you.

    • Think Strategy

      After you replied i had my suspicion about that it might not work, but i decided to try it first in a test-environment. Sadly my suspicions were right.

      The ip address you set up for the PXE-Server ( is also the DHCP-server. When you try to boot a client to it, it will ask for a ip address from an DHCP-Server which happens on port 67. Which off course the client will receive. However, when you configured ¨/etc/dhcp/dhcpd.conf¨, there you told the DHCP-Server if a client might ask for a PXE-Server it can be found on address (

      allow booting;
      allow bootp;
      option option-128 code 128 = string;
      option option-129 code 129 = text;
      filename “pxelinux.0”;

      In my case the situation is that the Linux Ubuntu Server does NOT have a DHCP-Server, so some other way needs to be setup to tell clients where to find the PXE-Server.

      In case of Microsoft WDS I THINK it broadcasts a package through out the network to find out which ip the WDS is having.

      Thanks anyway your tutorial is much more simple to configure and understand then other tutorials i read about PXE-Server.

      Gonna look on the web if there is a way to bypass this problem, if i find a way, ill let you know.

      • SK

        Good luck mate. Hope you find a solution.

        • Think Strategy

          Sk, Brother, i found a solution to the problem, although you need to make some HARDWARE/Software network configuration changes.

          (do keep in mind this is still a theory, because i have not yet test it in real life).

          In the case that we talked about

          allow booting;
          allow bootp;
          option option-128 code 128 = string;
          option option-129 code 129 = text;
          filename “pxelinux.0”;

          The next-server(PXE server) is being pointed at in the DHCP file, but this is being done on the machine that is running the DHCP-server in the case you described is also the PXE-Server. If you are running a router/machine on openWRT or whatever Linux machine as DHCP-Server, this could be achieved. This theoretically could be achieved in even using a Raspberry pi as the openWRT/Linux router as the DHCP-Server, because it could be on 24/7 and not really using a lot of energy.

          In my case, i have already ordered a few months ago Turris Omnia router running a modified version of OpenWRT, so this theoretically could be achieved.

          I still have to receive it, i´ll let you know if it indeed can be solved/is like my theory.

          • SK

            Thank you brother. I hope this solution will work. Once you got the solution, please let me know. I will update your notes in the article. Thanks again. Much appreciated.

  • Jeff6times7

    I followed all the instructions and when the installer began to download the installation components from a mirror, it failed because it couldn’t resolve the address of the mirror. I opened a shell and added my router’s IP address as an additional nameserver. As of now, it has installed the base system and I think there’s not much left in the installation process.

    • Ravi Shekhar Jethani

      I think you selected a country mirror. And by adding router’s IP address you are actually allowing access to the internet. So in your case all the installation files are coming from internet not the local LAN. Solution: While choosing mirror scroll to the top and manually enter the pxe server ip( for example on this page)

  • Tahir Muzaffar

    Please let me know what modification should i make in these commands if i want to install ununtu server text mode only?????
    label linux
    kernel ubuntu-installer/i386/linux
    append ks= vga=normal initrd=ubuntu-installer/i386/initrd.gz
    ramdisk_size=16432 root=/dev/rd/0 rw —

    • SK

      You don’t have to change anything. Just mount the Ubuntu server ISO and continue the installation. Ubuntu server OS doesn’t has any graphical DE.

  • Alhaji Abubakari Sadiq

    this is so nice.Thanks

  • ali

    When do you think you’ll publish a post on a multi distribution setup? This worked perfectly,, but keen to get a couple of distros and a nice menu for my lab

    • SK

      Glad It helped you. I will soon make a guide on a multi-distribution setup.

  • Geroo

    Anyone has any idea how to make this works for windows installation ??