In my last entry I showed how to make the Linux distro SystemRescueCD PXE bootable. In this entry I'm going to give you 2 examples of making boot images that you can boot over the network with PXE. The first image we are going to make is a bootable version of the Seatools diagnostic software to test hard drives from Seagate. The second image we are going to make is a generic dos bootable PXE image.
The images we make will be loaded by the syslinux bootloader. The installation and setup of syslinux was covered in the entry "Making SystemRescueCD PXE bootable".
The first image we are going to make one for Seatools. Seatools is diagnostic software given out by Seagate to test/fix their hard drives. To make a this image you will need access to a windows machine. Either boot into a windows virtual machine or just use a actual windows machine. First, go to the Seagate website and go to the support section. In there you will see the downloads section. Look for the software "Seatools for DOS". Follow the links to the download section. When offered the choice of text or graphical choose either one they both work. Now choose the "Floppy Diskette Creator" and download that to the windows machine. It will be a windows executable. This is what we will need to make the floppy disk for us.
The next thing we need to download is the software that will emulate a floppy disk drive for us. Download the free software called Virtual Floppy Drive for Windows. Unzip it and run the vfdwin.exe executable. Click the driver tab and click the Start button to load the virtual floppy driver. Then click the Drive0 tab. Click the Change button and select a drive letter to be the virtual floppy drive. Then click the Open/Create button and click the browse button. Type the name of an image file you want to make. Make sure you give the filename the extention .img. Then click the Open button to finish the selection. Media type should be 3.5 1.44MB. Disk type should be set to FILE. Then click the create button. Now, Run the Seatools software you downloaded and if it asks point it to the floppy drive. It might not ask. Just click the "Create Floppy" button. After its done writing click the close button under the Drive0 tab to finish the floppy image. Now take the .img file you just made and put it on the tftp server with the other PXE boot images you have. Edit your PXE boot menu and put in an entry for this image. Below is the entry for my syslinux PXE boot menu.
label seatools kernel memdisk append initrd=seatools.img floppy
On next boot you should be able to type "seatools" at the PXE boot prompt and seatools should load
Now lets look at creating a generic dos boot image. With this dos boot image you can do things like flash a bios of a machine that does not have a cdrom or floppy disk. You can run lots of dos programs you need right from the PXE boot prompt. First, we need to download a dos floppy disk image from somewhere. This is just generic dos boot disk made by using dd on linux to copy it to a file. Like "dd if=/dev/fd0 of=/tmp/floppy.img bs=10240". If you have a favorite dos floppy you can make an boot image of it with that last command. Then copy the image over to the tftp directory where the other images are and put in a boot menu item for it. It just might boot.
I choose to take an already made dos boot image and put my own software on it. I downloaded a clean version of a 2.88MB FreeDOS boot disk. It was made by a Sourceforge project called FreeDOS Odin. So go there and download one yourself. Save a copy of the downloaded image file somewhere so you can keep reusing it. Now we are going to add our own software to the dos boot disk image we just downloaded. I made a copy of my downloaded image and called it dosboot.img. We are going to mount that file and copy the files we need to the disk image. The example below will copy the file dosbin.exe as an example.
mkdir /tmp/dos
sudo mount -o loop dosboot.img /tmp/dos/
sudo cp dosbin.exe /tmp/dos
sudo umount /tmp/dos
Now copy the dosboot.img file back up to the tftp boot dir. Edit the PXE menu file and put in a new line for the DOS floppy image. Look at the example above for a reference. Save the file and boot your new PXE image.
Have you ever wanted to stop carrying those bootable floppy disks, cd-rom's, or usb drives everytime you want to install, test, update, or rescue a machine on your network? If you have a network with hundreds or thousands of computers it's a pain to be lugging usb drives or cd-rom's to boot one if they need a new disk image or to test a hardware problem. Enter PXE. PXE, aka Pre-Execution Environment, or 'pixie' is an environment used to boot computers using a network interface. That means you need no data storage device at all to boot the machine. Most current machines have settings in the bios to turn on PXE booting. With PXE booting you can do things like booting dos floppy image with bios update or run a memory test with memtest86. You can also boot full operating systems to rescue or burn in machines. The following information will show you how to setup the enviorment to PXE boot the linux distro SystemRescueCD and some other boot images. This example is done using CentOS. Let's get started.
First we have to turn on PXE booting for each machine. Boot the computer and go into the bios. Find the section in the bios that has to do with the boards devices. There will usually be a section about the LAN or ethernet devices. It will say something like "OnBoard LAN Boot ROM". Turn this on. Save the settings. Reboot. Go back into the bios and find the boot device section. Here you will select the order of your boot devices. Your network controller should be in the list of devices. It might be called something funny like "IBA GE Slot ..." but rest assured that is the LAN adapter. Move it up or down in the order you want to have it try to boot the machine over the network. It has to be before a device that has boot media or it will boot that device first.
Now we need to add a few lines to your dhcp server. If you don't have one you will need to set one up as PXE can not work without one. If your using CentOS you can install one with the command "yum install dhcp". On a working dhcpd server you will need to add the following lines to the /etc/dhcpd.conf configuration file. Make sure you choose your own ip blocks for the different ranges here. Restart the dhcpd server after putting in the lines.
subnet 192.168.5.0 netmask 255.255.255.0 { range 192.168.1.50 192.168.1.55; range dynamic-bootp 192.168.1.56 192.168.1.60; next-server 192.168.5.1; filename "pxelinux.0"; }
If your dhcpd.conf file already has the subnet line then you just need following lines in between the curly braces. Make sure you choose your own ip blocks for different ranges here. The dynamic-bootp line is the ip range for the PXE boot servers. Choose an empty range on your network for these ip's. The next-server line should be the tftp server ip address (which we will setup next). The filename line is the file that is given out on boot.
range dynamic-bootp 192.168.1.56 192.168.1.60; next-server 192.168.5.1; filename "pxelinux.0";
On the same machine or another machine you will need to start a tftp server. PXE will not work without this either. You can install one on CentOS machines with the command "yum install tftp-server". After it's installed we will make a few dir's we need and start the server. The commands for this are below.
mkdir /tftpboot
mkdir -p /tftpboot/pxelinux.cfg
/usr/sbin/in.tftpd -l -B 1460 -s /tftpboot/
Now make sure the syslinux package is installed on the machine with the tftp server. Syslinux is the boot loader PXE will use to boot. You can install it on CentOS using the command "yum install syslinux". Then find out where the file pxelinux.0 lives. On my install it was in /usr/lib/syslinux/pxelinux.0. Copy this file to the /tftpboot dir.
cp /usr/lib/syslinux/pxelinux.0 /tftpboot
Download the latest SystemRescueCd iso to the machine with the tftp server. We are going to mount it on loopback so we can pull some files off to put in the /tftpboot dir. Don't use any version of SystemRescueCD prior to 1.0 for PXE booting. It's broken. This example uses version 1.0.
mkdir /tmp/iso
mount -o loop systemrescuecd-x86-1.0.0.iso /tmp/iso
cd /tmp/iso
cp bootdisk/* /tftpboot
cp isolinux/* /tftpboot
cp syslinux/syslinux.cfg /tftpboot/pxelinux.cfg/default
Now we need to setup an http server. Apache, thttpd, lighttpd, or any other http server will do. I would suggest thttpd if you just want to setup a simple http server. The reason for this is that we need to pull the root filesystem over on boot and it's over 150MB. Doing that via tftp is super slow. Tftp was not made for large files. sysrcd.md5 and sysrcd.dat are the 2 files that need to be copied to the http server running on the machine you installed tftp or any other http server you have running already. It does not have to be on this machine. Only these 2 files are transfered this way. The rest are done via tftp. My example will show copying the 2 files to a dir on the same machine as the tftp server. The root of the my http server will be pointing to /var/www/htdocs/.
cp /tftpboot/sysrcd.md5 /tftpboot/sysrcd.sys /var/www/htdocs/systemrescuecd
Let's modify the default SystemRescueCD menu file /tftpboot/pxelinux.cfg/default. You will need to modify the 2nd line in the file which is the kernel options line for the default kernel (rescuecd). The line starts with the word append. Append the following line (below) to the end of the append line.They are just boot options for the kernel. This will need to go after each line in the default file you want to boot from that needs the SystemRescueCD root filesystem. Other boot images like memtest won't need it. If you put your sysrcd.dat file on a different http server or path from example configuration above then you will need to edit the boot line to reflect where that file is.
setkmap=us boothttp=http://192.168.5.1/systemrescuecd/sysrcd.dat dodhcp ar_source=http://192.168.5.1/systemrescuecd/ ar_nowait
The first sets the keymap to US. The second tells rescue cd to get the root filesystem from an http server (tftp is very slow ~2MB/s). You can also replace boothttp=http with boottftp=tftp. I can't stress enough that tftp is to slow for big images like sysrcd.dat. The dodhcp says to make a dhcp request after booting. The line starting with ar_source tells the system to pull a shell script off an server and execute it after booting. The file it pulls has to be named autorun and it has to be a shell script. You can have 10 autorun files. The format is autorun#. Where # is a digit from 0 to 9. ar_nowait tells the machine to not wait for a keypress after executing server. Take out the ar_source part if you don't want to execute an autorun shell script after boot. It is not required. Save this file after your done editing.
If you do what to use the autorun script then here is an idea for it. Put some files you might need when you boot your enviorment in a dir and have ncftpget or wget (already on the SystemRescueCD cd) get any files for you after boot. Make a dir in the same dir you have your SystemRescueCD boot files and put your files in there. Then on boot it will pull those files over for you to use. For example I have an ftp server I pull files from when my image boots. The example is below.
#!/bin/bash ncftpget ftp://192.168.5.6/systemrescuecd/scripts/*.sh ncftpget ftp://192.168.5.6/seatools/st chmod 755 *.sh st
That should be it. Boot a machine (with PXE turned on) that has network access to all the things we setup. It should boot. PXE will get an ip from the dhcp server (bootp) and then pull the pxelinux.0 file (via tftp) to boot. After the pxelinux.0 file is loaded it should bring up the SystemRescueCD menu and you can boot from there. You will notice if you hit the F2 key you will get other menu items. You can boot these other images also. SystemRescueCD comes with boot images like memtest for memory testing or dban for disk wiping.