DHCP and PXE and TFTP and HTTP in CentOS 6 (Part 2) (aka how to boot Ultimate Boot CD via PXE)
So my previous post talks about setting up DHCP. Read that if you haven’t setup DHCP yet. You need it for PXE and TFTP and HTTP. So many acronyms…
So again, PXE is for booting up a machine via the network. DHCP gives the machine the necessary network configuration, and PXE gives it some files for actually booting up. TFTP and HTTP simply provide the files.
I keep mentioning HTTP. Normally you’ll only need TFTP, especially if you only want to be able install CentOS 6 off the network. I however ran into a situation where I needed to be able to boot the Ultimate Boot CD (UBCD) to diagnose a failing hard drive. That’s where HTTP comes in. Using PXE, I can boot off the UBCD ISO via HTTP. Sounds interesting? Then read on.
PXE and TFTP
So let’s setup PXE and TFTP first. Install syslinux and tftp-server:
yum install syslinux tftp-server
Now, TFTP stuff is located in the /var/lib/tftpboot/ directory. You need to copy some syslinux stuff to it and create the directory for the menu.
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
Now, add the following configuration options into /etc/dhcp/dhcpd.conf:
allow booting;
allow bootp;
next-server 10.0.0.1;
filename "pxelinux.0";
The “next-server” option is wherever the PXE/TFTP stuff is. Since my server’s IP address is 10.0.0.1, that’s what’s in the configuration. Change it to your server’s IP. If you followed my previous post, put these 4 lines just below the “authoritative;” option.
At this point, you should restart your DHCP server.
service dhcpd restart
Next, enable TFTP in xinetd. The configuration file is /etc/xinetd.d/tftp. Set
disable = yes
to
disable = no
Start xinetd and make it start on boot:
service xinetd start && chkconfig xinetd on
Boot images
So to keep things organized, I create an “images” directory inside the tftpboot/ directory.
mkdir /var/lib/tftpboot/images
I copy CentOS 6.2’s pxeboot images from our FTP server. You can get these from CentOS mirrors. The files are in the images/pxeboot/ directory. The files are:
initrd.img
vmlinuz
Copy these 2 files into the images/ directory. If you’ll have other versions of CentOS, Linux, or whatever, I suggest setting up a directory structure to organize the files in there.
Menu
So the menu is what you get once you network boot a computer. Since I like to have CentOS 6, CentOS 5, and memtest (more on this later) available, I have the menu structure setup like this:
default --> Boot local harddrive
--> CentOS 6 x86_64
--> CentOS 5 x86_64
--> Tools
Now I created a file called “default” in that pxelinux.cfg/ directory created above. This configuration gives a 10 second timeout before booting from the local hard drive:
default menu.c32
prompt 0
timeout 100
ontimeout local
MENU TITLE Main Menu
LABEL local
MENU LABEL Boot Local Hard Drive
LOCALBOOT 0
LABEL centos_6_x86_64
MENU LABEL CentOS 6 x86_64
KERNEL menu.c32
APPEND pxelinux.cfg/centos_6_x86_64
LABEL centos_5_x86_64
MENU LABEL CentOS 5 x86_64
KERNEL menu.c32
APPEND pxelinux.cfg/centos_5_x86_64
LABEL tools
MENU LABEL Tools
KERNEL menu.c32
APPEND pxelinux.cfg/tools
Then created the menu that is mentioned in the APPEND options above. I’ll just show the CentOS 6 (the i386 and CentOS 5 menus are similar) and Tools menu.
pxelinux.cfg/centos_6_x86_64:
MENU TITLE CentOS 6 x86_64
LABEL default
MENU LABEL Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default
LABEL centos_6_x86_64
MENU LABEL CentOS 6 x86_64
KERNEL images/centos/6/x86_64/vmlinuz
APPEND initrd=images/centos/6/x86_64/initrd.img
pxelinux.cfg/tools:
MENU TITLE Tools
LABEL default
MENU LABEL Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default
The “default” in each submenu gives a way to go back to the root menu. The Tools menu is empty for now.
memtest
So what about memtest? Download it from here:
http://www.memtest.org/download/4.20/memtest86+-4.20.bin.gz
Then gunzip it then put it in the images/ directory.
Then add it to the Tools menu by appending the following:
LABEL memtest
MENU LABEL Memtest86+
KERNEL images/memtest/memtest86+
Make sure the “KERNEL” has the correct filename.
Ultimate Boot CD
This needs an HTTP server. You basically put the ISO into an HTTP server you can access. So find an HTTP server and put the ISO there. I’ll use 10.0.0.1 for my example.
Next, the pxelinux.0 stuff has to be replaced with gpxelinux.0. So, copy that and memdisk from the syslinux/ shared directory:
cp /usr/share/syslinux/gpxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/memdisk /var/lib/tftpboot/
and replace the the following line in /etc/dhcp/dhcpd.conf:
filename "pxelinux.0";
with this:
filename "gpxelinux.0";
and restart DHCP:
service dhcpd restart
Now, a menu has to be created for it. I appended this to the Tools menu:
LABEL ubcd
MENU LABEL Ultimate Boot CD
KERNEL memdisk
APPEND iso initrd=http://10.0.0.1/pub/ubcd/ubcd511.iso
So this should boot up, and get the ubcd511.iso from the HTTP server. It’ll take awhile since that’s a 300mb ISO. Update that URL to whatever it is in your local network.
Conclusion
That’s it. You should be able to boot from the network, select CentOS X, and be able to install via FTP or HTTP or whatever other method you have. If you use Kickstart, you can even create separate menu entries for each type of server you need, and automatically install from there.
You should also now be able to test the memory on your computers, as well as boot up the Ultimate Boot CD and test hardware, or whatever other feature that has.
Again, fun huh?