Tuesday, July 19, 2011

Using unRAID and DD-WRT to create a PXE boot server

For a while if been struggling with the idea to create a PXE server in my network. It annoys me carrying USB sticks or DVD's around in my local network, especially since I have a unRAID (Slackware 12 running from a USB stick) server running 24/7.
My unRAID server
So I went and made myself a PXE server.


I'm using the 5.x build of unRAID, witch means there is no native tft support anymore that the 4.x version had, so there might be some extra steps to take that you don't need if you are running 4.x.
On the upside 5.x automatically installs everything in the 'extra' folder on the USB flash drive.



The unRAID server part
  1. Download tftp-hpa-0.48-i486-1.tgz to your unRAID server and place it in the extra folder (\\tower\flash\extra)
  2. Open a telnet or SSH session to the unRAID server and run the command: installpkg /boot/extra/tftp-hpa-0.48-i486-1.tgzThis will install the packages right away (this is also automatically done when you reboot the server, if you are using the 4.x version of unRAID you have to edit the 'go' file)
  3. Now you have to create a folder where your PXE boot images and other server stuff can stay, i made a new share on my unRAID server via the webinterface and called it 'SEVER' and made it hidden.
  4. I made another folder under that share called 'tftpboot' -> in the telnet session run: mkdir /mnt/user/SERVER/tftpboot
  5. Now we need to run the tftp 'daemon', run it in 'listening mode' and define the start directory, run: in.tftpd -l -s /mnt/user/SERVER/tftpboot
  6. We also need to make sure this runs on a server restart so also add the above line to the 'go' script. (\\tower\flash\config\go)
  7. To boot Linux via PXE you need the files from the syslinux package, to do download this packadge (contains the version 4.10-pre-15 binaries) or use the files from the syslinux site, put the following files in your newly created directory:
    • pxelinux.0
    • menu.c32
    • memdisk
    • mboot.c32
    • chain.c32

  8. Now the files are in the correct folder make sure the files in there can be executed, run:  chmod -R -c 755 /mnt/user/SERVER/tftpboot/*The output should be: mode of `/mnt/user/SERVER/tftpboot/xxx.xxx' changed to 0755 (rwxr-xr-x) repeated for each file.
  9. We have the configuration, now we need some things to boot and preferebly a folder where they all can sit nicely together, create a folder: mkdir -p /mnt/user/SERVER/tftpboot/images/dos/ and mkdir -p /mnt/user/SERVER/tftpboot/images/pmagic/ or maybe you want to do something like: mkdir -p /mnt/user/SERVER/tftpboot/images/centos/i386/6.0/ (if you want to netinstall CentOS)
  10. Now we need a directory for the PXEconfig files, run: mkdir /mnt/user/SERVER/tftpboot/pxelinux.cfg
  11. In this directory you can create config files for the PXE menus, the simple way is just create one file called: 'default' but its also possible to create a file based on the MAC adress of the PC you want to boot via PXE. for more information see the the syslinux wiki
    So here is the contents of my /mnt/user/SERVER/tftpboot/pxelinux.cfg/default file:
default menu.c32
prompt 0
timeout 300
ONTIMEOUT local
MENU TITLE PXE Menu
LABEL Pmagic
        MENU LABEL ^Parted magic
        kernel images/pmagic/bzImage
        append noapic initrd=images/pmagic/initramfs root=/dev/ram0 init=/linuxrc ramdisk_size=100000
LABEL Dos Bootdisk
        MENU LABEL ^Dos bootdisk
        kernel memdisk
        append initrd=images/dos/622c.img
default PXE config file in Notepad2
Parted magic
The first line PXE boots to 'Parted magic' a free full Linux distribution with a great partition manager that can run completely from memory, the second is a Dos 6.22 boot disk image. Fairly simple, but that is enough for now to see if it works.
To use parted magic, download the latest pmagic-pxe zip file (mine was pmagic-pxe-6.3-i486.zip) and extract it, copy over the entire pmagic directory to you server in the \\tower\SERVER\tftpboot\images folder.
Make sure any files put in the 'images' folder are executable, you might need to run the 
chmod -R -c 755 /mnt/user/SERVER/tftpboot/* command again.



The DHCP server part

Now your server is able to serve PXE boot requests but now you need a way to let the PC's in your network know where they can find it.
To do this you need to configure your DHCP server. How you do this depends on your network layout & DHCP configuration, for DHCPd you need to edit you /etc/dhcpd.conf file to something like:

allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server x.x.x.x; 
filename "/pxelinux.0";
(Replacing x.x.x.x with the IP adress of your server)
DD-WRT configuration
I use a simple D-Link DIR-825 router for my DHCP and the nice thing is: it runs DD-WRT so all I had to do is login to my router, go to the services tab and add the following line to "Additional DNSMasq Options"
dhcp-boot=pxelinux.0,yyyy,x.x.x.x
Replacing yyyy with the host name of your server and x.x.x.x with it's IP address and that's is.
Now you should be able to run VMware or boot from a client en get the nice PXE menu:
Booting to PXE menu


    2 comments:

    1. I tried this and I can get the bzimage to load and the initrd.img to load partially (after about 5 minutes of seeing the... go by) then I get a Boot failed: press a key to retry

      I also tried the ISO version with the same result

      dos images load just fine. seems like the images are too big or something. any ideas?

      ReplyDelete
      Replies
      1. I try'd loading a big ISO directly via PXE and had the same result.
        Loading a big iso like this is not recommended, most linux distributions use a small PXE boot envourment and from there load the needed packadges from FTP or HTTP.
        You could try using the latest version of pxelinux or isolinux from the syslinux site.

        Delete