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