Advertisement
serega_by

Untitled

Nov 11th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.21 KB | None | 0 0
  1. #! /bin/sh
  2. set -e
  3.  
  4. # grub-mkconfig helper script.
  5. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  6. #
  7. # GRUB is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # GRUB is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. prefix=/usr
  21. exec_prefix=${prefix}
  22. bindir=${exec_prefix}/bin
  23. libdir=${exec_prefix}/lib
  24. . ${libdir}/grub/grub-mkconfig_lib
  25.  
  26. export TEXTDOMAIN=grub
  27. export TEXTDOMAINDIR=${prefix}/share/locale
  28.  
  29. CLASS="--class gnu-linux --class gnu --class os --class xen"
  30.  
  31. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  32.   OS=GNU/Linux
  33. else
  34.   OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  35.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
  36. fi
  37.  
  38. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  39. # the initrds that Linux uses don't like that.
  40. case ${GRUB_DEVICE} in
  41.   /dev/loop/*|/dev/loop[0-9])
  42.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  43.     # We can't cope with devices loop-mounted from files here.
  44.     case ${GRUB_DEVICE} in
  45.       /dev/*) ;;
  46.       *) exit 0 ;;
  47.     esac
  48.   ;;
  49. esac
  50.  
  51. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  52.     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  53.     || uses_abstraction "${GRUB_DEVICE}" lvm; then
  54.   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  55. else
  56.   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  57. fi
  58.  
  59. menuentry "Win7" {
  60. insmod part_msdos
  61. insmod ntfs
  62. set root='(hd0,msdos2)'
  63. search --no-floppy --fs-uuid --set то_что_нашли
  64. chainloader +1
  65. }
  66.  
  67. linux_entry ()
  68. {
  69.   os="$1"
  70.   version="$2"
  71.   xen_version="$3"
  72.   recovery="$4"
  73.   args="$5"
  74.   xen_args="$6"
  75.   if ${recovery} ; then
  76.     title="$(gettext_quoted "%s, with Linux %s and XEN %s (recovery mode)")"
  77.  else
  78.    title="$(gettext_quoted "%s, with Linux %s and XEN %s")"
  79.  fi
  80.  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" "${xen_version}"
  81.  save_default_entry | sed -e "s/^/\t/"
  82.  
  83.  if [ -z "${prepare_boot_cache}" ]; then
  84.    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  85.  fi
  86.  printf '%s\n' "${prepare_boot_cache}"
  87.  cat << EOF
  88.     echo    '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
  89.     multiboot   ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
  90.     module  ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
  91. EOF
  92.  if test -n "${initrd}" ; then
  93.    cat << EOF
  94.     echo    '$(gettext_quoted "Loading initial ramdisk ...")'
  95.     module  ${rel_dirname}/${initrd}
  96. EOF
  97.  fi
  98.  cat << EOF
  99. }
  100. EOF
  101. }
  102.  
  103. linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
  104.         basename=$(basename $i)
  105.     version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
  106.        if grub_file_is_not_garbage "$i" && grep -qx "CONFIG_XEN_DOM0=y" /boot/config-${version} 2> /dev/null ; then echo -n "$i " ; fi
  107.      done`
  108. xen_list=`for i in /boot/xen*; do
  109.        if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  110.      done`
  111. prepare_boot_cache=
  112.  
  113. while [ "x${xen_list}" != "x" ] ; do
  114.    list="${linux_list}"
  115.    current_xen=`version_find_latest $xen_list`
  116.    xen_basename=`basename ${current_xen}`
  117.    xen_dirname=`dirname ${current_xen}`
  118.    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
  119.    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
  120.    while [ "x$list" != "x" ] ; do
  121.     linux=`version_find_latest $list`
  122.     echo "Found linux image: $linux" >&2
  123.     basename=`basename $linux`
  124.     dirname=`dirname $linux`
  125.     rel_dirname=`make_system_path_relative_to_its_root $dirname`
  126.     version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  127.     alt_version=`echo $version | sed -e "s,\.old$,,g"`
  128.     linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  129.  
  130.     initrd=
  131.     for i in "initrd.img-${version}" "initrd-${version}.img" \
  132.         "initrd-${version}" "initrd.img-${alt_version}" \
  133.         "initrd-${alt_version}.img" "initrd-${alt_version}"; do
  134.         if test -e "${dirname}/${i}" ; then
  135.         initrd="$i"
  136.         break
  137.         fi
  138.     done
  139.     if test -n "${initrd}" ; then
  140.         echo "Found initrd image: ${dirname}/${initrd}" >&2
  141.     else
  142.    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
  143.         linux_root_device_thisversion=${GRUB_DEVICE}
  144.     fi
  145.  
  146.     linux_entry "${OS}" "${version}" "${xen_version}" false \
  147.         "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  148.     if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
  149.         linux_entry "${OS}" "${version}" "${xen_version}" true \
  150.         "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
  151.     fi
  152.  
  153.     list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  154.    done
  155.    xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
  156. done
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement