summaryrefslogtreecommitdiffstats
path: root/scripts/mk-images.x86
blob: fe7a978b969d2d89e61971fa6dad455130f35579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#
# mk-images.x86
#
# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

SYSLINUX=$IMGPATH/usr/share/syslinux/syslinux-nomtools

if [ ! -f $SYSLINUX ]; then
  echo "Warning: nomtools syslinux doesn't exist"
  SYSLINUX=$IMGPATH/usr/bin/syslinux
  if [ ! -f $SYSLINUX ]; then
    echo "$SYSLINUX doesn't exist"
    exit 1
  fi
fi

# prepare a directory with the kernel, initrd, and various message files
# used to populate a boot image
prepareBootTree() {
	(cd $BOOTDISKDIR; find . -maxdepth 1 ! -name "*.msg" ! -type d | cpio --quiet -p $MBD_BOOTTREE)
	
	ln $MBD_FSIMAGE $MBD_BOOTTREE/initrd.img
	cp $KERNELROOT/boot/vmlinuz-* $MBD_BOOTTREE/vmlinuz

	if [ -f $IMGPATH/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg ]; then
		cp $IMGPATH/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg $MBD_BOOTTREE/splash.jpg
		cp $IMGPATH/usr/share/syslinux/vesamenu.c32 $MBD_BOOTTREE/vesamenu.c32
		sed -i s'/default linux/default vesamenu.c32/g' $MBD_BOOTTREE/syslinux.cfg
		sed -i 's/prompt 1/#prompt 1/g' $MBD_BOOTTREE/syslinux.cfg
	elif [ -x $IMGPATH/usr/lib/anaconda-runtime/splashtolss.sh ]; then
		$IMGPATH/usr/lib/anaconda-runtime/splashtolss.sh $BOOTDISKDIR/syslinux-splash.png $BOOTDISKDIR/splash.lss
		if [ $? != 0 ]; then
		    echo $0: Failed to create splash.lss
		    exit 1
		fi    
		cp $BOOTDISKDIR/splash.lss $MBD_BOOTTREE/splash.lss
	elif [ -f $IMGPATH/usr/lib/anaconda-runtime/splash.lss ]; then
		cp $IMGPATH/usr/lib/anaconda-runtime/splash.lss $MBD_BOOTTREE/splash.lss
	fi

	rm -f $MBD_BOOTTREE/syslinux-splash.png
	sed -i "s/@PRODUCT@/$PRODUCT/g" $MBD_BOOTTREE/syslinux.cfg
	sed -i "s/@VERSION@/$VERSION/g" $MBD_BOOTTREE/syslinux.cfg

	rm -f $MBD_BOOTTREE/memtest*
	for file in $BOOTDISKDIR/*.msg; do
	    filename=`basename $file`
	    sed -e "s/@VERSION@/$VERSION/g" $file > $MBD_BOOTTREE/$filename
	done
	if [ $? != 0 ]; then
	    echo $0: Failed to copy messages from $BOOTDISKDIR to $MBD_BOOTTREE.
	    umount $MBD_BOOTTREE
	    rm -rf $MBD_BOOTTREE $MBD_TMPIMAGE
	    exit 1
	fi
}

mkdir -p $TOPDESTPATH/images/pxeboot
cat > $TOPDESTPATH/images/README <<EOF
This directory contains image files that can be used to create media
capable of starting the $PRODUCT installation process.

The boot.iso file is an ISO 9660 image of a bootable CD-ROM.  It is useful
in cases where the CD-ROM installation method is not desired, but the
CD-ROM's boot speed would be an advantage.

To use this image file, burn the file onto CD-R (or CD-RW) media as you
normally would.
EOF

makeBootImages() {
  local initrd="initrd.img"
  local kernelimage="vmlinuz"

  if [ "$kernelvers" = "$kernelxen" ] ; then
    local tag="${kernelvers#kernel}"
    if [ -n "$tag" -a "$tag" != "$kernelvers" ] ; then
      initrd="initrd${tag}.img"
      kernelimage="vmlinuz${tag}"
    fi
  fi

  echo "Building $initrd"
  makeinitrd --initrdto $TOPDESTPATH/images/pxeboot/$initrd \
	--initrdsize 8192 \
	--loaderbin loader \
	--modules "$INITRDMODS"
  [ $? = 0 ] || exit 1

  if [ "$kernelvers" != "$kernelxen" ] ; then
    if [ -f $IMGPATH/usr/share/syslinux/isolinux.bin ]; then
	echo "Building isolinux directory"
	MBD_BOOTTREE=$TOPDESTPATH/isolinux
	MBD_FSIMAGE=$TOPDESTPATH/images/pxeboot/initrd.img
	mkdir $MBD_BOOTTREE
	cp $IMGPATH/usr/share/syslinux/isolinux.bin $MBD_BOOTTREE/isolinux.bin

	prepareBootTree

	# isolinux needs the config file to be isolinux.cfg
	mv $MBD_BOOTTREE/syslinux.cfg $MBD_BOOTTREE/isolinux.cfg

	# copy in memtest if present
	if [ -f $IMGPATH/usr/lib/anaconda-runtime/boot/memtest* ]; then
           cp $IMGPATH/usr/lib/anaconda-runtime/boot/memtest* $MBD_BOOTTREE/memtest
           echo -e "label memtest86\n  menu label ^Memory test\n  kernel memtest\n  append -\n" >> $MBD_BOOTTREE/isolinux.cfg
	fi
    else
	echo "No isolinux binaries.  Skipping isolinux creation"
    fi

    # symlink the kernel for pxe dir
    ln $TOPDESTPATH/isolinux/vmlinuz $TOPDESTPATH/images/pxeboot/vmlinuz

    cat > $TOPDESTPATH/images/pxeboot/README <<EOF
The files in this directory are useful for booting a machine via PXE.  

The following files are available:
vmlinuz - the kernel used for the installer
initrd.img - an initrd with support for all install methods and
    drivers supported for installation of $PRODUCT
EOF
    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$BASEARCH]
kernel = images/pxeboot/vmlinuz
initrd = images/pxeboot/initrd.img
__EOT__
    if [ -n "$BOOTISO" ]; then echo "boot.iso = images/$BOOTISO" >> $TOPDESTPATH/.treeinfo ; fi    
  fi

  # set up the boot stuff for the xen guest kernel
  if [ -z "$kernelxen" -o "$kernelvers" = "$kernelxen" ] ; then
    cp $KERNELROOT/boot/vmlinuz-$version $TOPDESTPATH/images/pxeboot/$kernelimage
    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-xen]
kernel = images/pxeboot/$kernelimage
initrd = images/pxeboot/$initrd

__EOT__
  fi
}


doPostImages() {
    if [ -n "$BOOTISO" ]; then
        EFIARGS=""
        EFIGRAFT=""
        if [ -f $TOPDESTPATH/images/pxeboot/efiboot.img ]; then
            cp $TOPDESTPATH/images/pxeboot/efiboot.img $TOPDESTPATH/isolinux/efiboot.img
            EFIARGS="-eltorito-alt-boot -e isolinux/efiboot.img -no-emul-boot"
            EFIGRAFT="EFI/boot=$TOPDESTPATH/EFI/boot"
        fi
        BIOSARGS="-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
        echo $PWD:\$ mkisofs -o $TOPDESTPATH/images/$BOOTISO $BIOSARGS $EFIARGS -R -J -V "$PRODUCT" -T -graft-points isolinux=$TOPDESTPATH/isolinux images/install.img=$TOPDESTPATH/images/install.img $EFIGRAFT
        mkisofs -o $TOPDESTPATH/images/$BOOTISO $BIOSARGS $EFIARGS -R -J -V "$PRODUCT" -T -graft-points isolinux=$TOPDESTPATH/isolinux images/install.img=$TOPDESTPATH/images/install.img $EFIGRAFT
        implantisomd5 $TOPDESTPATH/images/$BOOTISO
    fi

}