summaryrefslogtreecommitdiffstats
path: root/scripts/mk-images.ia64
blob: 56fd8dc714dd3164e8a7d36ebece57d64041e5d0 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
#
# mk-images.ia64
#
# 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/>.
#

#makebootdisk required for EFI bootloader dosfs image
makebootdisk() {
    EXTRAKERNELPATH=""
    INITRDFLAGS=""
    MBD_FILENAME=""
    INITRDFILE=""
    MBD_TMPIMAGE=${TMPDIR:-/tmp}/makebootdisk.image.$$
    MBD_BOOTTREE=${TMPDIR:-/tmp}/makebootdisk.tree.$$
    MBD_BOOTTREE_TMP=$MBD_BOOTTREE'_tmp'
    while [ x$(echo $1 | cut -c1-2) = x"--" ]; do
	if [ $1 = "--kernelto" ]; then
	    EXTRAKERNELPATH=$2
	    shift; shift
	    continue
	elif [ $1 = "--initrdflags" ]; then
	    INITRDFLAGS=$2
	    shift; shift
	    continue
	elif [ $1 = "--initrd" ]; then
	    INITRDFILE=$2
	    shift; shift
	    continue
	elif [ $1 = "--imagename" ]; then
	    MBD_FILENAME=$IMAGEPATH/$2
	    shift; shift
	    continue
	fi
	echo "Unknown option passed to makebootdisk"
	exit 1
    done

    if [ -z "$MBD_FILENAME" ]; then
	echo "No imagename passed"
	exit 1
    fi

    if [ -n "$INITRDFILE" ]; then
	MBD_FSIMAGE="$INITRDFILE"
    elif [ -n "$INITRDFLAGS" ]; then
	eval makeinitrd --keep $INITRDFLAGS
    fi

    mkdir -p $MBD_BOOTTREE
    mkdir -p $MBD_BOOTTREE_TMP
    rm -rf $MBD_BOOTTREE_TMP
    mkdir -p $MBD_TMPIMAGE

    # provided by the mk-image.$ARCH file
    prepareBootImage

    left=$(df $MBD_BOOTTREE | tail -n1)
    left=$(echo $left | awk '{print $4'})

    umount $MBD_BOOTTREE

    if [ -n "$EXTRAKERNELPATH" ]; then
	mkdir -p `dirname $EXTRAKERNELPATH`
	cp -f $KERNELROOT/$KERNELDIR/${KERNELNAME}-* $EXTRAKERNELPATH
    fi

    mkdir -p `dirname $MBD_FILENAME`
    rm -rf $MBD_TMPIMAGE $MBD_MNTPOINT $MBD_BOOTTREE
    if [ -z "$INITRDFILE" ]; then
	rm -f $MBD_FSIMAGE
    fi

    echo "Wrote $MBD_FILENAME (${left}k free)"
}

prepareBootImage() {

	prepareBootTree

	# dynamically calculate the size of the dosfs
	BOOTDISKSIZE=$(du -kcs $MBD_BOOTTREE_TMP | tail -n1 | awk '{print $1}')
	BOOTDISKSIZE=$(expr $BOOTDISKSIZE + 100)
	echo "The size of the boot.img dosfs is $BOOTDISKSIZE"
	dd if=/dev/zero bs=1k count=$BOOTDISKSIZE of=$MBD_FILENAME 2>/dev/null
	mkdosfs -C $MBD_FILENAME $BOOTDISKSIZE >/dev/null
	mount -o loop -t vfat $MBD_FILENAME $MBD_BOOTTREE
	cp -R $MBD_BOOTTREE_TMP/* $MBD_BOOTTREE
}

prepareBootTree() {
	mkdir -p $MBD_BOOTTREE_TMP/EFI/boot
	cp $MBD_FSIMAGE $MBD_BOOTTREE_TMP/EFI/boot/initrd.img

	cp -a $BOOTDISKDIR/* $MBD_BOOTTREE_TMP/EFI/boot/
	cp $KERNELROOT/boot/efi/EFI/redhat/vmlinuz-* $MBD_BOOTTREE_TMP/EFI/boot/vmlinuz

	cp $MBD_BOOTTREE_TMP/EFI/boot/elilo.efi $MBD_BOOTTREE_TMP/EFI/boot/bootia64.efi
	cat > $MBD_BOOTTREE_TMP/EFI/boot/elilo.conf << EOF
prompt	
timeout=50
relocatable

image=vmlinuz
        label=linux
        read-only
	initrd=initrd.img
EOF

	# make a copy in the root of the image
	cp $MBD_BOOTTREE_TMP/EFI/boot/* $MBD_BOOTTREE_TMP
}

makeBootImages() {
  if [ "$kerneltag" != "xen" ]; then
    # Because ia64 boxes use EFI there needs to be a boot.img dosfs.
    echo "making boot.img for EFI bootloader"
    makebootdisk --kernelto $TOPDESTPATH/kernels/vmlinuz  \
	--imagename boot.img \
	--initrdflags '--initrdto $TOPDESTPATH/images/ramdisk.img \
		     	    --initrdsize 12288 \
			    --loaderbin loader \
			    --modules "$INITRDMODS sgiioc4" '


    mkdir -p $TOPDESTPATH/images/pxeboot
    makeinitrd --initrdto $TOPDESTPATH/images/pxeboot/initrd.img \
	--initrdsize 12288 \
	--loaderbin loader \
	--modules "$INITRDMODS sgiioc4"
    [ $? = 0 ] || exit 1
    mv $TOPDESTPATH/kernels/vmlinuz $TOPDESTPATH/images/pxeboot/vmlinuz
    rmdir $TOPDESTPATH/kernels

    # make a boot iso
    mkdir -p $TOPDESTPATH/images/isopath
    cp -l $TOPDESTPATH/images/boot.img $TOPDESTPATH/images/isopath
    mkisofs -quiet -o $TOPDESTPATH/images/boot.iso -b boot.img -no-emul-boot -R -J -V "$PRODUCT" -T $TOPDESTPATH/images/isopath
    rm -rf $TOPDESTPATH/images/isopath

    # make a pxe dir with kernel + initrd
    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-$KERNELARCH]
kernel = images/pxeboot/vmlinuz
initrd = images/pxeboot/initrd.img
boot.iso = images/boot.iso
boot.img = images/boot.img

__EOT__

  else # set up the boot stuff for the xen guest kernel
    echo "Building $KERNELARCH guest initrd.img"
    mkdir -p $TOPDESTPATH/images/xen
    makeinitrd --initrdto $TOPDESTPATH/images/xen/initrd.img \
	--initrdsize 12288 \
	--loaderbin loader \
	--modules "$INITRDMODS"
    [ $? = 0 ] || exit 1
    cp $KERNELROOT/boot/efi/EFI/redhat/vmlinuz-*xen* $TOPDESTPATH/images/xen/vmlinuz
    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$KERNELARCH]
kernel = images/xen/vmlinuz
initrd = images/xen/initrd.img

__EOT__
  fi
}