The attached patch adds support for turning a liveCD ISO image into a network-bootable PXE image.

Myself and Chris Lalancette looked into this in some detail and came up with two different ways to do this. This is the simpler of the two methods and results in the least invasive changes to livecd-creator -- just a single line patch to mayflower and a 100-or-so-line extra script called 'livecd-iso-to-pxeboot' which works analogously to 'livecd-iso-to-disk'.

The way it works is to bundle the complete ISO image inside the initrd. The kernel and (bloated) initrd are downloaded using PXE in the normal way, and the init script finds and loopback-mounts the ISO image and booting continues as normal.

One possible con of this approach is whether or not it's a good idea to download a very large (min 200 MB) initrd image over TFTP. There are two reasons we can think of why you *wouldn't* want to do this:

(1) "traditional" TFTP is limited to 32 MB max file size, although all modern TFTP implementations supersede that with a 4 GB limit (RFC 2348).

(2) TFTP uses its own transport layer which might not be able to back-off as nicely as TCP on busy networks.

However in my testing there was no problem at all using TFTP on large files over an ethernet LAN.

The other approach which we looked at and partially implemented was to modify the normal initrd/init so that it could do a separate request to download the ISO. It could possibly do this over another protocol such as HTTP (although in Chris's tests he just used a separate TFTP connection). The implementation of this is considerably more complicated:

(a) The initrd has to carry around dhclient, network scripts, and all the network programs like '/sbin/ip'.

(b) The initrd has to be able to find the TFTP server again, which basically involves making another DHCP query. In Chris's original implementation he also added specific DHCP options to carry the TFTP server information since it wasn't clear how to get this out of stock dhclient.

(c) After booting, because of (b), the network is already set up, which is not how a live CD expects it to be. Therefore the live CD itself would need to be changed if it does any network configuration.

All in all, I would say that the attached patch is a simpler and better approach.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
diff --git a/Makefile b/Makefile
index 393d6db..bf7a0d6 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ install:
 	$(INSTALL_PROGRAM) -D tools/livecd-creator $(DESTDIR)/usr/bin/livecd-creator
 	$(INSTALL_PROGRAM) -D tools/image-creator $(DESTDIR)/usr/bin/image-creator
 	$(INSTALL_PROGRAM) -D tools/livecd-iso-to-disk.sh $(DESTDIR)/usr/bin/livecd-iso-to-disk
+	$(INSTALL_PROGRAM) -D tools/livecd-iso-to-pxeboot.sh $(DESTDIR)/usr/bin/livecd-iso-to-pxeboot
 	$(INSTALL_PROGRAM) -D tools/mayflower $(DESTDIR)/usr/lib/livecd-creator/mayflower
 	$(INSTALL_DATA) -D AUTHORS $(DESTDIR)/usr/share/doc/livecd-tools-$(VERSION)/AUTHORS
 	$(INSTALL_DATA) -D COPYING $(DESTDIR)/usr/share/doc/livecd-tools-$(VERSION)/COPYING
diff --git a/livecd-tools.spec b/livecd-tools.spec
index 8201cc8..cd3e139 100644
--- a/livecd-tools.spec
+++ b/livecd-tools.spec
@@ -4,7 +4,7 @@
 
 Summary: Tools for building live CD's
 Name: livecd-tools
-Version: 013
+Version: 014
 Release: 1%{?dist}
 License: GPLv2
 Group: System Environment/Base
@@ -52,6 +52,7 @@ rm -rf $RPM_BUILD_ROOT
 %doc AUTHORS COPYING README HACKING
 %{_bindir}/livecd-creator
 %{_bindir}/livecd-iso-to-disk
+%{_bindir}/livecd-iso-to-pxeboot
 %dir /usr/lib/livecd-creator
 /usr/lib/livecd-creator/mayflower
 %dir %{_datadir}/livecd-tools
diff --git a/tools/livecd-iso-to-pxeboot.sh b/tools/livecd-iso-to-pxeboot.sh
new file mode 100755
index 0000000..30fe5ac
--- /dev/null
+++ b/tools/livecd-iso-to-pxeboot.sh
@@ -0,0 +1,130 @@
+#!/bin/bash
+# Convert a live CD iso so that it can be booted over the network
+# using PXELINUX.
+# Copyright 2008 Red Hat, Inc.
+# Written by Richard W.M. Jones <[EMAIL PROTECTED]>
+# Based on a script by Jeremy Katz <[EMAIL PROTECTED]>
+# Based on original work by Chris Lalancette <[EMAIL PROTECTED]>
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+export PATH=/sbin:/usr/sbin:$PATH
+
+usage() {
+    echo "Usage: livecd-iso-to-pxeboot <isopath>"
+    exit 1
+}
+
+cleanup() {
+    [ -d "$CDMNT" ] && umount $CDMNT && rmdir $CDMNT
+    [ -d "$INITRDROOT" ] && rm -rf $INITRDROOT
+}
+
+exitclean() {
+    echo "Cleaning up to exit..."
+    cleanup
+    exit 1
+}
+
+if [ $(id -u) != 0 ]; then
+    echo "You need to be root to run this script."
+    exit 1
+fi
+
+# Check pxelinux.0 exists.
+if [ ! -f /usr/lib/syslinux/pxelinux.0 ]; then
+    echo "Warning: /usr/lib/syslinux/pxelinux.0 not found."
+    echo "Make sure syslinux or pxelinux is installed on this system."
+fi
+
+while [ $# -gt 1 ]; do
+    case "$1" in
+	*) usage ;;
+    esac
+    shift
+done
+
+ISO="$1"
+
+if [ -z "$ISO" -o ! -e "$ISO" ]; then
+    usage
+fi
+
+if [ -d tftpboot ]; then
+    echo "Subdirectory tftpboot exists already.  I won't overwrite it."
+    echo "Delete the subdirectory before running."
+    exit 1
+fi
+
+mkdir tftpboot
+
+# Mount the ISO.
+# FIXME: would be better if we had better mountpoints
+CDMNT=$(mktemp -d /media/cdtmp.XXXXXX)
+mount -o loop "$ISO" $CDMNT || exitclean
+
+trap exitclean SIGINT SIGTERM
+
+# Does it look like an ISO?
+if [ ! -d $CDMNT/isolinux -o ! -f $CDMNT/isolinux/initrd0.img ]; then
+    echo "The ISO image doesn't look like a LiveCD ISO image to me."
+    exitclean
+fi
+
+# Put the ISO image inside the initrd.
+INITRDROOT=$(mktemp -d /media/initrd.XXXXXX)
+gzip -dc $CDMNT/isolinux/initrd0.img | (cd $INITRDROOT && cpio -id)
+cp "$ISO" $INITRDROOT
+(cd $INITRDROOT && find . | cpio -H newc --quiet -o | gzip -9) > tftpboot/initrd0.img
+rm -rf $INITRDROOT
+INITRDROOT=
+
+# Kernel image.
+cp $CDMNT/isolinux/vmlinuz0 tftpboot/vmlinuz0
+
+# pxelinux bootloader.
+if [ -f /usr/lib/syslinux/pxelinux.0 ]; then
+    cp /usr/lib/syslinux/pxelinux.0 tftpboot
+else
+    echo "Warning: You need to add pxelinux.0 to tftpboot/ subdirectory"
+fi
+
+# pxelinux configuration.
+mkdir tftpboot/pxelinux.cfg
+ISOBASENAME=`basename "$ISO"`
+cat > tftpboot/pxelinux.cfg/default <<EOF
+DEFAULT pxeboot
+TIMEOUT 20
+PROMPT 0
+LABEL pxeboot
+	KERNEL vmlinuz0
+	APPEND initrd=initrd0.img root=/$ISOBASENAME rootfstype=iso9660 rootflags=loop
+ONERROR LOCALBOOT 0
+EOF
+
+# All done, clean up.
+umount $CDMNT
+rmdir $CDMNT
+
+echo "Your pxeboot image is complete."
+echo
+echo "Copy tftpboot/ subdirectory to /tftpboot or a subdirectory of /tftpboot."
+echo "Set up your DHCP, TFTP and PXE server to serve /tftpboot/.../pxeboot.0"
+echo
+echo "Note: The initrd image contains the whole CD ISO and is consequently"
+echo "very large.  You will notice when pxebooting that initrd can take a"
+echo "long time to download.  This is normal behaviour."
+
+exit 0
+
diff --git a/tools/mayflower b/tools/mayflower
index 2e46098..162d4d4 100755
--- a/tools/mayflower
+++ b/tools/mayflower
@@ -477,7 +477,8 @@ if [ "$shell" == "1" ] ; then
 fi
 
 # don't wait for "mtd0" as no device file will appear
-if [ "$root" != "mtd0" ] ; then
+# and don't worry about this if $thingtomount is a regular file
+if [ "$root" != "mtd0" -a ! -f "$thingtomount" ] ; then
 
     # If we don't have the /dev/root link.. ask the user to create..
     if [ "$waitforsymlink" != "1" ] ; then

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

--
Fedora-livecd-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/fedora-livecd-list

Reply via email to