source: client/shared/scripts/grubSyntax @ 4be0673

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-instalacionwebconsole3
Last change on this file since 4be0673 was adcd13d, checked in by adv <adv@…>, 8 years ago

#788

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5363 a21b9725-9963-47de-94b9-378ad31fedc9

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