[9c535e0] | 1 | #! /bin/sh |
---|
| 2 | set -e |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | if [ $# == 3 ]; then |
---|
| 7 | DISK=$1;PART=$2;KERNELPARAM=$3 |
---|
| 8 | fi |
---|
| 9 | |
---|
| 10 | if [ $# == 2 ]; then |
---|
| 11 | DISK=$1;PART=$2 |
---|
| 12 | fi |
---|
| 13 | |
---|
| 14 | if [ $# == 1 ]; then |
---|
| 15 | KERNELPARAM=$1 |
---|
| 16 | fi |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | OG_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 |
---|
| 84 | DISK=${DISK:-"1"} |
---|
| 85 | OSSEARCH=$(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 | |
---|
| 105 | prefix=/usr |
---|
| 106 | exec_prefix=${prefix} |
---|
| 107 | libdir=${exec_prefix}/lib |
---|
| 108 | |
---|
| 109 | . ${libdir}/grub/grub-mkconfig_lib |
---|
| 110 | |
---|
| 111 | found_other_os= |
---|
| 112 | |
---|
| 113 | make_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 |
---|
| 124 | if [ "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 |
---|
| 136 | fi |
---|
| 137 | EOF |
---|
| 138 | else |
---|
| 139 | cat << EOF |
---|
| 140 | if [ "x\${timeout}" != "x-1" ]; then |
---|
| 141 | if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then |
---|
| 142 | set timeout=0 |
---|
| 143 | fi |
---|
| 144 | fi |
---|
| 145 | EOF |
---|
| 146 | fi |
---|
| 147 | fi |
---|
| 148 | fi |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | adjust_timeout () { |
---|
| 152 | if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then |
---|
| 153 | cat <<EOF |
---|
| 154 | if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then |
---|
| 155 | EOF |
---|
| 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 | |
---|
| 165 | if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then |
---|
| 166 | adjust_timeout |
---|
| 167 | exit 0 |
---|
| 168 | fi |
---|
| 169 | |
---|
| 170 | if [ -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 |
---|
| 174 | fi |
---|
| 175 | |
---|
| 176 | case "$1" in |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | esac |
---|
| 180 | |
---|
| 181 | OSPROBED="`os-prober | grep $OSSEARCH | tr ' ' '^' | paste -s -d ' '`" |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | if [ -z "${OSPROBED}" ] ; then |
---|
| 185 | # empty os-prober output, nothing doing |
---|
| 186 | adjust_timeout |
---|
| 187 | exit 0 |
---|
| 188 | fi |
---|
| 189 | |
---|
| 190 | osx_entry() { |
---|
| 191 | found_other_os=1 |
---|
| 192 | cat << EOF |
---|
| 193 | menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os { |
---|
| 194 | EOF |
---|
| 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 | } |
---|
| 239 | EOF |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | wubi= |
---|
| 243 | |
---|
| 244 | for 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 |
---|
| 278 | menuentry "${LONGNAME} (on ${DEVICE})" --class windows --class os { |
---|
| 279 | EOF |
---|
| 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 | } |
---|
| 297 | EOF |
---|
| 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 |
---|
| 322 | menuentry "${LLABEL} (on ${DEVICE})" --class gnu-linux --class gnu --class os { |
---|
| 323 | EOF |
---|
| 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} |
---|
| 332 | EOF |
---|
| 333 | if [ -n "${LINITRD}" ] ; then |
---|
| 334 | cat << EOF |
---|
| 335 | initrd ${LINITRD} |
---|
| 336 | EOF |
---|
| 337 | fi |
---|
| 338 | cat << EOF |
---|
| 339 | } |
---|
| 340 | EOF |
---|
| 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 |
---|
| 351 | menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os { |
---|
| 352 | EOF |
---|
| 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 | } |
---|
| 372 | EOF |
---|
| 373 | ;; |
---|
| 374 | *) |
---|
| 375 | echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2 |
---|
| 376 | ;; |
---|
| 377 | esac |
---|
| 378 | done |
---|
| 379 | |
---|
| 380 | adjust_timeout |
---|