source: client/shared/scripts/grubSyntax @ b169708

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 b169708 was 9c535e0, checked in by adv <adv@…>, 12 years ago

#588 #484 Instalar grub sobre GNU/linux de 32 y 64 bits. Configurar fichero grub opcional

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

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