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