2 # Convert a live CD iso so that it can be booted over the network
4 # Copyright 2008 Red Hat, Inc.
5 # Written by Richard W.M. Jones <rjones@redhat.com>
6 # Based on a script by Jeremy Katz <katzj@redhat.com>
7 # Based on original work by Chris Lalancette <clalance@redhat.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 export PATH
=/sbin
:/usr
/sbin
:$PATH
25 echo "Usage: livecd-iso-to-pxeboot <isopath>"
30 [ -d "$CDMNT" ] && umount
$CDMNT && rmdir $CDMNT
34 echo "Cleaning up to exit..."
39 if [ $
(id
-u) != 0 ]; then
40 echo "You need to be root to run this script."
44 # Check pxelinux.0 exists.
45 if [ ! -f /usr
/lib
/syslinux
/pxelinux
.0 ]; then
46 echo "Warning: /usr/lib/syslinux/pxelinux.0 not found."
47 echo "Make sure syslinux or pxelinux is installed on this system."
50 while [ $# -gt 1 ]; do
59 if [ -z "$ISO" -o ! -e "$ISO" ]; then
63 if [ -d tftpboot
]; then
64 echo "Subdirectory tftpboot exists already. I won't overwrite it."
65 echo "Delete the subdirectory before running."
72 # FIXME: would be better if we had better mountpoints
73 CDMNT
=$
(mktemp
-d /media
/cdtmp.XXXXXX
)
74 mount
-o loop
"$ISO" $CDMNT || exitclean
76 trap exitclean SIGINT SIGTERM
78 # Does it look like an ISO?
79 if [ ! -d $CDMNT/isolinux
-o ! -f $CDMNT/isolinux
/initrd0.img
]; then
80 echo "The ISO image doesn't look like a LiveCD ISO image to me."
84 # Create a cpio archive of just the ISO and append it to the
85 # initrd image. The Linux kernel will do the right thing,
86 # aggregating both cpio archives (initrd + ISO) into a single
88 ISOBASENAME
=`basename "$ISO"`
89 ISODIRNAME
=`dirname "$ISO"`
90 ( cd "$ISODIRNAME" && echo "$ISOBASENAME" |
cpio -H newc
--quiet -o ) |
92 cat $CDMNT/isolinux
/initrd0.img
- > tftpboot
/initrd0.img
95 cp $CDMNT/isolinux
/vmlinuz0 tftpboot
/vmlinuz0
97 # pxelinux bootloader.
98 if [ -f /usr
/lib
/syslinux
/pxelinux
.0 ]; then
99 cp /usr
/lib
/syslinux
/pxelinux
.0 tftpboot
101 echo "Warning: You need to add pxelinux.0 to tftpboot/ subdirectory"
104 # pxelinux configuration.
105 mkdir tftpboot
/pxelinux.cfg
106 cat > tftpboot
/pxelinux.cfg
/default
<<EOF
112 APPEND initrd=initrd0.img root=/$ISOBASENAME rootfstype=iso9660 rootflags=loop
116 # All done, clean up.
120 echo "Your pxeboot image is complete."
122 echo "Copy tftpboot/ subdirectory to /tftpboot or a subdirectory of /tftpboot."
123 echo "Set up your DHCP, TFTP and PXE server to serve /tftpboot/.../pxeboot.0"
125 echo "Note: The initrd image contains the whole CD ISO and is consequently"
126 echo "very large. You will notice when pxebooting that initrd can take a"
127 echo "long time to download. This is normal behaviour."