13 February 2012

HOWTO: Boot Linux from network using PXE and DNSMASQ proxy

This tutorial allows to boot and install Linux from network using PXE and DNSMASQ.

DNSMASQ is a very light implementation of TFTPD,DHCPD and NAMED.

In most of the cases there is already a DHPCD server on the network and starting a new DHCPD server would not work.
Therefore we are going to configure DNSMASQ as a PROXY DHCPD for the existing server and specify what PXE service to use.

The example provides a menu that can install RedHat 5, RedHat 6 and also can start the Memtest utility from the network.

Configure SYSLINUX

Install syslinux
yum install syslinux

Create a folder for TFTP server with the following (similar) structure
mkdir -p /tftboot/pxelinux.cfg
mkdir -p /tftboot/images/rhel/x86_64/5
mkdir -p /tftboot/images/rhel/x86_64/6

Copy the necessary files from syslinux
cp /usr/share/syslinux/menu.c32 /tftboot
cp /usr/share/syslinux/pxelinux.0 /tftboot

Copy initrd.img and vmlinuz from the original ISO
cp /mnt/rhel5/images/pxeboot/initrd.img /tftboot/images/rhel/x86_64/5
cp /mnt/rhel5/images/pxeboot/vmlinuz /tftboot/images/rhel/x86_64/5

cp /mnt/rhel6/images/pxeboot/initrd.img /tftboot/images/rhel/x86_64/6
cp /mnt/rhel6/images/pxeboot/vmlinuz /tftboot/images/rhel/x86_64/6


Download and copy memtest from memtest.org
cp ~/Downloads/memtest86+-4.20.bin /tftboot/memtest


Create and edit /tftboot/pxelinux.cfg/default file
The IP 192.168.1.201 can be changed to reflect the path to your installation files

default menu.c32
prompt 0

menu title PXE Boot Menu

label rhel5-x86_64
    menu label rhel5-x86_64
    kernel images/rhel/x86_64/5/vmlinuz
    append initrd=images/rhel/x86_64/5/initrd.img method=nfs:192.168.1.201:/mnt/rhel5 lang=us keymap=us ip=dhcp noipv6

label rhel6-x86_64
    menu label rhel6-x86_64
    kernel images/rhel/x86_64/6/vmlinuz
    append initrd=images/rhel/x86_64/6/initrd.img method=nfs:192.168.1.201:/mnt/rhel6 lang=us keymap=us ip=dhcp noipv6

label memtest86
    menu label memtest86
    kernel memtest
    append -


If you like a VESA menu instead of the text mode, change menu.c32 with vesamenu.c32 (after you have copied it from /usr/share/syslinux).


Configure DNSMASQ

Install dnsmasq
yum install dnsmasq

Create and edit /etc/dnsmasq.d/pxe.conf with the following content
The IP 192.168.1.201 should be the IP of the machine that runs DNSMASQ

tftp-root=/tftpboot
enable-tftp
dhcp-boot=pxelinux.0
dhcp-option=vendor:PXEClient,6,2b
dhcp-no-override
pxe-prompt="Press F8 for boot menu", 3
pxe-service=X86PC, "Boot from network", pxelinux
pxe-service=X86PC, "Boot from local hard disk", 0
dhcp-range=192.168.1.201,proxy

Edit /etc/dnsmasq.conf and check you have a line at the of the file similar to this:
conf-dir=/etc/dnsmasq.d

Start dnsmask
/etc/init.d/dnsmasq restart

Boot a machine using the network option from BIOS and install your system or run memtest!

2 comments:

  1. Thank you, this is very helpful. I found a typo, an extra "L" in "menul label memtest86".

    ReplyDelete