User Tools

Site Tools

This wiki is read only and for archival purposes only. >>>>>>>>>> Please use the new OpenWrt wiki at <<<<<<<<<<

This is an old revision of the document!

PXE-Boot from OpenWRT

In some cases you want to use your OpenWRT as a PXE-Server to network-boot other devices. Reasons could be:

  • Boot Ubuntu / Debian / CentOS Live Systems
  • Install any Linux Distrib. or Windows (via winpe) over network
  • Boot debugging tools like knoppix / gparted / clonezilla / backtrack

The following example shows how to provide PXE-Booting for Ubuntu Live System on an OpenWRT Router.

Basic idea:

  • Connect USB Mass Storage to router to store PXE-Boot files and Live Images
  • use dnsmasq service for dhcp & tftp readonly booting
  • use nfs for further service booting (required by e.g. ubuntu)

Booting other Linux based distributions is not very different, only the boot parameters differ and can be found everywhere on the internet.

The following instructions have been done step-by-step on an OpenWRT Attitude Adjustment 12.09 on a tl-wdr3600on 6th of December 2013

1. Install Mass Storage

Install USB-Support

root@OpenWRT:~# opkg install usbutils kmod-usb-storage  block-mount
Show connected USB-Devices
root@OpenWRT:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 003: ID 0951:1600 Kingston Technology DataTraveler G3 4GB
Verify the USB-device in /dev

We assume that the USB-device is plugged in and has been formatted to FAT32 or EXT2,3

If you have a NTFS filesystem please install NTFS support: opkg install ntfs-3g For more information on NTFS see writable_ntfs

root@OpenWRT:~# ls -l /dev/sd*
brw-r--r--    1 root    root        8,   0 Jan  1  1970 /dev/sda
brw-r--r--    1 root    root        8,   1 Dec  6 17:52 /dev/sda1
Create mountpoint for usbdevice
root@OpenWRT:~# mkdir /mnt/extstorage
Enable automatic mounting of external USB Storage. For additional Information see fstab
root@OpenWRT:~# vim /etc/config/fstab
config global automount
        option from_fstab 1
        option anon_mount 1

config global autoswap
        option from_fstab 1
        option anon_swap 0

config mount
        option target   /mnt/extstorage
        option device   /dev/sda1
        option enabled  1
        option enabled_fsck 0
Now enable start of fstab-service on boot of OpenWRT
root@OpenWRT:~# /etc/init.d/fstab enable
Start fstab this time manually
root@OpenWRT:~# /etc/init.d/fstab start
Verify that the USB Mass Storage /dev/sda1 is mounted to /mnt/extstorage
root@OpenWRT:~# mount | grep extstorage
/dev/sda1 on /mnt/extstorage type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
For testing purposes, touch a file on the usb-stick and reboot OpenWrt router:
root@OpenWRT:~# touch /mnt/extstorage/test.txt
root@OpenWRT:~# reboot
After the reboot you should be able to verify again that the USB Mass Storage is mounted to /mnt/extstorage and that the test.txt exists.

2. Prepare files for PXE-Booting

Generate TFTP-Boot folder structure and files:

root@OpenWRT:~# cd /mnt/extstorage
root@OpenWRT:~# mkdir tftp tftp/pxelinux.cfg tftp/disks tftp/disks/ubuntu1310-64

Now you have to download syslinux. Download Syslinux Direct-Link to 13-Oct-2013 Syslinux v6.02

The basic wget from OpenWRT does NOT support wget from https://. The following steps could be done by downloading the syslinux to your pc and transfer the required files manually to your usb-stick.

Because the basic OpenWRT wget does not support https, we have to install the package wget (thanks to theoradicus for giving this important hint) and the extended tar command to extract the compressed archive afterwards:

root@OpenWRT:~# opkg update
root@OpenWRT:~# opkg install wget tar

Now we can download the syslinux archive and extract it. We do not have the public SSL-CAs on our OpenWRT so we have to NOT check the server-certificate:

root@OpenWRT:~# mkdir /mnt/extstorage/syslinux-download
root@OpenWRT:~# cd /mnt/extstorage/syslinux-download
root@OpenWRT:/mnt/extstorage/syslinux-download# wget --no-check-certificate
root@OpenWRT:/mnt/extstorage/syslinux-download# tar -xf syslinux-6.02.tar.gz

You have to copy the following files from the syslinux to your tftp-folder:

  • ./bios/core/pxelinux.0
  • ./bios/com32/elflink/ldlinux/ldlinux.c32
  • ./bios/com32/menu/vesamenu.c32
  • ./bios/com32/lib/libcom32.c32
  • ./bios/com32/libutil/libutil.c32

As one single long copy-command:

root@OpenWRT:~# cd /mnt/extstorage/syslinux-download/syslinux-6.02/bios
root@OpenWRT:/mnt/extstorage/syslinux-download/syslinux-6.02/bios# cp core/pxelinux.0 com32/elflink/ldlinux/ldlinux.c32 com32/menu/vesamenu.c32 com32/lib/lib
com32.c32 com32/libutil/libutil.c32 /mnt/extstorage/tftp

Hint: We do a BIOS / Legacy PXE Boot - NOT an UEFI boot, this is something completely different!

Now we create our default menu-file:

root@OpenWRT:~# vim /mnt/extstorage/tftp/pxelinux.cfg/default
DEFAULT vesamenu.c32

label Ubuntu
        MENU LABEL Ubuntu Live 13.10 64-Bit
        KERNEL disks/ubuntu/casper/vmlinuz.efi
        APPEND boot=casper ide=nodma netboot=nfs nfsroot= initrd=disks/ubuntu/casper/initrd.lz
        TEXT HELP
                Starts the Ubuntu Live-CD - Version 13.10 64-Bit

As you can see we need nfs for this operating system. Other operating systems like clonezilla can be fully booted via TFTP an do not need an additional nfs service.

We now have to download and extract the Ubuntu 13.10 to the USB-Drive.

One Option is to do this directly on the OpenWRT itself, but I downloaded the Ubuntu ISO on my computer and plugged in the USB-Drive from OpenWRT and put only the extracted files onto the USB-Drive

Finally, you should have something like the following folder structure:

root@OpenWRT:~#  cd ..
root@OpenWRT:~# # find /mnt/extstorage/tftp/

3. Enable TFTP and NFS Service

Configure dnsmasq service to enable read-only tftp-service

root@OpenWRT:~# vim /etc/config/dhcp
config dnsmasq
         ... a lot of config done before...
        option enable_tftp '1'
        option tftp_root '/mnt/extstorage/tftp'
        ... a lot more config

config boot linux
        option filename 'pxelinux.0'
        option serveraddress ''
        option servername 'OpenWRT'

root@OpenWRT:~# /etc/init.d/dnsmasq restart

Now we have to install and configure the NFS-Service:

root@OpenWRT:~# opkg install nfs-kernel-server

Configure NFS-Share now

root@OpenWRT:~# vim /etc/exports
/mnt/extstorage/tftp/disks  *(ro,async,no_subtree_check)

Now enable portmap and nfsd and (re)start them

root@OpenWRT:~# /etc/init.d/portmap enable
root@OpenWRT:~# /etc/init.d/portmap restart
root@OpenWRT:~# /etc/init.d/nfsd enable
root@OpenWRT:~# /etc/init.d/nfsd restart

And now we are ready to go! Just grab a computer (or Virtual Machine) and PXE Boot - you should be able to fully boot into Ubuntu 13.10 via your OpenWRT Router :-D Hint: you often have to enable PXE-Booting in BIOS and press e.g. F12 to get into the Boot-Menu.

doc/howto/tftp.pxe-server.1510102779.txt.bz2 · Last modified: 2017/11/08 01:59 by leeand00