This documentation applies only Turris OS 3.x that is no longer present in newly sold routers. The new documentation is located at https://docs.turris.cz/.
PXE is a technology, which allows boot of a computer through the network. The technology can be use to run diagnostic tools, or to install an operating system through the network. It is also possible to run a whole operating system on a drive-less machine.
Let us start with a somewhat informal introduction. The household of a standard IT enthusiast is full of NAS boxes, external drives, multimedia centers and tens of terabytes of data regularly fly through his network. Unlike in previous years, CDs and DVDs are hard to find. If you are known to be an IT expert among your relatives and friends, you will find yourself supplied with “broken”, “slow” or “weird” computers and pleas to repair them.
And now we come to the actual issue. It is oftentimes useful to be able to boot some kind of installer or a live OS, but CDs/DVDs can't be found, the computer is an older low-end model and the manufacturer doesn't support a boot from a USB drive. An alternative scenario is that you are prepared, you have a supply of CDs, but the computer in question doesn't have a working CD drive.
If these types of situations sound familiar to you, the good news is, that a boot though the network is a relatively old technology, which can also be implemented on a lot of low-end models.
Because the internal memory of the router Turris is meant mainly for the use of the OS, it's size is not adequate for saving installation images. It's necessary to connect another storage device for saving the images — an external HDD, NAS, USB flash disk or SD card.
If you plan to have the boot running permanently, it's necessary to count with the fact that this storage always has to be accessible to the OS. The boot through the network can partly be managed by the DHCP server dnsmasq, which Turris uses. The is one small complication however: if the dnsmasq doesn't find the given storage, it will refuse to run. The computers in the local network will not send information about the DNS server and “the Internet will stop working”, which is very undesirable. So it's necessary to some storage ready, which the router can use at all times.
The previous issue also relates to the choice of file system on the given storage medium. The given medium always has to be physically accessible and the OS has to be able to mount it during a boot. For that reason it's not so easy to operate a storage with NTFS, because the system doesn't know how to mount NTFS automatically. With a little effort and experimentation, this can be overcome using the same method, which is described in the manual for NAS - mount the drive before running dnsmasq.
Note: If you want to mount the root file system, you can never use NTFS – it would not be possible to set the right authorization for the data.
Automatic mounting of a connected device can be set in
/etc/config/fstab
:
The file can look for example like this:
config global option anon_swap '0' option anon_mount '0' option auto_swap '1' option auto_mount '1' option delay_root '5' option check_fs '1' config mount option enabled '1' option uuid '126c85e6-b7f8-4df9-b83a-25e4531f98d1' option target '/mnt/data'
The option enabled
enables automatic mounting, uuid
is an identification of the EXT section and target
the location, where the disk should be mounted. Writing into /dev/sda1
and the like also works.
TIP: The mount can also be done in the administration interface LuCI in the tab System / Mount points. More information concerning this can be found in the documentation for NAS
If the service fstab
is not enabled, enable it using this command:
/etc/init.d/fstab enable
If you need to test the functioning of individual components, it can be helpful to install one of the visualization tools (for example VirtualBox) to create a virtual computer, configure its network card for bridge mode and test the boot through the network here. Rebooting a virtual computer is almost instantaneous and the whole mount can be done on one computer without the need of additional HW.
We will first prepare the directory structure in a folder, which we have designated on the external medium for this purpose. The folder used in the following examples is /mnt/data
.
cd /mnt/data mkdir tftp tftp/images tftp/pxelinux.cfg
Then you need to download Syslinux, which is a set of loaders that are able to boot from various media. This also where the loader for the boot through the network PXE is found. A list of available packages can be found on this page. Download the newest version in the preferred archive.
Copy the following files from the Syslinux archive into /mnt/data/tftp
:
bios/core/pxelinux.0
bios/com32/elflink/ldlinux/ldlinux.c32
bios/com32/menu/vesamenu.c32
– graphical version of the menubios/com32/menu/menu.c32
– text version of the menubios/com32/lib/libcom32.c32
bios/com32/libutil/libutil.c32
Even though may look somewhat unusual, the files from the given directory structure are really copied into one directory, without keeping the structure the same.
It's possible to select only one of the menu versions - either vesamenu.c32
or menu.c32
.
Note: The last part of the manual uses both these versions.
In addition, we will need an NFS server. Install it by activating the NAS package in the Foris interface. Alternatively from the command line (attention, this will cause the package to not be updated automatically) using the following command:
opkg install nfs-kernel-server
Set the sharing of the directory with the installation images in the file /etc/exports
:
/mnt/data/tftp/images *(ro,async,no_subtree_check)
Enable and activate/ restart the installed services:
/etc/init.d/portmap enable /etc/init.d/portmap restart /etc/init.d/nfsd enable /etc/init.d/nfsd restart
Finally it's necessary to edit the file /etc/config/dhcp
. This adds two lines to the section config dnsmasq
and a new section – config boot
. After these changes have been made, the file should look like this:
config dnsmasq option domainneeded '1' option boguspriv '1' option localise_queries '1' option rebind_protection '1' option rebind_localhost '1' option local '/lan/' option domain 'lan' option expandhosts '1' option authoritative '1' option readethers '1' option leasefile '/tmp/dhcp.leases' option resolvfile '/tmp/resolv.conf.auto' option port '0' option enable_tftp '1' option tftp_root '/mnt/data/tftp' config boot 'linux' option filename 'pxelinux.0' option serveraddress '192.168.1.1' option servername 'Turris' ...
The rest of the file remains unchanged. The last step is to restart the service:
/etc/init.d/dnsmasq restart
First of all we download the distribution image, which we will be installing. This manual shows how to do this using a Ubuntu distribution, because it is one of the major ones. The procedure should be similar for other distributions.
After we have downloaded the image, we will mount it as a loop device. This command needs to be done through root:
mount -o loop ubuntu-14.04.1-desktop-amd64.iso /mnt/mountpoint/
The image has roughly this structure:
$ cd /mnt/mountpoint/ $ ls -l celkem 2548 -r--r--r-- 1 root root 134 čec 23 00:34 autorun.inf dr-xr-xr-x 1 root root 2048 čec 23 00:36 boot dr-xr-xr-x 1 root root 2048 čec 23 00:36 casper dr-xr-xr-x 1 root root 2048 čec 23 00:35 dists dr-xr-xr-x 1 root root 2048 čec 23 00:36 EFI dr-xr-xr-x 1 root root 2048 čec 23 00:36 install dr-xr-xr-x 1 root root 18432 čec 23 00:36 isolinux -r--r--r-- 1 root root 21426 čec 23 00:36 md5sum.txt dr-xr-xr-x 1 root root 2048 čec 23 00:35 pics dr-xr-xr-x 1 root root 2048 čec 23 00:35 pool dr-xr-xr-x 1 root root 2048 čec 23 00:35 preseed -r--r--r-- 1 root root 231 čec 23 00:35 README.diskdefines lr-xr-xr-x 1 root root 1 čec 23 00:35 ubuntu -> . -r--r--r-- 1 root root 2551408 dub 14 2014 wubi.exe
The files wubi.exe
and autorun.inf
will not further be required and be careful about the item ubuntu
– it is a symbolical reference back to the present directory and when attempting to copy data, this could cause an infinite loop. The rest of the file should be copied into the directory /mnt/data/images/
and into a suitably named sub-directory, for example ubuntu-14.04-64
. The whole command could look like this:
cp -r boot casper dists EFI install isolinux md5sum.txt pics pool preseed /mnt/data/tftp/images/ubuntu-14.04-64/.
The first thing, which appears on the computer that is being booted, is the boot menu. What this menu can look like can be demonstrated on an advanced example with numerous levels. The example again works with an Ubuntu distribution.
DEFAULT menu.c32 PROMPT 0 TIMEOUT 300 ONTIMEOUT local MENU TITLE Turris at lair-net PXE-Boot Menu LABEL local MENU LABEL Boot from local hard-drive LOCALBOOT 0 LABEL ubuntu MENU LABEL Ubuntu KERNEL menu.c32 APPEND pxelinux.cfg/ubuntu.cfg
Now let's look line by line at what the individual options mean:
DEFAULT menu.c32
– Signifies which menu to draw. menu.c32
for the text menu option, vesamenu.c32
for the graphical menu option. This concerns that file, which you copied from the Syslinux project.PROMPT 0
– Leaves out the prompt and displays the boot menu straight away.TIMEOUT 300
– Sets the duration of a timeout, during which it is possible to select a given action. (in tenths of a second, e.g. 300 = 30 seconds).ONTIMEOUT local
– Constitutes a default action, which takes place when timeout runs out. As defined by the setting, the action labeled local
takes place. MENU TITLE Turris PXE-Boot Menu
– The title of your boot menu.LABEL local
– Definition of a menu item. MENU LABEL Boot from local hard-drive
– Title under which this menu item appears. Following this is a list of actions, which should be undertaken.LOCALBOOT 0
– Says to perform a boot from the local drive.LABEL ubuntu
– Definition of the next item. MENU LABEL Ubuntu
– Title…KERNEL menu.c32
– Commands to implement a kernel. In this case we will implement menu.c32
again, that is we again show some menu. APPEND pxelinux.cfg/ubuntu.cfg
– Parameters handed over to the kernel. In case of a menu kernel, there would be another configuration file here.
The label with the title ubuntu
leads us to the next screen. It's appearance is defined here:
MENU TITLE Ubuntu Images label ubuntu-14.04 MENU LABEL Ubuntu 14.04 LTS Live/Install DVD 64-Bit KERNEL images/ubuntu-14.04-64/casper/vmlinuz.efi APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/data/tftp/images/ubuntu-14.04-64/ initrd=images/ubuntu-14.04-64/casper/initrd.lz TEXT HELP Starts the Ubuntu 14.04 LTS Live DVD - 64-Bit ENDTEXT
MENU TITLE Ubuntu Images
– Title of the new menu. LABEL ubuntu-14.04
– Definition of a menu item.MENU LABEL Ubuntu 14.04 LTS Live/Install DVD 64-Bit
– Title for a new record.KERNEL images/ubuntu-14.04-64/casper/vmlinuz.efi
– Command to implement a kernel. This label already constitutes an operating system boot, that is why it will be a kernel acquired from an image.APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/data/tftp/images/ubuntu-14.04-64/ initrd=images/ubuntu-14.04-64/casper/initrd.lz
– Parameters passed onto the kernel. Because it is an actual system, it has to say, where the intramdisc is found. The remaining information is a description of how to get data via network. The exact parameters for the kernel will differ across distributions and it is suitable to look for them on the website of the given distribution. TEXT HELP
and ENDTEXT
is help for the given active menu item.A complete list of available options can be found on the Syslinux wikipedia.
Some distributions, for example Debian, provide their own network installer. Those are usually very easy to put into operation – the downloaded files only need to be unpacked into the root of the TFTP server. The installer contains all the required parts including the Syslinux files. However, it is desirable for me in particular to include the Debian installer in my menu.
After unpacking the network installer, it is relatively easy to find out that pxelinux.cfg/default
leads to the file debian-installer/amd64/boot-screens/syslinux.cfg
, which is prepared for work with the graphical version of the menu vesamenu.c32
.
Adding the entire Debian network installer can be achieved through this item in the main menu:
LABEL debian-netinst MENU LABEL Debian netinst KERNEL vesamenu.c32 APPEND debian-installer/amd64/boot-screens/syslinux.cfg
We assume that the network installer is unpacked into the directory /mnt/data/tftp/debian-installer
.
This section presents a manual for other distributions, by means of one example. No further commentary is needed here.
DEFAULT menu.c32 PROMPT 0 TIMEOUT 300 ONTIMEOUT local MENU TITLE Turris at lair-net PXE-Boot Menu LABEL local MENU LABEL Boot from local hard-drive LOCALBOOT 0 LABEL tools MENU LABEL Tools KERNEL menu.c32 APPEND pxelinux.cfg/tools.cfg LABEL debian-netinst-64 MENU LABEL Debian 7 "Wheezy" netinst (64-bit) KERNEL vesamenu.c32 APPEND debian-installer/amd64/boot-screens/syslinux.cfg LABEL debian-netinst-32 MENU LABEL Debian 7 "Wheezy" netinst (32-bit) KERNEL vesamenu.c32 APPEND debian-installer/i386/boot-screens/syslinux.cfg LABEL linux-mint MENU LABEL Linux Mint KERNEL menu.c32 APPEND pxelinux.cfg/linux-mint.cfg LABEL ubuntu MENU LABEL Ubuntu KERNEL menu.c32 APPEND pxelinux.cfg/ubuntu.cfg
MENU TITLE Tools Boot Menu LABEL systemrescuecd-4-tftp MENU LABEL System Rescue CD 4.0.0 32-bit (TFTP) KERNEL images/systemrescuecd-4.0.0/rescue32 APPEND netboot=tftp://192.168.1.1/images/systemrescuecd-4.0.0/sysrcd.dat initrd=images/systemrescuecd-4.0.0/initram.igz TEXT HELP Starts the System Rescue CD - 32-Bit ENDTEXT LABEL systemrescuecd-4-nfs MENU LABEL System Rescue CD 4.0.0 32-bit (NFS) KERNEL images/systemrescuecd-4.0.0/rescue32 APPEND netboot=nfs://192.168.1.1:/mnt/data/tftp/images/systemrescuecd-4.0.0 initrd=images/systemrescuecd-4.0.0/initram.igz TEXT HELP Starts the System Rescue CD - 32-Bit ENDTEXT
MENU TITLE Linux Mint Images LABEL linux-mint-17 MENU LABEL Linux Mint 17.1 Cinnamon Live/Install DVD 64-Bit KERNEL images/mint17-cinnamon-64/casper/vmlinuz APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/data/tftp/images/mint17-cinnamon-64/ initrd=images/mint17-cinnamon-64/casper/initrd.lz TEXT HELP Starts the Linux Mint 17 Live DVD - 64-Bit ENDTEXT LABEL linux-mint-16 MENU LABEL Linux Mint 16 Cinnamon Live/Install DVD 64-Bit KERNEL images/mint16-cinnamon-64/casper/vmlinuz APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/data/tftp/images/mint16-cinnamon-64/ initrd=images/mint16-cinnamon-64/casper/initrd.lz TEXT HELP Starts the Linux Mint 16 Live DVD - 64-Bit ENDTEXT
MENU TITLE Ubuntu Images LABEL ubuntu-14.04 MENU LABEL Ubuntu 14.04 LTS Live/Install DVD 64-Bit KERNEL images/ubuntu-14.04-64/casper/vmlinuz.efi APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/data/tftp/images/ubuntu-14.04-64/ initrd=images/ubuntu-14.04-64/casper/initrd.lz TEXT HELP Starts the Ubuntu 14.04 LTS Live DVD - 64-Bit ENDTEXT