How-To boot from LAN with a PXE Environment
This guide will try to show you how to "boot from LAN" a workstation that has no CD/DVD Drive, and is not capable to boot from usb device too. This way you could boot a live Linux CD image and do a subsequent install over the phisical HDD or simply use that Linux distribution with thinclients, which are usually diskless. Let's split this tutorial in two parts, one for the server building and one for the client setup; for semplicity we can start talking about the client .. so let's begin with requirements:
CONFIGURING A PXE CLIENT
REQUIREMENTS:
In order to boot from the Local Area Network the workstation must be equipped with a Network Controller which supports PXE; moreover the motherboard has to be ready for booting from the NIC itself (modern motherboard usually have an onboard LAN NIC and are fully capable of booting from them, but for old PC, like Pentium III or so, you may encounter some difficulties: e.g., even if you got a relatively new PCI NIC, which supports PXE, the motherboard could not be able to boot from lan anyway). So, if your PC can boot from LAN and your NIC is PXE capable, you're ok so far (client part is just done) ..If your PC cannot boot from LAN, but you've got a PCI PXE NIC, there is still one option to get booting done; ohoh, this last chance provides one more requirement: a ( working =)) floppy drive !
There's an opensource project, called gPXE, which provides the software needed to boot from a standard PXE Environment: me myself discovered all these informations today, so i'm not expert about it; what i can say you is that pointing your browser to "http://rom-o-matic.net/gpxe/gpxe-1.0.0/contrib/rom-o-matic/" you can download a boot floppy image with gPXE.
gPXE will load your Network Card driver and enable it in order to boot from lan; instructions follow:
Find the name or the device ID and vendor for your NIC:
$lspci -nn
Select the appropriate driver for your NIC on the dropdown box and download the floppy bootable image (.dsk). Then we're going to format a floppy and 'cat' the image into it:
$ mkfs.vfat /dev/fd0 #If you're Linux Box doesn't provide this command, probably you must install the dosfstools
$ cat floppy_image_name.dsk > /dev/fd0
Floppy is ready; once you reboot your PC, make sure it's configured to boot from floppy (you have to enable this option in the BIOS: consider reading the motherboard manual if you don't know how to do it): the floppy will load gPXE, activate your Network Card and provide support for PXE booting. That's it; client side is ready to go.
BUILDING A BOOT PXE SERVER
Some considerations before we begin: if your needs are only those to boot a live cd (let's say you have to do some extra maintainance which requires an halted/non running system) then you could try with some distributions that kindly offers a builtin PXE server; in my little experience i can say that there are at least three choices:
- Knoppix # works perfectly even using gPXE
- Slax
- Trinity Rescue Kit
I tried all of them, but slax and TRK didn't work as expected using gPXE, while they're fine with a standard PXE client (in this case i used two VirtualBox Machines for the server and the client side, without any problem). I'm going to suggest using knoppix, which is also one of the major and appreciated live distribution you may find; moreover it offers a 'standard' linux environment, while slax and TRK are, in my opinion, 'hacked' systems (you know, personalization makes the differences). So, once you've got your free copy of Knoppix, started it and verified your network is up & running, you can start the 'Terminal Server' (which is nothing other than a PXE server) from the main Menu - Preferences. Follow the simple instructions on screen and the server will be up. Now comes the cool part:
"BUILDIND YOUR OWN PXE SERVER"
In this tutorial i will use Debian Squeeze as Operating System and ADRIANE-KNOPPIX_V6.2.1 as the image to boot.
Things we need:
- A TFTP Server
- A DHCPD Server
- An NFS Server
- syslinux
Let's install those packages first:
# apt-get install tftpd-hpa dhcp3-server nfs-common nfs-kernel-server syslinux
The process of booting from LAN is a kind of:
The client starts a Dhcp request to obtain a valid IP Address. The dhcpd server assign an IP in his scope and pass extra parmaters to the client, such as the address of the FTPT server and the initial filename to request from the TFTP server. Once the client has this information, it will contact the TFTP server, download the file and load that file in memory: this kind of process will make it possible, at the end of the story, to boot a kernel image. Finally the client will connect to an NFS share in order to access the remaing files needed to the kernel itself to perform a complete boot.
First step: TFTP
# nano /etc/default/tftpd-hpa
The file reads as follow:
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"
No need to change anything, apart from the TFTP_DIRECTORY if you're not satisfied; i set it toTFTP_DIRECTORY="/home/tftp" as i had more free space left on that device. The binding address could eventually be changed to the private 'static' ip address of your machine, like:
TFTP_ADDRESS="192.168.0.100:69"
Restart the service when you're done with the configuration:
# /etc/init.d/tftpd-hpa restart
Second Step: DHCPD
# nano /etc/dhcp/dhcpd.conf
The rilevant parts to be modified are:
option domain-name "localdomain"; #Your Domain Name here, like 'example.org'
option domain-name-servers 8.8.8.8; #DNS server address to be passed at the client (could be an internal or esternal one; this is Google DNS)
default-lease-time 600; #Time in seconds before the dhcp lease will expire
max-lease-time 7200;
authoritative; #Make this dhcp server authoritative for your network: you need to disable other DHCPD running servers to avoid problems.
subnet 192.168.0.0 netmask 255.255.255.0 { #Network address your dhcpd will work on, and relative netmask range
192.168.0.101 192.168.0.110; #DHCPD scope: range of IP addresses it will use when assigning them upon clients' requests
option domain-name-servers 8.8.8.8; #Same DNS
option domain-name "localdomain"; #Same Domain Name
filename "gpxelinux.0"; #Filename the client will expect to download from the TFTP Server
next-server 192.168.0.100; #IP Address of the TFTP Server (in this scenario the same machine will act as DHCPD, TFTP, NFS Server)
option routers 192.168.0.254; #IP Address of your gateway, to make the client connected to the internet.
option broadcast-address 192.168.0.255; #Broadcast address of your network
default-lease-time 600;
max-lease-time 7200;}
Restart the dhcpd server
# /etc/init.d/isc-dhcp-server restart
Now we must prepare the files in the TFTP home: the final directory will look like this ..
root@PXE:/home/tftp# ls -l
totale 7404
-r--r--r-- 1 root root 93 17 ott 02.28 boot.msg
-r--r--r-- 1 root root 256 17 ott 02.28 german.kbd
-r--r--r-- 1 root root 89513 17 ott 01.58 gpxelinux.0
drwxr-xr-x 3 root root 4096 17 ott 02.41 knoppix
-r--r--r-- 1 root root 18050 17 ott 02.28 logo.16
-r--r--r-- 1 root root 3893888 17 ott 02.34 miniroot.gz
drwxr-xr-x 2 root root 4096 17 ott 02.20 pxelinux.cfg
-r--r--r-- 1 root root 3545232 17 ott 02.34 vmlinuz
You can copy the 'boot.msg, german.kbd, logo.16' files from the Knoppix cd, located under "\boot\isolinux". Create a knoppix directory (this is useful if you decide to keep more images available for the clients) and copy inside it the KNOPPIX directory located in the root of the Knoppix CD. Copy the gpxelinux.0, or alternatively, the pxelinux.0 from /usr/lib/syslinux/ of the PXE Server (they are part of the syslinux package we installed at the beginning). Then you need the initrd and the kernel file (miniroot.gz and vmlinuz) which you can take from a running Knoppix distro (maybe using a Virtual Machine). Finally we must instruct pxelinux about what system it's going to boot; so, create a pxelinux.cfg directory, cd into it and touch a new file named 'default'; it's content will look like this:
DEFAULT vmlinuz
APPEND nfsdir=192.168.0.100:/home/tftp/knoppix nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=791 initrd=miniroot.gz quiet BOOT_IMAGE=knoppix
TIMEOUT 300
PROMPT 1
DISPLAY boot.msg
LABEL knoppix
KERNEL vmlinuz
APPEND nfsdir=192.168.0.100:/home/tftp/knoppix nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=791 initrd=miniroot.gz quiet BOOT_IMAGE=knoppix
LABEL knoppix-txt
KERNEL vmlinuz
APPEND nfsdir=192.168.0.100:/home/tftp/knoppix nodhcp lang=us ramdisk_size=100000 init=/etc/init apm=power-off nomce vga=normal initrd=miniroot.gz BOOT_IMAGE=knoppix
As you can see we're going to specify some things like the initrd and the kernel image mentioned above (keep the filenames coherent) and we APPEND the last useful information each client needs: an NFS directory. So let's configure NFS as the last step.
# nano /etc/exports
Add a line like the following:
/home/tftp/knoppix 192.168.0.0/24(async,ro)
This will instruct our NFS Server to public the /home/tftp/knoppix directory over the network and make it available to the client (in this case all the clients which are part of the 192.168.0.0/24 network). If you make changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command:
# exportfs -a
That's all, i think: time to boot your client from PXE; if it's all gone as expected, you'll first see a dhcp request from the client and then, just after some seconds, the main boot logo screen of Knoppix: enter 'knoppix' at the command line prompt and there you go !