HOWTO: setup a PXE Server with dnsmasq

To setup a PXE server with dnsmasq is really simple the second time 🙂 This is how I did mine on Ubuntu 12.04, but it should be similar on most Linux distros and versions.

Setup dnsmasq so it is providing DNS and DHCP first. See my How to setup dnsmasq for DNS and DHCP.

Decide where you are going to put the files for your PXE server. By files, I mean are the copies of the install CD/DVD, the menus and configuration for the tftp server. I put mine in /tftp and then in sub directories pxeboot and webroot. Create the empty directory structure now. From now on when I refer to pxeboot I mean /tftp/pxeboot and for webroot I mean /tftp/webroot. Also when I’m talking about https://localhost you can substitute the actual local host for a hostname or IP address. https://mypxe

We will be needing a working HTTP server I use Apache as it is already used for a number of other things on my Server/Nas machine. without further ado lets get on!

Install and setup Apache2

sudo apt-get install apache2

The web server should have it’s root directory pointing at /tftp/webroot. The simplest configuration file for this is as below, not very elegant but it will work for now.


 Require all granted


Alias           /webroot        /tftp/webroot

To test the basic http service use the url https://localhost you should see the default Apache web page.

To test the webroot directories, let’s create a simple index.html page and check it displays in a browser. Create the file /tftp/webroot/index.html with the following text. Save it so it is readable by everyone.

Default Webroot start page

;

This is the default web page for the webroot server.

The web server software is running but no content has been added, yet.

Now start or reload the Apache configuration if the server was already running, only really necessary when the server was not already running. [khakisample] sudo service apache2 start sudo service apache2 reload [/khakisample] In your browser use the URL https://localhost/webroot/ and you should see the text from the index.html you saved above. If you do not you did it wrong, please try again and follow all the steps in order. :-) One more thing to check, that wget is working as expected. go to your HOME directory and get the index.html file from webroot. The PXE booting process involves using wget to grab some initial files.
cd
wget https://localhost/webroot/index.html

The output should look something like this

$ wget https://localhost/webroot/index.html
--2011-07-17 09:51:35--  https://localhost/webroot/index.html
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5533 (5.4K) [text/html]
Saving to: `index.html'

100%[=====================================================>] 5,533       --.-K/s   in 0s      

2011-07-17 09:51:35 (178 MB/s) - `index.html' saved [5533/5533]

Configuration for dnsmasq for a tftp server

To change a working install of Dnsmasq to work as a PXE server we need to turn on a few settings.

Edit the file /etc/dnsmasq.conf to turn on the following options, see the comments in the file for what they do.

dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/tftp/pxeboot

reload the dnsmasq daemon to take the changes in to use.

sudo service dnsmasq restart

Creating the PXE server content

Download the latest Ubuntu installation DVD, not the Live CD. This needs to be copied into webroot. I have a subdirectory structure that allows for continuous expansion and makes it easy to update from one version to another.

/tftp/webroot
|-- 11.04
|   `-- x86_64
|       |-- casper -> img/casper
│       ├── boot
│       ├── casper
│       ├── dists
│       ├── doc
│       ├── EFI
│       ├── install
│       ├── isolinux
│       ├── pics
│       ├── pool
│       ├── preseed
│       └── ubuntu -> .
└── preseed
|-- 12.04
|   `-- x86_64
|       |-- casper -> img/casper
│       ├── boot
│       ├── casper
│       ├── dists
│       ├── doc
│       ├── EFI
│       ├── install
│       ├── isolinux
│       ├── pics
│       ├── pool
│       ├── preseed
│       └── ubuntu -> .
└── preseed

Note: the ASCII art for the directory structure was the output from 'tree -d -L 5'

Mount the Ubuntu install DVD and copy everything over to the img directory for the correct release (u11.04, u12.04) and architecture X86_64. I only use X86_64 now. You will need to mount the iso image, see my really short mini howto for that.

While that is copying over we can create the PXE server stuff in pxeboot. Create a subdirectory /tftp/pxeboot/boot and then another subdirectory under that for the release of Ubuntu, (u11.04, u12.04). Rather then copy the PXE boot files over again make a symbolic link back to the casper subdirectory from the directory structure above. In my case I use:

ln -s ../../webroot/ubuntu12.04/img/casper ubuntu12.04

Create another subdirectory under /tftp/pxeboot this time called pxelinux.cfg. This will hold your menu configuration files.
Now get a copy of pxelinux.0 this can be found in the directory img/install/netboot/pxelinux.0. Also pull over a copy of the file vesamenu.c32 you can get this from img/install/netboot/ubuntu-installer/amd64/boot-screens/vesamenu.c32.

In this example we are work with Ubuntu 12.04, the current LTS version, lets create a simple menu to boot up from.

Using PXElinux it will eventually load the pxelinux.0/default. A quick and dirty one option menu would be

UI vesamenu.c32

LABEL u12.04_desktop
        MENU LABEL ^1) Install Desktop
	KERNEL boot/ubuntu12.04/linux
	APPEND url=https://mypxe/webroot/ubuntu12.04/preseed/desktop.cfg hostname=desktop-test vga=788 initrd=boot/ubuntu12.04/initrd.gz locale=en_GB.UTF-8 console-setup/ask_detect=false keyboard-configuration/layoutcode=gb domain=example.com --

NOTE: The last line, APPEND, must be all on one line.

Useful links

One thought on “HOWTO: setup a PXE Server with dnsmasq

Leave a Reply

Your email address will not be published. Required fields are marked *