NoPaste

10_linux

von fischig

SNIPPET_TEXT:
  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="/usr"
  22. datarootdir="/usr/share"
  23. ubuntu_recovery="0"
  24. quiet_boot="0"
  25. quick_boot="0"
  26. gfxpayload_dynamic="0"
  27. vt_handoff="0"
  28.  
  29. . "$pkgdatadir/grub-mkconfig_lib"
  30.  
  31. export TEXTDOMAIN=grub
  32. export TEXTDOMAINDIR="${datarootdir}/locale"
  33.  
  34. CLASS="--class gnu-linux --class gnu --class os"
  35. SUPPORTED_INITS="sysvinit:/lib/sysvinit/init systemd:/lib/systemd/systemd upstart:/sbin/upstart"
  36.  
  37. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  38.   OS=GNU/Linux
  39. else
  40.   case ${GRUB_DISTRIBUTOR} in
  41.     Ubuntu|Kubuntu)
  42.       OS="${GRUB_DISTRIBUTOR}"
  43.       ;;
  44.     *)
  45.       OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  46.       ;;
  47.   esac
  48.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
  49. fi
  50.  
  51. OS=""
  52.  
  53. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  54. # the initrds that Linux uses don't like that.
  55. case ${GRUB_DEVICE} in
  56.   /dev/loop/*|/dev/loop[0-9])
  57.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  58.    # We can't cope with devices loop-mounted from files here.
  59.    case ${GRUB_DEVICE} in
  60.      /dev/*) ;;
  61.      *) exit 0 ;;
  62.    esac
  63.  ;;
  64. esac
  65.  
  66. # Default to disabling partition uuid support to maintian compatibility with
  67. # older kernels.
  68. GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
  69.  
  70. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
  71. # and mounting btrfs requires user space scanning, so force UUID in this case.
  72. if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
  73.    || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  74.         && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
  75.    || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  76.         && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
  77.    || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
  78.  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  79. elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
  80.    || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
  81.  LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
  82. else
  83.  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  84. fi
  85.  
  86. case x"$GRUB_FS" in
  87.    xbtrfs)
  88.         rootsubvol="`make_system_path_relative_to_its_root /`"
  89.         rootsubvol="${rootsubvol#/}"
  90.         if [ "x${rootsubvol}" != x ]; then
  91.             GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  92.         fi;;
  93.     xzfs)
  94.         rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  95.         bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  96.         LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
  97.         ;;
  98. esac
  99.  
  100. title_correction_code=
  101.  
  102. if [ -x /lib/recovery-mode/recovery-menu ]; then
  103.     GRUB_CMDLINE_LINUX_RECOVERY=recovery
  104. else
  105.     GRUB_CMDLINE_LINUX_RECOVERY=single
  106. fi
  107. if [ "$ubuntu_recovery" = 1 ]; then
  108.     GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset"
  109. fi
  110.  
  111. if [ "$vt_handoff" = 1 ]; then
  112.   for word in $GRUB_CMDLINE_LINUX_DEFAULT; do
  113.     if [ "$word" = splash ]; then
  114.       GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT \$vt_handoff"
  115.     fi
  116.   done
  117. fi
  118.  
  119. linux_entry ()
  120. {
  121.   os="$1"
  122.   version="$2"
  123.   type="$3"
  124.   args="$4"
  125.  
  126.   if [ -z "$boot_device_id" ]; then
  127.       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  128.   fi
  129.   if [ x$type != xsimple ] ; then
  130.       case $type in
  131.           recovery)
  132.               title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;;
  133.           init-*)
  134.               title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "${type#init-}")" ;;
  135.           *)
  136.               title="$(gettext_printf "%s"  Linux-"${version}")" ;;
  137.       esac
  138.       if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  139.           replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  140.           quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  141.           title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  142.           grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
  143.       fi
  144.       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  145.   else
  146.       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  147.   fi      
  148.   if [ "$quick_boot" = 1 ]; then
  149.       echo "    recordfail" | sed "s/^/$submenu_indentation/"
  150.   fi
  151.   if [ x$type != xrecovery ] ; then
  152.       save_default_entry | grub_add_tab
  153.   fi
  154.  
  155.   # Use ELILO's generic "efifb" when it's known to be available.
  156.  # FIXME: We need an interface to select vesafb in case efifb can't be used.
  157.  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  158.       echo "    load_video" | sed "s/^/$submenu_indentation/"
  159.   else
  160.       if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  161.           echo "        load_video" | sed "s/^/$submenu_indentation/"
  162.       fi
  163.   fi
  164.   if ([ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]) && \
  165.      ([ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]); then
  166.       echo "    gfxmode \$linux_gfx_mode" | sed "s/^/$submenu_indentation/"
  167.   fi
  168.  
  169.   echo "        insmod gzio" | sed "s/^/$submenu_indentation/"
  170.   echo "        if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
  171.  
  172.   if [ x$dirname = x/ ]; then
  173.     if [ -z "${prepare_root_cache}" ]; then
  174.       prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  175.     fi
  176.     printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  177.   else
  178.     if [ -z "${prepare_boot_cache}" ]; then
  179.       prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  180.     fi
  181.     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  182.   fi
  183.   if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
  184.     message="$(gettext_printf "Loading Linux %s ..." ${version})"
  185.     sed "s/^/$submenu_indentation/" << EOF
  186.         echo    '$(echo "$message" | grub_quote)'
  187. EOF
  188.   fi
  189.   if test -d /sys/firmware/efi && test -e "${linux}.efi.signed"; then
  190.     sed "s/^/$submenu_indentation/" << EOF
  191.         linux   ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
  192. EOF
  193.   else
  194.     sed "s/^/$submenu_indentation/" << EOF
  195.         linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  196. EOF
  197.   fi
  198.   if test -n "${initrd}" ; then
  199.     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  200.    if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
  201.       message="$(gettext_printf "Loading initial ramdisk ...")"
  202.       sed "s/^/$submenu_indentation/" << EOF
  203.         echo    '$(echo "$message" | grub_quote)'
  204. EOF
  205.     fi
  206.     initrd_path=
  207.     for i in ${initrd}; do
  208.       initrd_path="${initrd_path} ${rel_dirname}/${i}"
  209.     done
  210.     sed "s/^/$submenu_indentation/" << EOF
  211.         initrd  $(echo $initrd_path)
  212. EOF
  213.   fi
  214.   sed "s/^/$submenu_indentation/" << EOF
  215. }
  216. EOF
  217. }
  218.  
  219. machine=`uname -m`
  220. case "x$machine" in
  221.     xi?86 | xx86_64)
  222.         list=
  223.         for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  224.             if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  225.         done ;;
  226.     *)
  227.         list=
  228.         for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  229.                   if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  230.         done ;;
  231. esac
  232.  
  233. case "$machine" in
  234.     i?86) GENKERNEL_ARCH="x86" ;;
  235.     mips|mips64) GENKERNEL_ARCH="mips" ;;
  236.     mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  237.     arm*) GENKERNEL_ARCH="arm" ;;
  238.     *) GENKERNEL_ARCH="$machine" ;;
  239. esac
  240.  
  241. prepare_boot_cache=
  242. prepare_root_cache=
  243. boot_device_id=
  244. title_correction_code=
  245.  
  246. cat << 'EOF'
  247. function gfxmode {
  248.         set gfxpayload="${1}"
  249. EOF
  250. if [ "$vt_handoff" = 1 ]; then
  251.   cat << 'EOF'
  252.         if [ "${1}" = "keep" ]; then
  253.                 set vt_handoff=vt.handoff=7
  254.         else
  255.                 set vt_handoff=
  256.         fi
  257. EOF
  258. fi
  259. cat << EOF
  260. }
  261. EOF
  262.  
  263. # Use ELILO's generic "efifb" when it's known to be available.
  264. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  265. if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then
  266.   echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
  267. else
  268.   cat << EOF
  269. if [ "\${recordfail}" != 1 ]; then
  270.   if [ -e \${prefix}/gfxblacklist.txt ]; then
  271.     if hwmatch \${prefix}/gfxblacklist.txt 3; then
  272.       if [ \${match} = 0 ]; then
  273.         set linux_gfx_mode=keep
  274.       else
  275.         set linux_gfx_mode=text
  276.       fi
  277.     else
  278.       set linux_gfx_mode=text
  279.     fi
  280.   else
  281.     set linux_gfx_mode=keep
  282.   fi
  283. else
  284.   set linux_gfx_mode=text
  285. fi
  286. EOF
  287. fi
  288. cat << EOF
  289. export linux_gfx_mode
  290. EOF
  291.  
  292. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  293. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  294. submenu_indentation=""
  295.  
  296. is_top_level=true
  297. while [ "x$list" != "x" ] ; do
  298.   linux=`version_find_latest $list`
  299.   case $linux in
  300.     *.efi.signed)
  301.       # We handle these in linux_entry.
  302.      list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  303.       continue
  304.       ;;
  305.   esac
  306.   gettext_printf "Found linux image: %s\n" "$linux" >&2
  307.   basename=`basename $linux`
  308.   dirname=`dirname $linux`
  309.   rel_dirname=`make_system_path_relative_to_its_root $dirname`
  310.   version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  311.   alt_version=`echo $version | sed -e "s,\.old$,,g"`
  312.   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  313.  
  314.   initrd_early=
  315.   for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
  316.            ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
  317.     if test -e "${dirname}/${i}" ; then
  318.       initrd_early="${initrd_early} ${i}"
  319.     fi
  320.   done
  321.  
  322.   initrd_real=
  323.   for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  324.            "initrd-${version}" "initramfs-${version}.img" \
  325.            "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  326.            "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  327.            "initramfs-genkernel-${version}" \
  328.            "initramfs-genkernel-${alt_version}" \
  329.            "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  330.            "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  331.     if test -e "${dirname}/${i}" ; then
  332.       initrd_real="${i}"
  333.       break
  334.     fi
  335.   done
  336.  
  337.   initrd=
  338.   if test -n "${initrd_early}" || test -n "${initrd_real}"; then
  339.     initrd="${initrd_early} ${initrd_real}"
  340.  
  341.     initrd_display=
  342.     for i in ${initrd}; do
  343.       initrd_display="${initrd_display} ${dirname}/${i}"
  344.     done
  345.     gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
  346.   fi
  347.  
  348.   config=
  349.   for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  350.     if test -e "${i}" ; then
  351.       config="${i}"
  352.       break
  353.     fi
  354.   done
  355.  
  356.   initramfs=
  357.   if test -n "${config}" ; then
  358.       initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  359.  fi
  360.  
  361.  if test -z "${initramfs}" && test -z "${initrd_real}" ; then
  362.    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
  363.    # no initrd or builtin initramfs, it can't work here.
  364.    if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
  365.         || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
  366.  
  367.         linux_root_device_thisversion=${GRUB_DEVICE}
  368.    else
  369.         linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
  370.    fi
  371.  fi
  372.  
  373.  # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
  374.  # mentioned in the documentation that has to be set to 'y' instead of 'true' to
  375.  # enable it. This caused a lot of confusion to users that set the option to 'y',
  376.  # 'yes' or 'true'. This was fixed but all of these values must be supported now.
  377.  if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then
  378.    GRUB_DISABLE_SUBMENU="true"
  379.  fi
  380.  
  381.  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
  382.    linux_entry "${OS}" "${version}" simple \
  383.    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  384.  
  385.    submenu_indentation="$grub_tab"
  386.    
  387.    if [ -z "$boot_device_id" ]; then
  388.         boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  389.    fi
  390.    # TRANSLATORS: %s is replaced with an OS name
  391.    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  392.    is_top_level=false
  393.  fi
  394.  
  395.  linux_entry "${OS}" "${version}" advanced \
  396.              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  397.  for supported_init in ${SUPPORTED_INITS}; do
  398.    init_path="${supported_init#*:}"
  399.    if [ -x "${init_path}" ] && [ "$(readlink -f /sbin/init)" != "$(readlink -f "${init_path}")" ]; then
  400.       linux_entry "${OS}" "${version}" "init-${supported_init%%:*}" \
  401.                   "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} init=${init_path}"
  402.     fi
  403.   done
  404.   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  405.     linux_entry "${OS}" "${version}" recovery \
  406.                 "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
  407.   fi
  408.  
  409.   list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  410. done
  411.  
  412. # If at least one kernel was found, then we need to
  413. # add a closing '}' for the submenu command.
  414. if [ x"$is_top_level" != xtrue ]; then
  415.   echo '}'
  416. fi
  417.  
  418. echo "$title_correction_code"
  419.  

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN