Tag Archives: Pxe

Home / Pxe
1 Post

I am playing with the idea of using the PXE capabilities of my DiskStation for a while now. I postponed many times the moments that I want to start with it. It has some implications for my network infrastructure and I couldn’t find the time to do this. I decided to do it in several stages to come to the situation that I’m able to use the PXE server. This post will describe what I did to start using PXE with all kind of network boot functionality. It must be able to start installations of operating systems (Windows and Ubuntu), Anti virus scanners and other maintaining tools.

1. Prerequisites

Before you can use the PXE server you have to fulfill some prerequisites. You have to enable PXE capabilities on your current DHCP server, or use the DHCP capabilities of your DiskStation. I decided to use the DHCP of the DiskStation, because my router’s DHCP does not support these features. Many times these kind of features are not supported by the router you get from your ISP. This also allows me to start using the DNS server capabilities of my DiskStation. I have the feeling this DNS is much faster than the DNS of my router and, because I’m able to define the DNS-server to use, I took the opportunity to switch my DNS-server too.

Another prerequisite is the availability of a shared folder to serve the PXE from. You can use an existing one, but I’ll advise you to create a new one.

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. For your convenience I made a zip-file containing these files. You can download the zip from here.

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.

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:

default menu.c32
prompt 0

MENU TITLE PXE Boot Main Menu
MENU INCLUDE pxelinux.cfg/graphics.conf
MENU AUTOBOOT Starting Local System in # seconds

LABEL local
    MENU LABEL Boot local hard drive
    MENU default
    LOCALBOOT 0
    TIMEOUT 300
    TOTALTIMEOUT 9000

Create another text file in the pxelinux.cfg folder with the name graphics.conf. This file contains some color and other layout settings for the PXE boot menu and is included in the default file. Put the following text in the graphics.conf file:

    menu color tabmsg 37;40          #80ffffff #00000000
    menu color hotsel 30;47          #40000000 #20ffffff
    menu color sel 30;47             #40000000 #20ffffff
    menu color scrollbar 30;47       #40000000 #20ffffff
    MENU MASTER PASSWD yourpassword
    MENU WIDTH 80
    MENU MARGIN 22
    MENU PASSWORDMARGIN 26
    MENU ROWS 6
    MENU TABMSGROW 15
    MENU CMDLINEROW 15
    MENU ENDROW 24
    MENU PASSWORDROW 12
    MENU TIMEOUTROW 13
    MENU VSHIFT 6
    MENU PASSPROMPT Enter Password:
    NOESCAPE 1
    ALLOWOPTIONS 0

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. (i.e. tftproot).

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. Filling the PXE boot menu

As I mentioned before I would like to have many different tools and services from the PXE service. To make sure this stays accessible in the future, I need a menu structure with sub menu’s to organize all this. I’ll start to explain how to make these menu’s in the PXE boot menu. After that the filling of the submenu’s will be explained.

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:

default menu.c32
prompt 0

MENU TITLE PXE Boot Main Menu
MENU INCLUDE pxelinux.cfg/graphics.conf
MENU AUTOBOOT Starting Local System in # seconds

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.

3.3 Booting from an NFS share

This took me a while to figure out how this works. This has to do with how NFS works in the first place. After I sorted that out, I decided to setup a PXE from the ‘Trinity Rescue Kit’ (TRK). I downloaded the ISO image from TRK and extracted the ISO. (I know there are other archives.) You can download TRK from http://trinityhome.org/ (151M).

Copy the folder with it’s content of the extracted ISO as subfolder to ‘/TftpRoot/images/’. I presume that this subfolder name is ‘trk‘, so Trinity Rescue Kit is saved in /TftpRoot/images/trk/ on your DiskStations shared folder for PXE. The only thing left to do is enter the TRK as a menu entry in the PXE boot menu:

LABEL trk3
      menu label ^Trinity Rescue Kit
      kernel images/trk/kernel.trk
      append initrd=images/trk/initrd.trk ramdisk_size=65535 root=/dev/ram0 vga=0 trknfs={IP_DISKSTATION}:/volume1/TftpRoot/images/trk/ ro ip=::::::dhcp splash=verbose

Make sure you entered the correct IP address (IP_DISKSTATION) and volume in the append line of the menu entry above.

4. PXE Boot menu snippets

This chapter contains some examples of snippets to extend the PXE boot menu. The given file destinations are default located in the images folder that is located in the shared folder assigned to the PXE services. (i.e. tftproot)

4.1 Bootable ISO’s

This section contains a snippet that let the accordingly ISO image boot with the PXE server.

4.1.1 Hirens Boot CD
Source: http://www.hirensbootcd.org/download/
File(s): Hiren’s.BootCD.15.2.iso
File(s) destination: images/
Snippet:

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

4.2 Boot live systems

This section contains snippets that let you boot a live system from the network.

4.2.1 Trinity Rescue Disk
Source: http://trinityhome.org/Home/index.php?content=TRINITY_RESCUE_KIT_DOWNLOAD
File(s): ISO image extract in a subfolder named ‘trk’
File(s) destination: images/trk/
Snippet:

LABEL trk3
      menu label ^Trinity Rescue Kit
      kernel images/trk/kernel.trk
      append initrd=images/trk/initrd.trk ramdisk_size=65535 root=/dev/ram0 vga=0 
		trknfs={IP_DISKSTATION}:/volume1/TftpRoot/images/trk/ ro ip=::::::dhcp splash=verbose

(The ‘append’ line in the snippet above is ONE line.)

4.2 Other

For those who can read German, there is an extensive Wiki about PXE on Synology with many more examples to add items to your PXE bootmenu. Please visit the deutschen SynologyWiki. (They have a lot of other interesting Wiki’s too!)