Whitespace.
[catalyst.git] / targets / support / bootloader-setup.sh
1 #!/bin/bash
2 . ${clst_sharedir}/targets/support/functions.sh
3 . ${clst_sharedir}/targets/support/filesystem-functions.sh
4
5 # $1 is the destination root
6
7 extract_cdtar $1
8 extract_kernels $1/boot
9 check_bootargs
10 check_filesystem_type
11
12 default_append_line="root=/dev/ram0 init=/linuxrc ${cmdline_opts} ${custom_kopts} cdroot"
13 [ -n "${clst_splash_theme}" ] && default_append_line="${default_append_line} splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet"
14
15 case ${clst_hostarch} in
16         alpha)
17                 # NO SOFTLEVEL SUPPORT YET
18                 acfg=$1/etc/aboot.conf
19                 bctr=0
20                 # Pass 1 is for non-serial
21                 for x in ${clst_boot_kernel}
22                 do
23                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
24                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
25                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
26                         ((bctr=${bctr}+1))
27                 done
28                 # Pass 2 is for serial
29                 cmdline_opts="${cmdline_opts} console=ttyS0"
30                 for x in ${clst_boot_kernel}
31                 do
32                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
33                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
34                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
35                         ((bctr=${bctr}+1))
36                 done
37         ;;
38         arm)
39                 # NO SOFTLEVEL SUPPORT YET
40         ;;
41         hppa)
42                 # NO SOFTLEVEL SUPPORT YET
43                 icfg=$1/boot/palo.conf
44                 kmsg=$1/boot/kernels.msg
45                 hmsg=$1/boot/help.msg
46                 # Make sure we strip the extension to the kernel to allow palo to choose
47                 boot_kernel_common_name=${first/%32/}
48                 boot_kernel_common_name=${boot_kernel_common_name/%64/}
49                 echo "--commandline=0/${boot_kernel_common_name} initrd=${first}.igz root=/dev/ram0 init=/linuxrc cdroot ${cmdline_opts}" >> ${icfg}
50                 echo "--bootloader=boot/iplboot" >> ${icfg}
51                 echo "--ramdisk=boot/${first}.igz" >> ${icfg}
52                 for x in ${clst_boot_kernel}
53                 do
54                         echo "--recoverykernel=boot/${x}" >> ${icfg}
55                 done
56         ;;
57         ppc*|powerpc*)
58                 # NO SOFTLEVEL SUPPORT YET
59                 icfg=$1/boot/yaboot.conf
60                 kmsg=$1/boot/boot.msg
61
62                 echo "device=cd:" >> ${icfg}
63                 echo "root=/dev/ram" >> ${icfg}
64                 echo "fgcolor=white" >> ${icfg}
65                 echo "bgcolor=black" >> ${icfg}
66                 echo "message=/boot/boot.msg" >> ${icfg}
67
68                 # Here is where I fix up the boot.msg file.
69                 sed -e 's/ARCH/PowerPC/' \
70                         -e 's/HARDWARE/Apple and IBM hardware/' \
71                         -i $kmsg
72
73                 # Setup the IBM yaboot.conf
74                 etc_icfg=$1/etc/yaboot.conf
75                 mkdir -p $1/etc
76                 IBM_YABOOT="FALSE"
77                 echo "root=/dev/ram" >> ${etc_icfg}
78                 echo "fgcolor=white" >> ${etc_icfg}
79                 echo "bgcolor=black" >> ${etc_icfg}
80                 echo "message=/boot/boot.msg" >> ${etc_icfg}
81
82                 for x in ${clst_boot_kernel}
83                 do
84                         eval "clst_kernel_console=\$clst_boot_kernel_${x}_console"
85                         eval "clst_kernel_machine_type=\$clst_boot_kernel_${x}_machine_type"
86                         eval custom_kopts=\$${x}_kernelopts
87
88                         echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
89                         if [ "${clst_kernel_machine_type}" == "ibm" ]
90                         then
91                                 IBM_YABOOT="true"
92                                 if [ -n "${clst_kernel_console}" ]
93                                 then
94                                         echo >> ${etc_icfg}
95                                         echo "image=/boot/${x}" >> ${etc_icfg}
96
97                                         if [ -e "$1/boot/${x}.igz" ]
98                                         then
99                                                 echo "initrd=/boot/${x}.igz" >> ${etc_icfg}
100                                         fi
101
102                                         echo "label=${x}" >> ${etc_icfg}
103                                         echo "read-write" >> ${icfg}
104                                         echo "append=\"${default_append_line}\"" >> ${etc_icfg}
105
106                                         for y in ${clst_kernel_console}
107                                         do
108                                                 echo ${y}
109                                                 echo >> ${etc_icfg}
110                                                 echo "image=/boot/${x}" >> ${etc_icfg}
111
112                                                 if [ -e "$1/boot/${x}.igz" ]
113                                                 then
114                                                         echo "initrd=/boot/${x}.igz" >> ${etc_icfg}
115                                                 fi
116
117                                                 echo "label=${x}-${y} " >> ${etc_icfg}
118                                                 echo "read-write" >> ${icfg}
119                                                 echo "append=\"${default_append_line} console=${y}\"" >> ${etc_icfg}
120                                         done
121                                 else
122                                         echo >> ${etc_icfg}
123                                         echo "image=/boot/${x}" >> ${etc_icfg}
124
125                                         if [ -e "$1/boot/${x}.igz" ]
126                                         then
127                                                 echo "initrd=/boot/${x}.igz" >> ${etc_icfg}
128                                         fi
129
130                                         echo "label=${x}" >> ${etc_icfg}
131                                         echo "read-write" >> ${etc_icfg}
132                                         echo "append=\"${default_append_line}\"" >> ${etc_icfg}
133                                 fi
134                         else
135                                 # Here we wipe out the /ppc directory, if it exists.
136                                 rm -rf $1/ppc
137                                 if [ -n "${clst_kernel_console}" ]
138                                 then
139                                         echo >> ${icfg}
140                                         echo "image=/boot/${x}" >> ${icfg}
141
142                                         if [ -e "$1/boot/${x}.igz" ]
143                                         then
144                                                 echo "initrd=/boot/${x}.igz" >> ${icfg}
145                                         fi
146
147                                         echo "label=${x}" >> ${icfg}
148                                         echo "read-write" >> ${icfg}
149                                         echo "append=\"${default_append_line}\"" >> ${icfg}
150
151                                         for y in ${clst_kernel_console}
152                                         do
153                                                 echo >> ${icfg}
154                                                 echo "image=/boot/${x}" >> ${icfg}
155
156                                                 if [ -e "$1/boot/${x}.igz" ]
157                                                 then
158                                                         echo "initrd=/boot/${x}.igz" >> ${icfg}
159                                                 fi
160
161                                                 echo "label=${x}-${y} " >> ${icfg}
162                                                 echo "read-write" >> ${icfg}
163                                                 echo "append=\"${default_append_line} console=${y}\"" >> ${icfg}
164                                         done
165                                 else
166                                         echo >> ${icfg}
167                                         echo "image=/boot/${x}" >> ${icfg}
168
169                                         if [ -e "$1/boot/${x}.igz" ]
170                                         then
171                                                 echo "initrd=/boot/${x}.igz" >> ${icfg}
172                                         fi
173
174                                         echo "label=${x}" >> ${icfg}
175                                         echo "read-write" >> ${icfg}
176                                         echo "append=\"${default_append_line}\"" >> ${icfg}
177                                 fi
178                         fi
179                 done
180
181                 if [ "${IBM_YABOOT}" == "FALSE" ]
182                 then
183                         rm ${etc_kmsg}
184                         rmdir $1/etc
185                         if [ -d $1/ppc ]
186                         then
187                                 rm -r $1/ppc
188                         fi
189                 fi
190
191         ;;
192         sparc*)
193                 # NO SOFTLEVEL SUPPORT YET
194                 scfg=$1/boot/silo.conf
195                 echo "default=\"help\"" > ${scfg}
196                 echo "message=\"/boot/boot.msg\"" >> ${scfg}
197
198                 for x in ${clst_boot_kernel}
199                 do
200                         echo >> ${icfg}
201                         echo "image=\"/boot/${x}\"" >> ${scfg}
202                         echo -e "\tlabel=\"${x}\"" >> ${scfg}
203                         echo -e "\tappend=\"initrd=/boot/${x}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts} cdroot\"" >> ${scfg}
204
205                 done
206
207                 echo "image=\"cat /boot/silo.conf\"" >> ${scfg}
208                 echo -e "label=\"config\"" >> ${scfg}
209                 echo "image=\"cat /boot/video.msg\"" >> ${scfg}
210                 echo -e "label=\"video\"" >> ${scfg}
211                 echo "image=\"cat /boot/help.msg\"" >> ${scfg}
212                 echo -e "label=\"help\"" >> ${scfg}
213                 echo "image=\"cat /boot/parameters.msg\"" >> ${scfg}
214                 echo -e "label=\"parameters\"" >> ${scfg}
215         ;;
216         ia64)
217                 # NO SOFTLEVEL SUPPORT YET
218                 iacfg=$1/boot/elilo.conf
219                 echo 'prompt' > ${iacfg}
220                 echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
221                 echo 'chooser=simple' >> ${iacfg}
222                 echo 'timeout=50' >> ${iacfg}
223                 echo 'relocatable' >> ${iacfg}
224                 echo >> ${iacfg}
225                 for x in ${clst_boot_kernel}
226                 do
227                         echo "image=/efi/boot/${x}" >> ${iacfg}
228                         echo "  label=${x}" >> ${iacfg}
229                         echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
230                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
231                         echo >> ${iacfg}
232                         echo "image=/efi/boot/${x}" >> ${iacfg}
233                         echo "  label=${x}-serial">> ${iacfg}
234                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS0,9600"' >> ${iacfg}
235                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
236                         echo >> ${iacfg}
237                         echo "image=/efi/boot/${x}" >> ${iacfg}
238                         echo "  label=${x}-ilo">> ${iacfg}
239                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS3,9600"' >> ${iacfg}
240                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
241                         echo >> ${iacfg}
242                         echo "image=/efi/boot/${x}" >> ${iacfg}
243                         echo "  label=${x}-sgi">> ${iacfg}
244                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttySG0,115200"' >> ${iacfg}
245                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
246                         echo >> ${iacfg}
247                         mv $1/boot/${x}{,.igz} $1/boot/efi/boot
248                 done
249                 cp ${iacfg} $1/boot/efi/boot
250         ;;
251         x86|amd64)
252                 if [ -e $1/isolinux/isolinux.bin ]
253                 then
254                         cp -f $1/boot/* $1/isolinux
255                         # the rest of this function sets up the config file for isolinux
256                         icfg=$1/isolinux/isolinux.cfg
257                         kmsg=$1/isolinux/kernels.msg
258                         echo "default ${first}" > ${icfg}
259                         echo "timeout 150" >> ${icfg}
260                         echo "ontimeout localhost" >> ${icfg}
261                         echo "prompt 1" >> ${icfg}
262                         echo "display boot.msg" >> ${icfg}
263                         echo "F1 kernels.msg" >> ${icfg}
264                         echo "F2 F2.msg" >> ${icfg}
265                         echo "F3 F3.msg" >> ${icfg}
266                         echo "F4 F4.msg" >> ${icfg}
267                         echo "F5 F5.msg" >> ${icfg}
268                         echo "F6 F6.msg" >> ${icfg}
269                         echo "F7 F7.msg" >> ${icfg}
270
271                         echo "Available kernels:" > ${kmsg}
272                         for i in 2 3 4 5 6 7
273                         do
274                                 cp ${clst_sharedir}/livecd/files/x86-F$i.msg \
275                                         $1/isolinux/F$i.msg
276                         done
277
278                         for x in ${clst_boot_kernel}
279                         do
280                                 eval custom_kopts=\$${x}_kernelopts
281                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
282                                 echo >> ${icfg}
283
284                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
285
286                                 if [ -n "${clst_kernel_softlevel}" ]
287                                 then
288                                         for y in ${clst_kernel_softlevel}
289                                         do
290                                                 echo "label ${x}-${y}" >> ${icfg}
291                                                 echo "  kernel ${x}" >> ${icfg}
292                                                 echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791" >> ${icfg}
293
294                                                 echo >> ${icfg}
295                                                 echo "   ${x}" >> ${kmsg}
296                                                 echo "label ${x}-${y}-nofb" >> ${icfg}
297                                                 echo "  kernel ${x}" >> ${icfg}
298                                                 echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz" >> ${icfg}
299                                                 echo >> ${icfg}
300                                                 echo "   ${x}-nofb" >> ${kmsg}
301                                         done
302                                 else
303                                         echo "label ${x}" >> ${icfg}
304                                         echo "  kernel ${x}" >> ${icfg}
305                                         echo "  append ${default_append_line} initrd=${x}.igz vga=791" >> ${icfg}
306                                         echo >> ${icfg}
307                                         echo "   ${x}" >> ${kmsg}
308                                         echo "label ${x}-nofb" >> ${icfg}
309                                         echo "  kernel ${x}" >> ${icfg}
310                                         echo "  append ${default_append_line} initrd=${x}.igz" >> ${icfg}
311                                         echo >> ${icfg}
312                                         echo "   ${x}-nofb" >> ${kmsg}
313                                 fi
314                         done
315
316                         if [ -f $1/isolinux/memtest86 ]
317                         then
318                                 echo >> $icfg
319                                 echo "   memtest86" >> $kmsg
320                                 echo "label memtest86" >> $icfg
321                                 echo "  kernel memtest86" >> $icfg
322                         fi
323                         echo >> $icfg
324                         echo "label localhost" >> $icfg
325                         echo "  localboot -1" >> $icfg
326                         echo "  MENU HIDE" >> $icfg
327                 fi
328
329                 if [ -e $1/boot/efi/elilo.efi ]
330                 then
331                         [ -e $1/isolinux/elilo.efi ] && rm -f $1/isolinux/elilo.efi
332                         iacfg=$1/boot/elilo.conf
333                         echo 'prompt' > ${iacfg}
334                         echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
335                         echo 'chooser=simple' >> ${iacfg}
336                         echo 'timeout=50' >> ${iacfg}
337                         echo >> ${iacfg}
338                         for x in ${clst_boot_kernel}
339                         do
340                                 echo "image=/efi/boot/${x}" >> ${iacfg}
341                                 echo "  label=${x}" >> ${iacfg}
342                                 echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
343                                 echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
344                                 echo >> ${iacfg}
345                                 echo "image=/efi/boot/${x}" >> ${iacfg}
346                                 echo >> ${iacfg}
347                                 cp -f $1/boot/${x}{,.igz} $1/boot/efi/boot > /dev/null
348                                 cp -f $1/isolinux/${x}{,.igz} $1/boot/efi/boot > /dev/null
349                         done
350                         cp ${iacfg} $1/boot/efi/boot
351                 fi
352
353                 if [ -e $1/boot/grub/stage2_eltorito ]
354                 then
355                         icfg=$1/boot/grub/menu.lst
356                         echo "default 0" > ${icfg}
357                         echo "timeout 15" >> ${icfg}
358                         echo "pager on" >> ${icfg}
359
360                         # Copy our splash if we're a Gentoo release
361                         case ${clst_livecd_type} in
362                                 gentoo-*)
363                                         [ -e ${clst_chroot_path}/boot/grub/splash.xpm.gz ] && \
364                                                 cp -f ${clst_chroot_path}/boot/grub/splash.xpm.gz \
365                                                 ${1}/boot/grub
366                                 ;;
367                         esac
368
369                         if [ -e ${1}/boot/grub/splash.xpm.gz ]; then
370                                 echo "splashimage=/boot/grub/splash.xpm.gz" >> ${icfg}
371                         fi
372
373                         for x in ${clst_boot_kernel}
374                         do
375                                 eval custom_kopts=\$${x}_kernelopts
376                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
377                                 echo >> ${icfg}
378
379                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
380
381                                 if [ -n "${clst_kernel_softlevel}" ]
382                                 then
383                                         for y in ${clst_kernel_softlevel}
384                                         do
385                                                 echo "title ${x}-${y}" >> ${icfg}
386                                                 echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791" >> ${icfg}
387                                                 if [ -e $1/boot/${x}.igz ]
388                                                 then
389                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
390                                                 fi
391                                                 echo >> ${icfg}
392                                                 echo "title ${x}-${y} [ No FrameBuffer ]" >> ${icfg}
393                                                 echo "kernel /boot/${x} softlevel=${y} ${default_append_line}" >> ${icfg}
394                                                 if [ -e $1/boot/${x}.igz ]
395                                                 then
396                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
397                                                 fi
398                                                 echo >> ${icfg}
399                                         done
400                                 else
401                                         echo "title ${x}" >> ${icfg}
402                                         echo "kernel /boot/${x} ${default_append_line} vga=791" >> ${icfg}
403                                         if [ -e $1/boot/${x}.igz ]
404                                         then
405                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
406                                         fi
407                                         echo >> ${icfg}
408                                         echo "title ${x} [ No FrameBuffer ]" >> ${icfg}
409                                         echo "kernel /boot/${x} ${default_append_line}" >> ${icfg}
410                                         if [ -e $1/boot/${x}.igz ]
411                                         then
412                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
413                                         fi
414                                 fi
415
416                         done
417
418                         # Setup help message
419                         echo >> ${icfg}
420                         echo "title help" >> ${icfg}
421                         cp ${clst_sharedir}/livecd/files/README.txt \
422                                 $1/boot/help.msg
423                         echo "cat /boot/help.msg" >> ${icfg}
424
425                         if [ -f $1/boot/memtest86 ]
426                         then
427                                 echo >> ${icfg}
428                                 echo "title memtest86" >> ${icfg}
429                                 echo "kernel /boot/memtest86" >> ${icfg}
430                         fi
431                 fi
432         ;;
433         mips)
434                 # NO SOFTLEVEL SUPPORT YET
435
436                 # Mips is an interesting arch -- where most archs will
437                 # use ${1} as the root of the LiveCD, an SGI LiveCD lacks
438                 # such a root.  Instead, we will use ${1} as a scratch
439                 # directory to build the components we need for the
440                 # CD image, and then pass these components to the
441                 # `sgibootcd` tool which outputs a final CD image
442                 scratch="${1}"
443                 [ ! -d "${scratch}/kernels" ] && mkdir ${scratch}/kernels
444                 [ ! -d "${scratch}/kernels/misc" ] && mkdir ${scratch}/kernels/misc
445                 [ ! -d "${scratch}/arcload" ] && mkdir ${scratch}/arcload
446                 echo "" > ${scratch}/arc.cf
447
448                 # Move kernel binaries to ${scratch}/kernels, and
449                 # move everything else to ${scratch}/kernels/misc
450                 for x in ${clst_boot_kernel}; do
451                         [ -e "${1}/boot/${x}" ] && mv ${1}/boot/${x} ${scratch}/kernels
452                         [ -e "${1}/boot/${x}.igz" ] && mv ${1}/boot/${x}.igz ${scratch}/kernels/misc
453                 done
454                 [ -d "${1}/boot" ] && rmdir ${1}/boot
455
456                 # Source the arcload source file to generated required sections of arc.cf
457                 source ${clst_sharedir}/targets/support/mips-arcload_conf.sh
458
459                 # Generate top portions of the config
460                 echo -e "${topofconfig}${serial}${dbg}${cmt1}" >> ${scratch}/arc.cf
461
462                 # Next, figure out what kernels were specified in the
463                 # spec file, and generate the appropriate arcload conf
464                 # blocks specific to each system
465                 ip22="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip22" | tr "\n" " ")"
466                 ip27="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip27" | tr "\n" " ")"
467                 ip28="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip28" | tr "\n" " ")"
468                 ip30="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip30" | tr "\n" " ")"
469                 ip32="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip32" | tr "\n" " ")"
470
471                 if [ -n "${ip22}" ]; then
472                         echo -e "${ip22base}" >> ${scratch}/arc.cf
473                         for x in ${ip22}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
474                         echo -e "${ip22vid}${ip22x}" >> ${scratch}/arc.cf
475                 fi
476
477                 [ -n "${ip27}" ] && echo -e "${ip27base}" >> ${scratch}/arc.cf
478                 [ -n "${ip28}" ] && echo -e "${ip28base}" >> ${scratch}/arc.cf
479                 [ -n "${ip30}" ] && echo -e "${ip30base}" >> ${scratch}/arc.cf
480
481                 if [ -n "${ip32}" ]; then
482                         echo -e "${ip32base}" >> ${scratch}/arc.cf
483                         for x in ${ip32}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
484                         echo -e "${ip32vid}${ip32x}" >> ${scratch}/arc.cf
485                 fi
486
487                 # Finish off the config
488                 echo -e "${cmt2}" >> ${scratch}/arc.cf
489
490                 # Move the bootloader binaries & config to their destination
491                 [ -e "${1}/sashARCS" ] && mv ${1}/sashARCS ${scratch}/arcload
492                 [ -e "${1}/sash64" ] && mv ${1}/sash64 ${scratch}/arcload
493                 [ -e "${1}/arc.cf" ] && mv ${1}/arc.cf ${scratch}/arcload
494                 ;;
495 esac
496 exit $?