1.1 Enable DHCP

I’ll start with a warning: you do NOT want to have more than one DHCP on your local home network. It is also a good idea to write down your current IP-address, subnet mask an gateway address. You might need this when the configuration of the DHCP service of the DiskStation is faulty and the current DHCP-service is disabled. (You can make the IP configuration of your workstation static with this information and enables you to gain network access again.)

This means when you start using the DHCP service of your DiskStation, you have to disable your current DHCP service. This is most of the time provided by your modem/router. On each modem/router this service can be managed, only the way how to do this differs. Check the manual of your modem how to do this.

To make the switch more smoothly for me, I use the same address pool range as was using on my modem/router. To enable the DHCP on the DiskStation open in DSM the ‘Control Panel‘ and select ‘Network‘. Click on the ‘Network Interface‘-tab. Select the ‘Lan’ you want to enable the DHCP service for. Click the ‘DHCP server‘ button.

In the ‘General‘ tab you have to tick the ‘Enable DHCP Server‘ checkbox. You have to define minimal one DNS-Server.
The ‘Primary DNS’ has to be filled with the IP-address of the DNS-server to use. If you remain using your modem/router as DNS-server, then you have to enter the IP-address of your modem/router here. If you use another DNS-server then you enter this IP-address accordingly. (How to use the DiskStation DNS is not a part of this post.
You have to find this information elsewhere, or keep using the DNS of your modem/router. This will make no difference for the PXE capabilities.)

You also have to define an address pool for the DHCP service. Click on the ‘Add‘ button and enter the start address and end address of the pool and enter a subnet mask and gateway address. (The start address and end address can be found in the modem/router settings. To find the subnet mask and the gateway address, you can use ‘ipconfig /all‘ in a Windows DOS-box. The gateway address will probably the IP-address of your modem/router.) Make sure the address pool is marked as ‘enabled‘.

Now click on the ‘Apply‘ button to start and enable the DHCP server of the DiskStation. Now it is the time to disable the DHCP-service on your modem/router. This completes the DHCP part.


 1.2 Creating shared folder

This is a default functionality of your DiskStation. In ‘Control Panel‘ Click ‘Shared Folder‘. Click on the ‘Create‘ button.

Give it an appropriate name (I choose tftproot) and ‘Location‘ and tick the boxes ‘hide this shared folder in ‘My Network Places‘ and ‘Hide folders and files for users without permissions’. Click the ‘OK‘ button to create the shared folder.

Select the just created shared folder and open the ‘Privileges‘ menu. Select the ‘Privileges Setup‘ item and give the ‘administrators group‘ read and write access.
I also added NFS read rights for my complete network. This can be done with the ‘NFS privileges‘ in the ‘Privileges‘ menu.
I struggled a while with the NFS privileges, but I have a working configuration now. You have to enter three values, the ‘IP address’ (or network) that has access to the NFS share, the ‘Privilege’ and the ‘Root squash’. I used 192.168.1.0/24 (Network), Read only and Map to admin.

With the above prerequisites fulfilled you are good to go to start using the PXE services of your DiskStation.


 2. Setup the DiskStations PXE service

The prerequisites must function well before it makes any sense to continue. So make sure your DHCP server works well.

The following step is to setup de PXE service. Before you can do that, you need some files to actually boot from the network.
I used PxeLinux witch is a part of SysLinux. you have to pick some files from several locations of the zip: chain.c32, mboot.c32, memdisk, menu.c32, pxelinux.0 and vesamenu.c32.

Extract or copy these files to the root of the shared folder you have created for your PXE service. (i.e. tftproot).
Use a program like WinSCP (If you are using Windows). The location of the shared folder will be /volumeX/tftproot where X is the volume number on witch you created the shared folder.
After you have done that, create a folder named pxelinux.cfg and a folder named images in the tftproot folder.

If you use a Linux box machine, you can use one of this 2 methods:

[toggle title=”First Method”]

wget https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz
tar -xvf syslinux-6.03.tar.gz

mkdir -p ~/TFTP/{pxelinux.cfg,images/} cp syslinux-6.03/bios/core/pxelinux.0 /var/lib/tftpboot/bios/
cp syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 ~/TFTP/
cp syslinux-6.03/bios/com32/lib/libcom32.c32 ~/TFTP/
cp syslinux-6.03/bios/com32/libutil/libutil.c32 ~/TFTP/
cp syslinux-6.03/bios/com32/menu/vesamenu.c32 ~/TFTP/
cp syslinux-6.03/bios/com32/modules/pxechn.c32 ~/TFTP/

[/toggle]

[toggle title=”Second Method”]

mkdir -p ~/TFTP/{pxelinux.cfg,images/} && \
wget -O - https://www.kernel.org/pub/linux/utils/boot/syslinux/6.xx/syslinux-6.03.tar.gz | \
tar -xzf - -C ~/TFTP/ --transform='s/.*\///' \
syslinux-6.03/bios/{core/pxelinux.0,com32/{menu/{menu,vesamenu}.c32,libutil/libutil.c32,elflink/ldlinux/ldlinux.c32,chain/chain.c32,lib/libcom32.c32}}

[/toggle]

The next thing to do is to create a text file named default in the pxelinux.cfg folder.
Use an appropriate text editor.
The one in WinSCP will do. (Windows default Notepad doesn’t!). put the following text in the default file:

PROMPT 0
NOESCAPE 0
ALLOWOPTIONS 0
TIMEOUT 100
ONTIMEOUT local

### TUI
DEFAULT menu.c32

### GUI
#UI vesamenu.c32
# The splash.png file is a PNG image with resolution of 640x480 px

#MENU BACKGROUND splash.png
MENU TITLE ---===[ Boot Menu ]===---

LABEL local
  MENU DEFAULT
  MENU LABEL ^1. Boot from hard drive
  COM32 chain.c32
  APPEND hd0

Save the files and switch to the DSM desktop of your DiskStation.

Open the ‘Control Panel‘ and tick the FTP feature. Select the ‘TFTP/PXE‘ tab.
Enable the ‘Enable TFTP service‘ feature and select the ‘TFTP root folder‘ you have created earlier.

Click the ‘Advanced Settings‘ button and make the ‘FTP Client Permissions‘ set to ‘Read only‘.
You also have to limit the ‘Allowed Clients‘ to the address range of your local network. (The start address and end address of your DHCP address pool will do.)
Click the ‘OK‘ button to confirm these advanced settings.

Now also enable the ‘Enable PXE service‘.
The next thing to do is to select the ‘Boot loader‘.
Click the button and pick: pxelinux.0.
Next select the LAN interface you enabled DHCP earlier on. (i.e. LAN 1).
The only thing left to do is to configure the DHCP.
Use the same information you used earlier to configure your DHCP service.
(DNS server address, start address, end address, subnet mask an gateway address) Click the ‘Apply‘ button to save the information and start the TFTP and PXE service.

If everything went well so far, you now must be able to do a network boot with a client computer and can select the option to ‘Boot the local hard drive’. I know this isn’t much, but it is the bare minimum to make sure PXE booting works. The following chapter will describe how to add more to the PXE boot menu. (Keep in mind I would like to create a rich boot menu with all kind of different options. This takes time to figure out.) You may want to go from here by yourself or you see what the next chapter will bring.

3.1 Adding a sub menu

To add a sub menu, create a new text file with an appropriate name in the pxelinux.cfg folder. For this example create a file with the name ‘rescue.menu‘ to accommodate all the functionality that the PXE service supplies to ‘rescue’ a computer. This can be a virus scanner or a recovery disk to try to recover data from a computer that can’t boot by it self.

For now the sub menu will not have any content (Beside an entry to return to the main menu). That will be handled later. First create the sub menu’s. Create a text file rescue.menu and put the following in it:

default menu.c32
prompt 0

MENU TITLE Rescue Menu
MENU INCLUDE pxelinux.cfg/graphics.conf

LABEL Main
    MENU LABEL ^Return to Main Menu
    KERNEL menu.c32
    APPEND pxelinux.cfg/default

Save the file. This file will be called from the default menu. To achieve this, the default text file must be extended with the following lines:

LABEL Rescue
	MENU LABEL ^Rescue Menu...
	KERNEL menu.c32 
	APPEND pxelinux.cfg/rescue.menu

This snippet creates a menu item in the PXE boot menu. So for any sub menu you need, you can use this structure. Just change the MENU LABEL, and the APPEND accordingly. The position in the text file of a snippet is also the position the item has in the boot menu. The new default now looks like this:

PROMPT 0
NOESCAPE 0
ALLOWOPTIONS 0
TIMEOUT 100
ONTIMEOUT local

### TUI
DEFAULT menu.c32

### GUI
#UI vesamenu.c32
# The splash.png file is a PNG image with resolution of 640x480 px

#MENU BACKGROUND splash.png
MENU TITLE ---===[ Boot Menu ]===---

LABEL local
  MENU DEFAULT
  MENU LABEL ^1. Boot from hard drive
  COM32 chain.c32
  APPEND hd0

LABEL Rescue
  MENU LABEL ^Rescue Menu...
  KERNEL menu.c32
  APPEND pxelinux.cfg/rescue.menu

You are now able to add items to the PXE menu’s. No matter is this is the default menu or any submenu.
The idea is the same: just add a snippet to the file you want to extend with the functionality.
Beyond this I only show the snippets that makes a PXE boot menu item, not a complete text file.


 

3.2 Booting an ISO image with PXE

The first idea that came up to me was to start with a bootable ISO-image.
I choose the Hirens Boot CD that can be downloaded from http://www.hirensbootcd.org. Download the zip (590M) and extract the ISO-file from the zip-archive.
copy Hiren’s.BootCD.15.2.iso to the images folder you created in the tftproot folder. (It is a good idea to create a structure that makes sure that you find your way in the future here, when this folder becomes more crowded.) For this example I simply drop the ISO in the images-folder.

The following snippet makes a menu entry that let you boot Hirens boot cd from the network:

LABEL hirensbootcd
	MENU LABEL ^Hirens boot CD
	kernel memdisk
	append iso initrd=images/Hiren's.BootCD.15.2.iso raw

When you add this snippet to the previously created rescue.menu file, you’ll find the Hirens boot cd in the rescue menu of the PXE boot menu.

I found out that not all the ISO images let them start so easily. In the next chapter I start collecting all kind of snippets to start all kind of functionality from the PXE server. An example that causes me troubles were the Kaspersky Rescue disk and the F-Secure rescue disk. I will keep trying and publish as soon as I’ve found a way to start these successfully.