source: client/shared/scripts/grubSyntax @ 5fd45d1

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 5fd45d1 was 3673737, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#890 #802 ogGrubInstall: To get kernel parameters we need the original grub.cfg: it\'s move at the end. grubSyntax: In kernel parameters, replaces UUID for DEVICE.

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