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
/share
/syslinux
/pxelinux
.0 -a ! -f /usr
/lib
/syslinux
/pxelinux
.0 ]; then
46 echo "Warning: 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."
70 # FIXME: would be better if we had better mountpoints
71 CDMNT
=$
(mktemp
-d /media
/cdtmp.XXXXXX
)
72 mount
-o loop
"$ISO" $CDMNT || exitclean
74 trap exitclean SIGINT SIGTERM
76 # Does it look like an ISO?
77 if [[ ( ! -d $CDMNT/isolinux
) ||
( ! -f $CDMNT/isolinux
/initrd0.img
&& ! -f $CDMNT/isolinux
/initrd.img
) ]]; then
78 echo "The ISO image doesn't look like a LiveCD ISO image to me."
82 if [[ -f $CDMNT/isolinux
/initrd0.img
]]; then
92 # Create a cpio archive of just the ISO and append it to the
93 # initrd image. The Linux kernel will do the right thing,
94 # aggregating both cpio archives (initrd + ISO) into a single
96 ISOBASENAME
=`basename "$ISO"`
97 ISODIRNAME
=`dirname "$ISO"`
98 ( cd "$ISODIRNAME" && echo "$ISOBASENAME" |
cpio -H newc
--quiet -L -o ) |
100 cat $CDMNT/isolinux
/$INITRD - > tftpboot
/$INITRD
103 cp $CDMNT/isolinux
/$VMLINUZ tftpboot
/$VMLINUZ
105 # pxelinux bootloader.
106 if [ -f /usr
/share
/syslinux
/pxelinux
.0 ]; then
107 cp /usr
/share
/syslinux
/pxelinux
.0 tftpboot
108 elif [ -f /usr
/lib
/syslinux
/pxelinux
.0 ]; then
109 cp /usr
/lib
/syslinux
/pxelinux
.0 tftpboot
111 echo "Warning: You need to add pxelinux.0 to tftpboot/ subdirectory"
114 # Get boot append line from original cd image.
115 if [ -f $CDMNT/isolinux
/isolinux.cfg
]; then
116 APPEND
=$
(grep -m1 append
$CDMNT/isolinux
/isolinux.cfg |
sed -e "s#CDLABEL=[^ ]*#/$ISOBASENAME#" -e "s/ *append *//")
119 # pxelinux configuration.
120 mkdir tftpboot
/pxelinux.cfg
121 cat > tftpboot
/pxelinux.cfg
/default
<<EOF
127 APPEND rootflags=loop $APPEND
131 # All done, clean up.
135 echo "Your pxeboot image is complete."
137 echo "Copy tftpboot/ subdirectory to /tftpboot or a subdirectory of /tftpboot."
138 echo "Set up your DHCP, TFTP and PXE server to serve /tftpboot/.../pxeboot.0"
140 echo "Note: The initrd image contains the whole CD ISO and is consequently"
141 echo "very large. You will notice when pxebooting that initrd can take a"
142 echo "long time to download. This is normal behaviour."