In some cases you want to use your OpenWRT as a PXE-Server to network-boot other devices. Reasons could be:
The following example shows how to provide PXE-Booting for Ubuntu Live System on an OpenWRT Router.
Basic idea:
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
Install USB-Support
root@OpenWRT:~# opkg install usbutils kmod-usb-storage block-mountShow 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 4GBVerify 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/sda1Create mountpoint for usbdevice
root@OpenWRT:~# mkdir /mnt/extstorageEnable 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 enableStart fstab this time manually
root@OpenWRT:~# /etc/init.d/fstab startVerify 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:~# rebootAfter 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.
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 https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.02.tar.gz 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:
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/libcom32.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
PROMPT 0
MENU TITLE OpenWRT PXE-Boot Menu
label Ubuntu
MENU LABEL Ubuntu Live 13.10 64-Bit
KERNEL disks/ubuntu/casper/vmlinuz.efi
APPEND boot=casper ide=nodma netboot=nfs nfsroot=192.168.1.1:/mnt/extstorage/tftp/disks/ubuntu1310-64/ initrd=disks/ubuntu/casper/initrd.lz
TEXT HELP
Starts the Ubuntu Live-CD - Version 13.10 64-Bit
ENDTEXT
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/ /mnt/extstorage/tftp/ /mnt/extstorage/tftp/disks /mnt/extstorage/tftp/disks/ubuntu1310-64 /mnt/extstorage/tftp/disks/ubuntu1310-64/pics ... /mnt/extstorage/tftp/disks/ubuntu1310-64/EFI ... /mnt/extstorage/tftp/disks/ubuntu1310-64/README.diskdefines /mnt/extstorage/tftp/disks/ubuntu1310-64/autorun.inf /mnt/extstorage/tftp/disks/ubuntu1310-64/casper /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/filesystem.size /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/initrd.lz /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/vmlinuz.efi /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/filesystem.manifest /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/filesystem.manifest-remove /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/filesystem.squashfs /mnt/extstorage/tftp/disks/ubuntu1310-64/isolinux ... /mnt/extstorage/tftp/disks/ubuntu1310-64/pool ... /mnt/extstorage/tftp/disks/ubuntu1310-64/wubi.exe /mnt/extstorage/tftp/disks/ubuntu1310-64/preseed ... /mnt/extstorage/tftp/disks/ubuntu1310-64/md5sum.txt /mnt/extstorage/tftp/disks/ubuntu1310-64/install /mnt/extstorage/tftp/disks/ubuntu1310-64/install/mt86plus /mnt/extstorage/tftp/disks/ubuntu1310-64/dists ... /mnt/extstorage/tftp/disks/ubuntu1310-64/ubuntu /mnt/extstorage/tftp/disks/ubuntu1310-64/boot ... /mnt/extstorage/tftp/ldlinux.c32 /mnt/extstorage/tftp/libcom32.c32 /mnt/extstorage/tftp/libutil.c32 /mnt/extstorage/tftp/pxelinux.0 /mnt/extstorage/tftp/pxelinux.cfg /mnt/extstorage/tftp/pxelinux.cfg/default /mnt/extstorage/tftp/vesamenu.c32
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 '192.168.1.1'
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
Hint: you often have to enable PXE-Booting in BIOS and press e.g. F12 to get into the Boot-Menu.
Note: It will help immensely to check your sys.log to see what path is actually being used to pull the pxelinux.0, vmlinuz.efi (kernel file), initrd.lz (which are transferred via tftp), etc…but of course you have to set that up on the router as well.
For instance in sys.log I received the following messages when I got mine working:
Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: error 0 TFTP Aborted received from 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: failed sending /mnt/extstorage/tftp/pxelinux.0 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/pxelinux.0 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/ldlinux.c32 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/44454c4c-4e00-104e-8038-b6c04f4a4431 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/01-00-1c-23-86-01-07 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A801EB not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A801E not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A801 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A80 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A8 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0A not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C0 not found Tue Nov 7 19:28:20 2017 daemon.err dnsmasq-tftp[16313]: file /mnt/extstorage/tftp/pxelinux.cfg/C not found Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/pxelinux.cfg/default to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/vesamenu.c32 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/libcom32.c32 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/libutil.c32 to 192.168.1.235 Tue Nov 7 19:28:20 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/pxelinux.cfg/default to 192.168.1.235 Tue Nov 7 19:28:34 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/vmlinuz.efi to 192.168.1.235 Tue Nov 7 19:28:42 2017 daemon.info dnsmasq-tftp[16313]: sent /mnt/extstorage/tftp/disks/ubuntu1310-64/casper/initrd.lz to 192.168.1.235 Tue Nov 7 19:29:24 2017 daemon.info dnsmasq-dhcp[16313]: DHCPDISCOVER(br-lan) 00:1c:23:86:01:07 Tue Nov 7 19:29:24 2017 daemon.info dnsmasq-dhcp[16313]: DHCPOFFER(br-lan) 192.168.1.235 00:1c:23:86:01:07 Tue Nov 7 19:29:24 2017 daemon.info dnsmasq-dhcp[16313]: DHCPREQUEST(br-lan) 192.168.1.235 00:1c:23:86:01:07 Tue Nov 7 19:29:24 2017 daemon.info dnsmasq-dhcp[16313]: DHCPACK(br-lan) 192.168.1.235 00:1c:23:86:01:07 Tue Nov 7 19:29:24 2017 daemon.notice rpc.mountd[16219]: authenticated mount request from 192.168.1.235:777 for /mnt/extstorage/tftp/disks/ubuntu1310-64 (/mnt/extstorage/tftp/disks)