Create Network PXE Boot Server with Fedora 18
March 20, 2013
Special thanks to Manually configure a PXE server, from Fedora’s documentation, for providing very useful information. You should consider that documentation as much more authoritative than this post. I have tried to focus on setting up infrastructure for multiple distros, BIOS, and IPv4. I’ll update with IPv6 and EFI as I test that.
Disclaimer: Although I have tested this post it may still be incomplete or may contain errors.
Installing an OS over the network is a big time saver, especially when combined with autoconfig options such as Kickstart, Pressed, and AutoYaST. The first step in doing so is create the infrastructure that allows a computer or server to boot from the network and install the OS. These instructions were created using Fedora 18. Install it in a VM and you are good to go. Make sure it uses static IPv4 and IPv6 addresses and is accessible via SSH.
The network boot server used for these instructions was named noosa. Whenever noosa is mentioned in these instructions understand that it refers to the boot server. Let’s say noosa has an IPv4 address of 192.168.1.15 and IPv6 address of 2100:192:168:1::15. Create a user called idopxe on the server, used later in the instructions.
You’ll need a DHCP server running on this server. This could cause conflicts on your network if you’re already running a DHCP server. But if your current DHCP server supports the extra options mentioned in these instructions then you can continue to use it. Otherwise you may have to replace your current DHCP server with the one running on noosa.
Major steps in the process are:
- Install and Configure TFTP Server
- Create PXE Directory Structure
- Copy OS ISOs to Boot Server
- Extract Files from OS ISO
- Configure PXE
- Install and Configure HTTP Server
- Install and Configure DHCP Server
Install and Configure TFTP Server
su -c 'yum install tftp-server'
Enable the service by editing the file /etc/xinetd.d/tftp and change
disable = yes
to
disable = no
Start the TFTP server. You’re starting xinetd because TFTP server is a xinetd-based service.
su -c 'systemctl start xinetd.service'
su -c 'systemctl enable xinetd.service'
You can now place files in /var/lib/tftpboot/ to be served by TFTP.
Create PXE Directory Structure
cd /var/lib/tftpboot/
su -c 'mkdir loopdir'
su -c 'mkdir linux'
su -c 'mkdir linux/fedora'
su -c 'mkdir linux/fedora/18'
su -c 'mkdir linux/fedora/18/x86_64'
su -c 'mkdir linux/fedora/18/x86_64/dvd'
su -c 'mkdir linux/fedora/18/x86_64/dvd/iso'
su -c 'mkdir linux/fedora/18/x86_64/dvd/files'
su -c 'mkdir linux/fedora/18/x86_64/dvd/kickstart'
Copy/download/upload Fedora 18 64-bit DVD ISO to /var/lib/tftpboot/linux/fedora/18/x86_64/dvd/iso/ directory.
Extract Files from OS ISO
su -c 'mount -o loop /var/lib/tftpboot/linux/fedora/18/x86_64/dvd/iso/Fedora-18-x86_64-DVD.iso /var/lib/tftpboot/loopdir'
rsync -v -a -H --exclude=TRANS.TBL /var/lib/tftpboot/loopdir/ /var/lib/tftpboot/linux/fedora/18/x86_64/dvd/files/
su -c 'umount /var/lib/tftpboot/loopdir'
Configure PXE
cd /var/lib/tftpboot/
su -c 'vim defaultbootmenu.txt'
Make sure it has the following contents:
== BOOT MENU == localdisk fedora_18_dvd_64_bios_default fedora_18_dvd_64_efi_default fedora_18_dvd_64_bios_kickstart fedora_18_dvd_64_efi_kickstart
Create a new directory:
su -c 'mkdir pxelinux.cfg'
cd pxelinux.cfg
su -c 'vim default'
DISPLAY defaultbootmenu.txt DEFAULT localdisk LABEL localdisk localboot 0x80 LABEL fedora_18_dvd_64_bios_default kernel linux/fedora/18/x86_64/dvd/files/isolinux/vmlinuz append initrd=linux/fedora/18/x86_64/dvd/files/isolinux/initrd.img repo=http://192.168.1.15/repo/linux/fedora/18/x86_64/dvd/files/ LABEL fedora_18_dvd_64_bios_kickstart kernel linux/fedora/18/x86_64/dvd/files/isolinux/vmlinuz append initrd=linux/fedora/18/x86_64/dvd/files/isolinux/initrd.img ks=http://192.168.1.15/repo/linux/fedora/18/x86_64/dvd/kickstart/anaconda-ks.cfg implicit 1 prompt 1 timeout 300
You’ll need to install the SYSLINUX package.
su -c 'yum install syslinux'
Copy pxelinux.0 file from SYSLINUX to tftpboot directory.
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
Install and Configure HTTP Server
su -c 'yum install httpd'
su -c 'systemctl start httpd.service'
su -c 'systemctl enable httpd.service'
Remember to open ports in the firewall.
cd /var/www/html
su -c 'mkdir repo'
cd repo
su -c 'ln -s /var/lib/tftpboot/linux/ linux'
You’ll have to fix some SELinux permissions to allow httpd to be able to follow this symlink. The easiest way, if you aren’t familiar with SELinux, is to set it in permissive mode.
su -c 'setenforce 0'
Install and Configure DHCP Server
su -c 'yum install dhcp'
Edit a config file to specify on which interface to allow DHCP services to run.
su -c 'vim /etc/sysconfig/dhcpd'
Just change the value for INTERFACES in this file. In our example we want to run DHCP on eth0. So the file should have the following contents.
DHCPDARGS="eth0";
If you want to run it on multiple interfaces, for example eth0 and eth1, then it should read
DHCPDARGS="eth0 eth1";
Now edit the dhcpd.conf file.
su -c 'vim /etc/dhcp/dhcpd.conf'
ddns-update-style none; option domain-name "codeghar.com"; option domain-name-servers 192.168.1.200, 192.168.1.201; default-lease-time 600; max-lease-time 7200; log-facility local7; class "linux-server" { match if substring(hardware, 1,6) = 00:11:22:33:44:55; } subnet 192.168.1.0 netmask 255.255.255.0 { pool { range 192.168.1.91 192.168.1.100; filename "pxelinux.0"; next-server 192.168.1.15; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option routers 192.168.1.1; allow members of "linux-server"; } }
In this configuration we give a default domain name, name servers, and other information. pxelinux.0 is the default file that other servers will use to boot when using PXE boot. next-server has the IP address of the TFTP server. In our case it’s noosa. You can use the class to match MAC addresses of certain servers only, thus not giving out dynamic IPs to other servers on your network. If your existing DHCP server can provide these options then you don’t need to run the DHCP server on noosa and instead need to pass this configuration to servers doing a PXE boot.
su -c 'systemctl start dhcpd.service'
su -c 'systemctl enable dhcpd.service'
Boot from network
Now when you boot from your target machine and choose network boot, it will get a DHCP IP and present a menu of options (defined in defaultbootmenu file). Just pick whatever is appropriate and off you go.
Recent Comments