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