23 August 2012

Boot winxp from http server

Traditional PXE booting uses TFTP for loading the image file. The TFTP is simple protocol and based on UDP so it has some dis-advantages as slow speed, not reliable, not WAN capable, maybe blocked by firewall. While GPXE is a modern way to boot from network, it does support loading the image file from http, ftp, iscsi ... which based on TCP protocol. By that way GPXE gains of high speed, reliable and can be used in WAN (internet) network. 

This post will show you how to boot winxp from an http server by using GPXE bootloader.

Topology :

gPXE topo.
This post will use the upper topology when deploying. In this topo :
  • The GPXE Server uses Linux (CentOS) and installed with : 
    • dnsmasq : this will supply DHCP and TFTP service. 
    • syslinux : this will supply the GPXE module. 
    • nginx : this will supply http web service. 
  • The PCs has NIC with bootrom support PXE. Can have internal harddisk or not.

Requirement :

Suppose that you have already known how make a vhd disk image which includes winxp, and how to load the image into ram memory. Take these articles for detail guidance : Run WinXP in RAM memory

Boot process :

  • The PC startup, do POST and chose NIC as boot device. The PC broadcast an DHCP request to require an IP address. 
  • The Server (dnsmasq) recieve the DHCP request. Then reply with an IP address (not used) and the information of the boot server (name of bootfile and IP address of boot server, in this case it is the same IP addess.) 
  • The PC receives the respond DHCP and set itself to use the IP address. The PC base on information of boot server than make an TFTP request to download the GPXE module. 
  • The Server (dnsmasq) receives the TFTP request for the GPXE module file. The server than respone with that file. 
  • The PC download than execute the GPXE module. GPXE then load the config file from server (default). Base on the config file, GPXE then download the winxp image and grub4dos by http protocol. 
  • GPXE than execute grub4dos to map the winxp image to memory than boot the ntldr.

Primary steps :

  1. Install and config DHCP/TFTP service. 
  2. Install and config GPXE module. 
  3. Install and config HTTP service. 
  4. Boot the PC.
Steps in detail :

1. Install and config DHCP/TFTP service.

Check if the server has installed with dnsmasq. If not, install it.

Server# yum install dnsmasq

========================================================================
Package Arch Version Repository Size
========================================================================
Installing:
dnsmasq x86_64 2.59-5.fc17 fedora 168 k
Transaction Summary
========================================================================
Install 1 Package
Total download size: 168 k
Installed size: 336 k
Is this ok [y/N]:y

Config the service dnsmasq : IP ranges will use for DHCP. Enable TFTP service. Name of the bootfile.

Server# vim /etc/dnsmasq.conf

dhcp-range=192.168.100.1,192.168.100.10,12h
dhcp-boot=gpxelinux.0
enable-tftp
tftp-root=/var/ftpd
log-queries
log-dhcp

Start the service.

Server# service dnsmasq start

Check if the service open listen port.

Server# netstat -pnatu | grep dnsmasq

tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN
tcp6 0 0 :::53 :::* LISTEN
udp 0 0 0.0.0.0:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 0.0.0.0:69 0.0.0.0:*
udp6 0 0 :::53 :::*
udp6 0 0 :::69 :::*

The DHCP port listen at udp:67 and TFTP listen at udp:69.

2. Install and config GPXE module.

Check if the server has installed with dnsmasq. If not, install it.

Server# yum install syslinux

========================================================================
Package Arch Version Repository Size
========================================================================
Installing:
syslinux x86_64 4.05-1.fc17 fedora 1.0 M
Transaction Summary
========================================================================
Install 1 Package
Total download size: 1.0 M
Installed size: 2.3 M
Is this ok [y/N]: y

Find the module gpxelinux.

Server# rpm -ql syslinux | grep gpxelinux

/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/gpxelinuxk.0

we will use the file gpxelinux.0. Copy that file to folder /var/ftpd/

When executed, GPXE will search for its config file at pxelinux.cfg/default.

We need to create them at /var/ftpd.

Server# mkdir /var/ftpd/pxelinux.cfg

Create the default file to load the winxp image and grub.exe.

Server# vim /var/ftpd/pxelinux.cfg/default

prompt 1
LABEL gpxelinux
kernel http://192.168.100.254/grub.exe
initrd http://192.168.100.254/MiniXP350.gz
APPEND --config-file="map (rd)+1 (hd0); map --hook; chainloader (hd0,0)/ntldr"

3. Install and config HTTP service.

Check if the server has installed with nginx. If not, install it.

Server# yum install nginx

========================================================================
Package Arch Version Repository Size
========================================================================
Installing:
nginx x86_64 1:1.0.15-4.fc17 updates 388 k
Transaction Summary
========================================================================
Install 1 Package
Total download size: 388 k
Installed size: 1.1 M
Is this ok [y/N]:

Config the nginx to point to folder /var/ftpd and enable browsing file on.

Server# vim /etc/nginx/nginx.conf

location / {
root /var/ftpd;
autoindex on;
}

Starting the nginx service.

Server# service nginx start

Check if the nginx opens listen port.

Server# netstat -pnatu | grep nginx

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

Now we need the minimal-winxp vhd disk image and grub.exe place at folder /var/ftpd.

For grub.exe, download grub4dos and extract grub.exe to that folder.

For minimal-winxp image, follow here (Run WinXP in RAM memory) to see how to make it.

When got the MiniXP350.vhd, gzip it to make it smaller to faster transfering later.

Server# gzip -9 -c /var/ftpd/MiniXP350.vhd > /var/ftpd/MiniXP350.gz

Server# ls -alhs /var/ftpd/MiniXP350.*

211M -rw-r--r-- 1 root root 211M Aug 23 15:08 /var/ftpd/MiniXP350.gz
351M -rw-r--r-- 1 root root 351M Aug 20 16:39 /var/ftpd/MiniXP350.vhd

After compression, the image file is about 211MB. This is good enough for transfer by http.

At this time, we have enough needed files for working. They are all stay at /var/ftpd/

Server# find /var/ftpd/

/var/ftpd/
/var/ftpd/MiniXP350.gz
/var/ftpd/MiniXP350.vhd
/var/ftpd/grub.exe
/var/ftpd/pxelinux.cfg
/var/ftpd/pxelinux.cfg/default
/var/ftpd/gpxelinux.0

Use a web browser connecting to the url http://192.168.100.254/ to check if nginx has work.

Check the nginx server

And it works fine.

Next to Part 2 >>