Fix pegasos kernelz rename;fix default_append_line to not include initrd= as too...
[catalyst.git] / targets / support / bootloader-setup.sh
1 #!/bin/bash
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/bootloader-setup.sh,v 1.19 2005/11/21 17:14:32 rocket Exp $
5 . ${clst_sharedir}/targets/support/functions.sh
6 . ${clst_sharedir}/targets/support/filesystem-functions.sh
7
8 # $1 is the destination root
9
10 extract_cdtar $1
11 extract_kernels $1/boot
12 check_dev_manager
13 check_bootargs
14 check_filesystem_type
15
16 default_append_line="root=/dev/ram0 init=/linuxrc ${cmdline_opts} ${custom_kopts} cdroot"
17
18 case ${clst_mainarch} in
19         alpha)
20                 acfg=$1/etc/aboot.conf
21                 bctr=0
22                 for x in ${clst_boot_kernel}
23                 do
24                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
25                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
26                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
27                         ((bctr=${bctr}+1))
28                 done
29                 ;;
30
31         arm)
32                 ;;
33         hppa)
34                 icfg=$1/boot/palo.conf
35                 kmsg=$1/boot/kernels.msg
36                 hmsg=$1/boot/help.msg
37                 echo "--commandline=0/${first} initrd=${first}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts}" >> ${icfg}
38                 echo "--bootloader=boot/iplboot" >> ${icfg}
39                 echo "--ramdisk=boot/${first}.igz" >> ${icfg}
40                 ;;
41         ppc)
42                 # PPC requirements: 
43                 # -----------------
44                 # The specs indicate the kernels to be build. We need to put
45                 # those kernels and the corresponding initrd.img.gz(s) in the
46                 # /boot directory. This directory contains a message boot.msg 
47                 # containing some info to be displayed on boot, a configuration
48                 # (yaboot.conf) specifying the boot options (kernel/initrd 
49                 # combinations). The boot directory also contains a file called
50                 # yaboot, which normally gets copied from the live environment.
51                 # For now we supply a prebuilt file, prebuilt configuration 
52                 # and prebuilt boot message. This can be enhanced later on
53                 # but the following suffices for now:
54                 
55                 # this sets up the config file for yaboot
56                 icfg=$1/boot/yaboot.conf
57                 kmsg=$1/boot/boot.msg
58                 echo "default ${first}" > ${icfg}
59                 echo "timeout 300" >> ${icfg}
60                 echo "device=cd:" >> ${icfg}
61                 echo "root=/dev/ram" >> ${icfg}
62                 echo "fgcolor=white" >> ${icfg}
63                 echo "bgcolor=black" >> ${icfg}
64                 echo "message=/boot/boot.msg" >> ${icfg}
65                 for x in ${clst_boot_kernel}
66                 do
67                         eval custom_kopts=\$${x}_kernelopts
68                         echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
69                         echo >> ${icfg}
70                         echo "image=/boot/${x}" >> ${icfg}
71                         
72                         if [ -e "/boot/${x}.igz" ]
73                         then
74                             echo "initrd=/boot/${x}.igz" >> ${icfg}
75                         fi
76                         
77                         echo "label=${x}" >> ${icfg}
78                         echo "read-write" >> ${icfg}
79                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
80                         then
81                             echo "append=\"${default_append_line} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${icfg}
82                         else
83                             echo "append=\"${default_append_line} splash=silent\"" >> ${icfg}
84                         fi
85                 done
86                 ;;
87         sparc*)
88                 scfg=$1/boot/silo.conf
89                 echo "default=\"help\"" > ${scfg}
90                 echo "message=\"/boot/boot.msg\"" >> ${scfg}
91
92                 for x in ${clst_boot_kernel}
93                 do
94                         echo >> ${icfg}
95                         echo "image=\"/boot/${x}\"" >> ${scfg}
96                         echo -e "\tlabel=\"${x}\"" >> ${scfg}
97                         echo -e "\tappend=\"initrd=/boot/${x}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts} cdroot\"" >> ${scfg}
98
99                 done
100
101                 echo "image=\"cat /boot/silo.conf\"" >> ${scfg}
102                 echo -e "label=\"config\"" >> ${scfg}
103                 echo "image=\"cat /boot/video.msg\"" >> ${scfg}
104                 echo -e "label=\"video\"" >> ${scfg}
105                 echo "image=\"cat /boot/help.msg\"" >> ${scfg}
106                 echo -e "label=\"help\"" >> ${scfg}
107                 ;;
108         ia64)
109                 iacfg=$1/boot/elilo.conf
110                 echo 'prompt' > ${iacfg}
111                 echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
112                 echo 'chooser=simple' >> ${iacfg}
113                 echo 'timeout=50' >> ${iacfg}
114                 echo >> ${iacfg}
115                 for x in ${clst_boot_kernel}
116                 do
117                         echo "image=/efi/boot/${x}" >> ${iacfg}
118                         echo "  label=${x}" >> ${iacfg}
119                         echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
120                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
121                         echo >> ${iacfg}
122                         echo "image=/efi/boot/${x}" >> ${iacfg}
123                         echo "  label=${x}-serial">> ${iacfg}
124                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS0,9600"' >> ${iacfg}
125                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
126                         echo >> ${iacfg}
127                 done
128                 cp ${iacfg} $1/boot/efi/boot
129                 mv $1/boot/${x}{,.igz} $1/boot/efi/boot
130                 ;;
131         x86|amd64)
132                 if [ -e $1/isolinux/isolinux.bin ]
133                 then
134                         mv $1/boot/* $1/isolinux
135                         rmdir $1/boot
136                         # the rest of this function sets up the config file for isolinux
137                         icfg=$1/isolinux/isolinux.cfg
138                         kmsg=$1/isolinux/kernels.msg
139                         echo "default ${first}" > ${icfg}
140                         echo "timeout 150" >> ${icfg}
141                         echo "prompt 1" >> ${icfg}
142                         echo "display boot.msg" >> ${icfg}
143                         echo "F1 kernels.msg" >> ${icfg}
144                         echo "F2 F2.msg" >> ${icfg}
145                         echo "F3 F3.msg" >> ${icfg}
146                         echo "F4 F4.msg" >> ${icfg}
147                         echo "F5 F5.msg" >> ${icfg}
148                         echo "F6 F6.msg" >> ${icfg}
149                         echo "F7 F7.msg" >> ${icfg}
150
151                         echo "Available kernels:" > ${kmsg}
152                         for i in 2 3 4 5 6 7
153                         do
154                                 cp ${clst_sharedir}/livecd/files/x86-F$i.msg \
155                                         $1/isolinux/F$i.msg
156                         done
157
158                         for x in ${clst_boot_kernel}
159                         do
160
161                                 eval custom_kopts=\$${x}_kernelopts
162                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
163                                 echo >> ${icfg}
164                                 echo "label ${x}" >> ${icfg}
165                                 echo "  kernel ${x}" >> ${icfg}
166                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
167                                 then
168                                         echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
169                                 else
170                                         echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
171                                 fi
172                         
173                                 echo >> ${icfg}
174                                 echo "   ${x}" >> ${kmsg}
175                                 echo "label ${x}-nofb" >> ${icfg}
176                                 echo "  kernel ${x}" >> ${icfg}
177                                 echo "  append ${default_append_line} initrd=${x}.igz" >> ${icfg}
178                                 echo >> ${icfg}
179                                 echo "   ${x}-nofb" >> ${kmsg}
180                         done
181
182                         if [ -f $1/isolinux/memtest86 ]
183                         then
184                                 echo >> $icfg
185                                 echo "   memtest86" >> $kmsg
186                                 echo "label memtest86" >> $icfg
187                                 echo "  kernel memtest86" >> $icfg
188                         fi
189                 fi
190
191                 if [ -e $1/boot/grub/stage2_eltorito ]
192                 then
193                         icfg=$1/boot/grub/grub.conf
194                         echo "default 1" > ${icfg}
195                         echo "timeout 150" >> ${icfg}
196
197                         # Setup help message
198                         echo >> ${icfg}
199                         echo "title help" >> ${icfg}
200                         cp ${clst_sharedir}/livecd/files/README.txt \
201                                 $1/boot/help.msg
202                         echo "cat /boot/help.msg" >> ${icfg}
203
204                         for x in ${clst_boot_kernel}
205                         do
206                                 eval custom_kopts=\$${x}_kernelopts
207                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
208                                 echo >> ${icfg}
209                                 echo "title ${x}" >> ${icfg}
210                                 
211                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
212                                 then
213                                         echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
214                                 else
215                                         echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent" >> ${icfg}
216                                 fi
217
218                                 if [ -e $1/boot/${x}.igz ]
219                                 then
220                                         echo "initrd /boot/${x}.igz" >> ${icfg}
221                                 fi
222                                 
223                                 echo >> ${icfg}
224                                 echo "title ${x} [ No FrameBuffer ]" >> ${icfg}
225                                 echo "kernel ${x} /boot/${x} ${default_append_line}" >> ${icfg}
226                                 if [ -e $1/boot/${x}.igz ]
227                                 then
228                                         echo "initrd /boot/${x}.igz" >> ${icfg}
229                                 fi
230                         done
231
232                         if [ -f $1/boot/memtest86 ]
233                         then
234                                 echo >> ${icfg}
235                                 echo "title memtest86" >> ${icfg}
236                                 echo "kernel /boot/memtest86" >> ${icfg}
237                         fi
238                 fi
239                 ;;
240         mips)
241                 # Mips is an interesting arch -- where most archs will
242                 # use ${1} as the root of the LiveCD, an SGI LiveCD lacks
243                 # such a root.  Instead, we will use ${1} as a scratch
244                 # directory to build the components we need for the
245                 # CD image, and then pass these components to the
246                 # `sgibootcd` tool which outputs a final CD image
247                 scratch="${1}"
248                 mkdir ${scratch}/kernels
249                 mkdir ${scratch}/kernels/misc
250                 mkdir ${scratch}/arcload
251                 echo "" > ${scratch}/arc.cf
252
253                 # Move kernel binaries to ${scratch}/kernels, and
254                 # move everything else to ${scratch}/kernels/misc
255                 for x in ${clst_boot_kernel}; do
256                         mv ${1}/boot/${x} ${scratch}/kernels
257                         mv ${1}/boot/${x}.igz ${scratch}/kernels/misc
258                 done
259                 rmdir ${1}/boot
260
261                 # Source the bashified arcload config
262                 source ${clst_sharedir}/targets/support/mips-arcload_conf.sh
263
264                 # Generate top portions of the config
265                 echo -e "${topofconfig}${serial}${dbg}${cmt1}" >> ${scratch}/arc.cf
266
267                 # Next, figure out what kernels were specified in the
268                 # spec file, and generate the appropriate arcload conf
269                 # blocks specific to each system
270                 ip22="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip22" | tr "\n" " ")"
271                 ip27="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip27" | tr "\n" " ")"
272                 ip28="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip28" | tr "\n" " ")"
273                 ip30="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip30" | tr "\n" " ")"
274                 ip32="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip32" | tr "\n" " ")"
275
276                 if [ -n "${ip22}" ]; then
277                         echo -e "${ip22base}" >> ${scratch}/arc.cf
278                         for x in ${ip22}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
279                         echo -e "${ip22vid}${ip22x}" >> ${scratch}/arc.cf
280                 fi
281
282                 [ -n "${ip27}" ] && echo -e "${ip27base}" >> ${scratch}/arc.cf
283                 [ -n "${ip28}" ] && echo -e "${ip28base}" >> ${scratch}/arc.cf
284                 [ -n "${ip30}" ] && echo -e "${ip30base}" >> ${scratch}/arc.cf
285
286                 if [ -n "${ip32}" ]; then
287                         echo -e "${ip32base}" >> ${scratch}/arc.cf
288                         for x in ${ip32}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
289                         echo -e "${ip32vid}${ip32x}" >> ${scratch}/arc.cf
290                 fi
291
292                 # Finish off the config
293                 echo -e "${cmt2}" >> ${scratch}/arc.cf
294
295                 # Move the bootloader binaries & config to their destination
296                 mv ${1}/sashARCS ${1}/sash64 ${1}/arc.cf ${scratch}/arcload
297                 ;;
298 esac
299 exit $?