source: client/shared/scripts/grubSyntax @ 6495c7c

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 6495c7c was d61c5e5, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #890 ogGrubInstallMbr detects Windows loader en ESP and saves de ogbootloader into directory 'grub'·

  • Property mode set to 100755
File size: 13.3 KB
Line 
1#!/bin/bash
2set -e
3
4#grubSyntax
5#version 1.1.0
6#autoconfigurador de items de menu para grub/brg
7#basado en scripts del paquete de grub
8#Antonio Doblas Viso
9#Universidad de Málaga
10#@version 1.1.1 - En los parámetros del kernel se sustituye el UUID por el dispositivo.
11#@version 1.1.1 - Detecta cargador de Windows en directorio Part-xx-yy dentro de ESP (#802 #888)
12
13DISK=
14PART=
15
16
17
18if [ $# == 3 ]; then
19        DISK=$1;PART=$2;KERNELPARAM=$3
20fi
21
22if [ $# == 2 ]; then
23        DISK=$1;PART=$2
24fi
25
26if [ $# == 1 ]; then
27        KERNELPARAM=$1
28fi
29
30
31#Versión de scripts compatible con la versión 1.99 de grub-probe
32#Uso del grub-probe 1.99  según arquitectura
33grub_probe=${grub_probe:-$OGBIN/grub-probe1.99_$(arch)}
34
35#librerias del osProber para kernel antiguos: detecta e identifica sistema operativos.
36if grub-install --version | grep 1.99 ; then
37    cp -r /opt/opengnsys/lib/os-probes/* /usr/lib/os-probes/
38else
39    # Librería os-probe para cargador de microsoft en dir part-x-y (uefi)
40    OSPROBE_MS_PART="/opt/opengnsys/lib/os-probes/mounted/efi/31part-x-y"
41    [ -f $OSPROBE_MS_PART ] && cp $OSPROBE_MS_PART /usr/lib/os-probes/mounted/efi
42fi
43
44
45#Autoreconocimiento del ogLive en cache
46#fichero de reconocimeinto de grub
47#fichero de lsb-release en la cache (al final de este scripts se elimina esta entrada para que el browser no lo muestre
48
49if [ $(ls /opt/opengnsys/cache/boot/$oglivedir/ogvmlinuz 2>/dev/null) ]; then
50        sed -i 's|/boot/\${oglivedir}/ogvmlinuz |/vmlinuz |i' /usr/lib/linux-boot-probes/mounted/90fallback
51        sed -i 's|/vmlinuz |/vmlinuz /boot/\${oglivedir}/ogvmlinuz |1' /usr/lib/linux-boot-probes/mounted/90fallback
52        mkdir -p /opt/opengnsys/cache/etc/
53        echo "DISTRIB_ID=Ubuntu" > /opt/opengnsys/cache/etc/lsb-release
54        echo "DISTRIB_RELEASE= " >> /opt/opengnsys/cache/etc/lsb-release
55        echo $oglivedir | awk -F- ' {print "DISTRIB_CODENAME="$2 }' >> /opt/opengnsys/cache/etc/lsb-release
56        echo "DISTRIB_DESCRIPTION=OpenGnsys Live" >> /opt/opengnsys/cache/etc/lsb-release
57fi
58
59#ver linea 195 detección de los os en variable OSPROBED
60
61OG_prepare_grub_to_access_device ()
62{
63  device="$1"
64  loop_file=
65  case ${device} in
66    /dev/loop/*|/dev/loop[0-9])
67      grub_loop_device="${device#/dev/}"
68      loop_file=`losetup "${device}" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
69      case $loop_file in
70        /dev/*) ;;
71        *)
72          loop_device="${device}"
73          device=`"${grub_probe}" --target=device "${loop_file}"` || return 0
74        ;;
75      esac
76    ;;
77  esac
78  if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then
79    grub_warn \
80      "$device is a crypto device, which GRUB cannot read directly.  Some" \
81      "necessary modules may be missing from /boot/grub/grub.cfg.  You may" \
82      "need to list them in GRUB_PRELOAD_MODULES in /etc/default/grub.  See" \
83      "http://bugs.debian.org/542165 for details."
84    return 0
85  fi
86  # Abstraction modules aren't auto-loaded.
87  abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
88  for module in ${abstraction} ; do
89    echo "insmod ${module}"
90  done
91  partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
92  for module in ${partmap} ; do
93    case "${module}" in
94      netbsd | openbsd)
95        echo "insmod part_bsd";;
96      *)
97        echo "insmod part_${module}";;
98    esac
99  done
100  fs="`"${grub_probe}" --device "${device}" --target=fs`"
101  for module in ${fs} ; do
102    echo "insmod ${module}"
103  done
104  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
105  # otherwise set root as per value in device.map.
106  #OG modificacion
107  echo "set root='`"${grub_probe}" --device "${device}" --target=drive`'"
108  #if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
109  #  echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}"
110  #fi
111
112  if [ "x${loop_file}" != x ]; then
113    loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)"
114    if [ "x${loop_mountpoint}" != x ]; then
115      echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}"
116      echo "set root=(${grub_loop_device})"
117    fi
118  fi
119}
120
121
122
123
124
125# grub-mkconfig helper script.
126# Copyright (C) 2006,2007,2008,2009  Free Software Foundation, Inc.
127#
128# GRUB is free software: you can redistribute it and/or modify
129# it under the terms of the GNU General Public License as published by
130# the Free Software Foundation, either version 3 of the License, or
131# (at your option) any later version.
132#
133# GRUB is distributed in the hope that it will be useful,
134# but WITHOUT ANY WARRANTY; without even the implied warranty of
135# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
136# GNU General Public License for more details.
137#
138# You should have received a copy of the GNU General Public License
139# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
140
141
142prefix=/usr
143exec_prefix=${prefix}
144libdir=${exec_prefix}/lib
145
146. ${libdir}/grub/grub-mkconfig_lib
147
148found_other_os=
149
150make_timeout () {
151  if [ "x${found_other_os}" = "x" ] ; then
152    if [ "x${1}" != "x" ] ; then
153      if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
154        verbose=
155      else
156        verbose=" --verbose"
157      fi
158
159      if [ "x${1}" = "x0" ] ; then
160        cat <<EOF
161if [ "x\${timeout}" != "x-1" ]; then
162  if keystatus; then
163    if keystatus --shift; then
164      set timeout=-1
165    else
166      set timeout=0
167    fi
168  else
169    if sleep$verbose --interruptible 3 ; then
170      set timeout=0
171    fi
172  fi
173fi
174EOF
175      else
176        cat << EOF
177if [ "x\${timeout}" != "x-1" ]; then
178  if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
179    set timeout=0
180  fi
181fi
182EOF
183      fi
184    fi
185  fi
186}
187
188adjust_timeout () {
189  if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
190    cat <<EOF
191if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
192EOF
193    make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}"
194    echo else
195    make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
196    echo fi
197  else
198    make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
199  fi
200}
201
202if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
203  adjust_timeout
204  exit 0
205fi
206
207if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
208  # missing os-prober and/or linux-boot-prober
209  adjust_timeout
210  exit 0
211fi
212
213case "$1" in
214
215
216esac
217
218
219
220# ADV  OSPROBED
221if [ -n "${DISK}" ]; then
222        #Si $DISK esta definido buscar en el disco y la particion parametro 1 y 2
223        OSSEARCH=$(ogDiskToDev $DISK $PART)
224        OSPROBED="`os-prober | grep $OSSEARCH | tr ' ' '^' | paste -s -d ' '`"
225else
226        #si no esta definido
227        OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
228fi
229
230#DISK=${DISK:-"1"}
231#echo $OSSEARCH
232#echo "$OSPROBED"
233
234
235if [ -z "${OSPROBED}" ] ; then
236  # empty os-prober output, nothing doing
237  adjust_timeout
238  exit 0
239fi
240
241osx_entry() {
242        found_other_os=1
243        cat << EOF
244menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os {
245EOF
246        save_default_entry | sed -e "s/^/\t/"
247        prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
248        cat << EOF
249        load_video
250        set do_resume=0
251        if [ /var/vm/sleepimage -nt10 / ]; then
252           if xnu_resume /var/vm/sleepimage; then
253             set do_resume=1
254           fi
255        fi
256        if [ \$do_resume = 0 ]; then
257           xnu_uuid ${OSXUUID} uuid
258           if [ -f /Extra/DSDT.aml ]; then
259              acpi -e /Extra/DSDT.aml
260           fi
261           $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
262           if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
263              xnu_mkext /System/Library/Extensions.mkext
264           else
265              xnu_kextdir /System/Library/Extensions
266           fi
267           if [ -f /Extra/Extensions.mkext ]; then
268              xnu_mkext /Extra/Extensions.mkext
269           fi
270           if [ -d /Extra/Extensions ]; then
271              xnu_kextdir /Extra/Extensions
272           fi
273           if [ -f /Extra/devprop.bin ]; then
274              xnu_devprop_load /Extra/devprop.bin
275           fi
276           if [ -f /Extra/splash.jpg ]; then
277              insmod jpeg
278              xnu_splash /Extra/splash.jpg
279           fi
280           if [ -f /Extra/splash.png ]; then
281              insmod png
282              xnu_splash /Extra/splash.png
283           fi
284           if [ -f /Extra/splash.tga ]; then
285              insmod tga
286              xnu_splash /Extra/splash.tga
287           fi
288        fi
289}
290EOF
291}
292
293wubi=
294
295for OS in ${OSPROBED} ; do
296  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
297  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
298  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
299  BOOT="`echo ${OS} | cut -d ':' -f 4`"
300
301  if [ -z "${LONGNAME}" ] ; then
302    LONGNAME="${LABEL}"
303  fi
304
305  echo "Found ${LONGNAME} on ${DEVICE}" >&2
306
307  case ${BOOT} in
308    chain)
309
310      case ${LONGNAME} in
311        Windows*)
312          if [ -z "$wubi" ]; then
313            if [ -x /usr/share/lupin-support/grub-mkimage ] && \
314               /usr/share/lupin-support/grub-mkimage --test; then
315              wubi=yes
316            else
317              wubi=no
318            fi
319          fi
320          if [ "$wubi" = yes ]; then
321            echo "Skipping ${LONGNAME} on Wubi system" >&2
322            continue
323          fi
324          ;;
325      esac
326      #adv
327      LABELCLASS=$(echo "${LONGNAME}" | awk '{print tolower($1$2);}')
328
329      found_other_os=1
330      cat << EOF
331menuentry "${LONGNAME} (on ${DEVICE})" --class $LABELCLASS --class windows {
332EOF
333      save_default_entry | sed -e "s/^/\t/"
334#ADV      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
335      OG_prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
336
337      case ${LONGNAME} in
338        Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
339        ;;
340        *)
341#ADV      cat << EOF
342#ADV    drivemap -s (hd0) \${root}
343#ADV EOF
344        ;;
345      esac
346
347      cat <<EOF
348        chainloader +1
349}
350EOF
351    ;;
352    efi)
353
354        found_other_os=1
355        EFIPATH=${DEVICE#*@}
356        DEVICE=${DEVICE%@*}
357        onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
358      cat << EOF
359menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' {
360EOF
361      save_default_entry | sed -e "s/^/\t/"
362#ADV      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
363      OG_prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
364
365      cat <<EOF
366        chainloader ${EFIPATH}
367}
368EOF
369    ;;
370    linux)
371        KERNELPARAM=""
372        #linuxprobed detecta todos los  kernels de una partición.
373      LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
374#esta opcion de linuxprobe solo interpreta el primer kernel detectado de la partición
375#Si queremos que autoincluya todos los kernels hay que comentar esta filtrado de LINUXPROBED
376      LINUXPROBED=$(echo $LINUXPROBED | awk '{ print $1}')     
377      prepare_boot_cache=
378       #        echo "ADV listado de los kerenel encontrados linux-boot-prober ${DEVICE} $LINUXPROBED"
379      for LINUX in ${LINUXPROBED} ; do
380        LINUX=$LINUXPROBED
381        LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
382        LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
383        LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
384        LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
385        LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
386        LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
387        # En los parámetros cambiamos el UUID por el valor de LROOT
388        UUID=$(blkid -s UUID -o value $LROOT)
389        LPARAMS="$(echo $LPARAMS | sed "s|UUID=$UUID|$LROOT|g")"
390        if [ -z "${LLABEL}" ] ; then
391          LLABEL="${LONGNAME}"
392        fi
393
394        if [ "${LROOT}" != "${LBOOT}" ]; then
395          LKERNEL="${LKERNEL#/boot}"
396          LINITRD="${LINITRD#/boot}"
397        fi
398
399        found_other_os=1
400        LABELCLASS=$(echo "${LLABEL}" | awk '{print tolower($1);}')
401        cat << EOF
402menuentry "${LLABEL} (on ${DEVICE})" --class $LABELCLASS --class linux --class os {
403EOF
404        save_default_entry | sed -e "s/^/\t/"
405        if [ -z "${prepare_boot_cache}" ]; then
406#ADV        prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
407            prepare_boot_cache="$(OG_prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
408        fi
409        printf '%s\n' "${prepare_boot_cache}"
410        if [ "$LABELCLASS" == "opengnsys" ]; then
411                KERNELPARAM=$(cat /proc/cmdline)
412        fi
413        cat <<  EOF
414        linux ${LKERNEL} ${LPARAMS} ${KERNELPARAM}
415EOF
416        if [ -n "${LINITRD}" ] ; then
417          cat << EOF
418        initrd ${LINITRD}
419EOF
420        fi
421        cat << EOF
422}
423EOF
424     done
425    ;;
426    macosx)
427      OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
428      osx_entry xnu_kernel 32
429      osx_entry xnu_kernel64 64
430    ;;
431    hurd)
432      found_other_os=1
433      cat << EOF
434menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os {
435EOF
436      save_default_entry | sed -e "s/^/\t/"
437      prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
438      grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
439      mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
440      grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
441      case "${grub_fs}" in
442        *fs)    hurd_fs="${grub_fs}" ;;
443        *)      hurd_fs="${grub_fs}fs" ;;
444      esac
445      cat << EOF
446        multiboot /boot/gnumach.gz root=device:${mach_device}
447        module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
448                        --multiboot-command-line='\${kernel-command-line}' \\
449                        --host-priv-port='\${host-port}' \\
450                        --device-master-port='\${device-port}' \\
451                        --exec-server-task='\${exec-task}' -T typed '\${root}' \\
452                        '\$(task-create)' '\$(task-resume)'
453        module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
454}
455EOF
456    ;;
457    *)
458      echo "  ${LONGNAME} is not yet supported by grub-mkconfig." >&2
459    ;;
460  esac
461done
462
463adjust_timeout
464
465rm /opt/opengnsys/cache/etc/lsb-release &>/dev/null
Note: See TracBrowser for help on using the repository browser.