6/5/10

Linux LiveCDs via PXE with Tomato in between

This post will walk you through configuring your linux system as a TFTP server that can serve pxelinux for booting a system over PXE. I use Tomato at home and I want to use that still as my DHCP server so I will be skipping the steps of setting up DHCP or DNSMASQ to serve ips etc. There are plenty of tutorials online for this.

Add configuration to Tomato

There is one thing we need to setup on Tomato so that we can hand the TFTP server portion of booting off to our linux server:

Under Advanced -> DHCP/DNS -> Custom Configuration for DNSmasq

Where 192.168.9.100 is the ip of the TFTP server.

dhcp-boot=pxelinux.0,,192.168.9.100

That is it save the configuration and now on to configuring the linux system.

Daemons

The Daemons/Service required for this system are as follows:
  • DHCP (Via tomato)
  • TFTP (Linux Server)
  • NFS (Linux Server)

This post will go through setting up these servers but please do not consider these settings by any means secure, securing NFS and TFTP for a public facing system is beyond the scope of this post.

Installing TFTP server

If you already have a TFTP server setup you can skip this section.

apt-get install tftpd-hpa

That is it, thank you debian/ubuntu :)

All files will be served out of /var/lib/tftpboot


Network File System Server (NFS)

The NFS daemon is sharing files to anyone on your network please use with caution :)

Install the server

apt-get install nfs-kernel-server

Configure exports for the NFS server by editing /etc/exports and adding the following

/var/lib/tftpboot/oses 192.168.9.0/24(ro,sync,no_subtree_check)

Note the 192.168.9.0/24 restricts this mount to the network 192.168.9.0-255, if you want all clients to be able to connect change that to simply a * which will export the share to the WORLD

Tell NFS about your updated exports:

sudo exportfs -r

Verify it is now exported via NFS:

sudo exportfs

That is it, all of your pxe bootable oses rootfile systems will live in /var/lib/tftpboot/oses

For more info on NFS please refer to: http://nfs.sourceforge.net/


PXELINUX Setup

The meat of the tutorial, how to setup PXELINUX to boot a Live CD

Install syslinux (apt-get install syslinux) and copy pxelinux.0 and menu.c32 to /var/lib/tftpboot

cp /usr/lib/syslinux/menu.c32 /var/lib/tftpboot
cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot


Create the directory where we are going to put all of our pxe linux configurations

mkdir /var/lib/tftpboot/pxelinux.cfg

pxelinux.cfg/default

We need to create a simple default configuration to load up a menu.

SERIAL 0 115200
PROMPT 0
DEFAULT menu.c32                             
INCLUDE pxelinux.cfg/linux.cfg


Notice the include pxelinux.cfg/linux.cfg

This is the file where we will add menu items for our PXE Boot menu. There are a lot of different ways to set up this portion and I suggest you check out the references for a more complete run down on configuring PXE.


Adding items to linux.cfg

Below are a few examples walking you through adding entries to your linux.cfg so you can boot to different OSes.


PXE Boot a Ubuntu Live CD

This uses Hardy but this will work with any Ubuntu live cd and most likely most others with little to no modification

Download the iso and copy out the meat of the iso we need to boot it:

wget http://releases.ubuntu.com/releases/9.10/ubuntu-9.10-desktop-i386.iso
mount ubuntu-9.10-desktop-i386.iso /mnt -o loop
mkdir /var/lib/tftpboot/oses/9.10_desktop
cp -a /mnt/casper/ /var/lib/tftpboot/9.10_desktop/
umount /mnt

Linux.cfg configuration


LABEL 9.10
   MENU LABEL Ubuntu Live (9.10_desktop)
   KERNEL /oses/9.10_desktop/casper/vmlinuz
   APPEND initrd=/oses/9.10_desktop/casper/initrd.lz netboot=nfs nfsroot=192.168.9.100:/var/lib/tftpboot/oses/9.10_desktop boot=casper --





PXE Boot CloneZilla

download iso http://clonezilla.org/download/sourceforge/alternative/iso-zip-files.php

mount clonezilla*.iso /mnt
cp /mnt/live/* /var/lib/tftp/oses/clonezilla/


Linux.cfg configuration

LABEL Clonezilla                                                                         
MENU LABEL CloneZilla
KERNEL /oses/clonezilla/live/vmlinuz                                                       
APPEND initrd=/oses/clonezilla/live/initrd.img boot=live debug union=aufs hostname=cloneZIZZY noswap nolocales edd=on ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" ip=frommedia netboot=nfs nfsroot=192.168.9.100:/var/lib/tftpboot/oses/clonezilla --

Or another (better?) approach to loading CloneZilla via PXE
http://clonezilla.org/clonezilla-live/livepxe.php


PXE Boot Memtest86

This is available on pretty much every linux distribution nowadays and resides in /boot/memtest86+.bin

Copy that file to your desired tftp os directory

cp /boot/memtest86+.bin /var/lib/tftpboot/oses/memtest86+/memtest86+

*Note file extensions do affect pxe behavior so be sure not to include the .bin extension.

Linux.cfg configuration

LABEL memtest86+
MENU LABEL memtest86+
KERNEL /oses/memtest86+/memtest86


Tada!

That is it. At the end of the day you should have a file structure similar to this:

/var/lib/tftpboot/
/var/lib/tftpboot/pxelinux.0
/var/lib/tftpboot/menu.c32
/var/lib/tftpboot/pxelinux.cfg
/var/lib/tftpboot/pxelinux.cfg/linux.cfg
/var/lib/tftpboot/pxelinux.cfg/default
/var/lib/tftpboot/oses/9.10_desktop
/var/lib/tftpboot/oses/memtest86+
/var/lib/tftpboot/oses/clonezilla

You can pretty much boot any operating system this way but each comes with its own quirks. Search around there is plenty of information for booting your OS of choice. 

References

6 comments:

  1. Nice howto .. I did notice one thing though.

    Bit of a typo on the dhcp line

    dchp-boot=pxelinux.0,,192.168.9.100

    should be

    dhcp-boot=pxelinux.0,,192.168.9.100

    ReplyDelete
  2. Thank you for pointing that out, fixed! :)

    ReplyDelete
  3. have you considered your tomato router being the pxe server as well? I would like to get it working on mine. I have an Asus RT-N16 running shiiby's newest build that includes NFS modules. Should be possible to be the router, NAS, and PXE server. Any thoughts or suggestions would be great.

    ReplyDelete
  4. I have not tried out shibby builds yet, but it is on my list. From the features available it should be relatively easy to this up end to end on your router. I have a spot of time coming up in the near future and I may take a crack at it myself and update this post. This for the pointer and if I get anywhere i'll let you know.

    ReplyDelete
  5. Any luck? I have an n16 as well, I am thinking I could use my external drive I have hooked up. Thanks for the write up!

    ReplyDelete