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