NoPaste

/etc/grub.d/10_linux

von willy4711

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

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. Alternativ kannst du den gesamten Eintrag auch als Datei herunterladen.