Advertisement
kachunkachunk

Ubuntu 16.04's Grub2 auto-loading of razer_acpi_fix.img

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