2011-04-05, 18:10
I have created a simple Perl-based script which can be hooked into any web server that supports a standard CGI interface.
You can find the code at: http://github.com/robinsmidsrod/pxe-dispatcher
What I usually do is to symlink this script in the root of my TFTP root (/srv/tftp/ on Ubuntu, which I use) and then I share out that folder as a Samba share (so I can edit the files from a Windows desktop machine). At the end I create a symlink in /var/www/tftp that points to /srv/tftp. This way I can easily boot from either TFTP or HTTP with the same files.
If I create /srv/tftp/pxeboot/default.pxe, this script will automatically be executed by iPXE on boot. If default.pxe doesn't exist, pxelinux.0 is booted if it exists. pxelinux.0 should be installed alongside pxeboot.cgi.
The more interesting part of the script is the part that allows you to create custom boot scripts by MAC of the client. They should be named something like /srv/tftp/pxeboot/0025b35fd52f.pxe. The content of the file is just a normal iPXE script.
My laptop has a boot script file which contains the following code:
And for that to work I have a separate file named /srv/tftp/pxeboot/freedos.pxe with the following code in it:
This enables me to boot FreeDOS on my laptop entirely from an iSCSI target.
Another script I have is named ubuntu-install.pxe and it contains the following code:
For booting Ubuntu, I just use a script similar to the FreeDOS variant, just with the strings "freedos" replaced with "ubuntu".
Hope some of you will find it useful, and I would love if any of you have any ideas for improvements. If you make any improvements, do send me a pull request on GitHub.
You can find the code at: http://github.com/robinsmidsrod/pxe-dispatcher
What I usually do is to symlink this script in the root of my TFTP root (/srv/tftp/ on Ubuntu, which I use) and then I share out that folder as a Samba share (so I can edit the files from a Windows desktop machine). At the end I create a symlink in /var/www/tftp that points to /srv/tftp. This way I can easily boot from either TFTP or HTTP with the same files.
If I create /srv/tftp/pxeboot/default.pxe, this script will automatically be executed by iPXE on boot. If default.pxe doesn't exist, pxelinux.0 is booted if it exists. pxelinux.0 should be installed alongside pxeboot.cgi.
The more interesting part of the script is the part that allows you to create custom boot scripts by MAC of the client. They should be named something like /srv/tftp/pxeboot/0025b35fd52f.pxe. The content of the file is just a normal iPXE script.
My laptop has a boot script file which contains the following code:
Code:
#!ipxe
echo
echo Booting HP laptop
chain freedos.pxe
And for that to work I have a separate file named /srv/tftp/pxeboot/freedos.pxe with the following code in it:
Code:
#!ipxe
echo
echo Booting FreeDOS for ${hostname} from SAN
set keep-san 1
set root-path iscsi:nas.smidsrod.lan::::iqn.2011-02.lan.smidsrod:${hostname}.boot.freedos
sanboot ${root-path}
echo Boot from ${root-path} failed, dropping to shell
shell
This enables me to boot FreeDOS on my laptop entirely from an iSCSI target.
Another script I have is named ubuntu-install.pxe and it contains the following code:
Code:
#!ipxe
echo
echo Installing Ubuntu for ${hostname} from SAN
# Setup iSCSI root path
set root-path iscsi:nas.smidsrod.lan::::iqn.2011-02.lan.smidsrod:${hostname}.boot.ubuntu
set skip-san-boot 1
set keep-san 1
# Hook iSCSI target
sanboot ${root-path}
# Boot kernel+initrd for Ubuntu install
kernel http://boot.smidsrod.lan/ubuntu-10.10-amd64-server/boot/linux
initrd http://boot.smidsrod.lan/ubuntu-10.10-amd64-server/boot/initrd.gz
imgargs linux ks=http://boot.smidsrod.lan/ubuntu-10.10-amd64-server/boot/ks.cfg
boot
echo Booting failed, dropping to shell
shell
For booting Ubuntu, I just use a script similar to the FreeDOS variant, just with the strings "freedos" replaced with "ubuntu".
Hope some of you will find it useful, and I would love if any of you have any ideas for improvements. If you make any improvements, do send me a pull request on GitHub.