Guest User

Untitled

a guest
Jun 3rd, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 44.87 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="${prefix}/share"
  23. grub_lang=`echo $LANG | cut -d . -f 1`
  24.  
  25. export TEXTDOMAIN=grub
  26. export TEXTDOMAINDIR="${datarootdir}/locale"
  27.  
  28. . "/usr/share/grub/grub-mkconfig_lib"
  29.  
  30. # Do this as early as possible, since other commands might depend on it.
  31. # (e.g. the `loadfont' command might need lvm or raid modules)
  32. for i in ${GRUB_PRELOAD_MODULES} ; do
  33.   echo "insmod $i"
  34. done
  35.  
  36. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  37. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  38. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  39. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
  40.  
  41. if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
  42. if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
  43. if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
  44.  
  45. cat << EOF
  46. if [ -s \$prefix/grubenv ]; then
  47.   load_env
  48. fi
  49. EOF
  50. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  51.     cat <<EOF
  52. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  53.    set default="${GRUB_DEFAULT_BUTTON}"
  54. elif [ "\${next_entry}" ] ; then
  55.    set default="\${next_entry}"
  56.    set next_entry=
  57.    save_env next_entry
  58.    set boot_once=true
  59. else
  60.    set default="${GRUB_DEFAULT}"
  61. fi
  62. EOF
  63. else
  64.     cat <<EOF
  65. if [ "\${next_entry}" ] ; then
  66.    set default="\${next_entry}"
  67.    set next_entry=
  68.    save_env next_entry
  69.    set boot_once=true
  70. else
  71.    set default="${GRUB_DEFAULT}"
  72. fi
  73. EOF
  74. fi
  75. cat <<EOF
  76.  
  77. if [ x"\${feature_menuentry_id}" = xy ]; then
  78.   menuentry_id_option="--id"
  79. else
  80.   menuentry_id_option=""
  81. fi
  82.  
  83. export menuentry_id_option
  84.  
  85. if [ "\${prev_saved_entry}" ]; then
  86.   set saved_entry="\${prev_saved_entry}"
  87.   save_env saved_entry
  88.   set prev_saved_entry=
  89.   save_env prev_saved_entry
  90.   set boot_once=true
  91. fi
  92.  
  93. function savedefault {
  94.   if [ -z "\${boot_once}" ]; then
  95.     saved_entry="\${chosen}"
  96.     save_env saved_entry
  97.   fi
  98. }
  99.  
  100. function load_video {
  101. EOF
  102. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  103.     cat <<EOF
  104.   insmod ${GRUB_VIDEO_BACKEND}
  105. EOF
  106. else
  107. # If all_video.mod isn't available load all modules available
  108. # with versions prior to introduction of all_video.mod
  109. cat <<EOF
  110.   if [ x\$feature_all_video_module = xy ]; then
  111.     insmod all_video
  112.   else
  113.     insmod efi_gop
  114.     insmod efi_uga
  115.     insmod ieee1275_fb
  116.     insmod vbe
  117.     insmod vga
  118.     insmod video_bochs
  119.     insmod video_cirrus
  120.   fi
  121. EOF
  122. fi
  123. cat <<EOF
  124. }
  125.  
  126. EOF
  127.  
  128. serial=0;
  129. gfxterm=0;
  130. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  131.     if [ xserial = "x$x" ]; then
  132.     serial=1;
  133.     fi
  134.     if [ xgfxterm = "x$x" ]; then
  135.     gfxterm=1;
  136.     fi
  137. done
  138.  
  139. if [ "x$serial" = x1 ]; then
  140.     if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  141.     grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
  142.     GRUB_SERIAL_COMMAND=serial
  143.     fi
  144.     echo "${GRUB_SERIAL_COMMAND}"
  145. fi
  146.  
  147. if [ "x$gfxterm" = x1 ]; then
  148.     if [ -n "$GRUB_FONT" ] ; then
  149.        # Make the font accessible
  150.        prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
  151.     cat << EOF
  152. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
  153. EOF
  154.     else
  155.     for dir in "${pkgdatadir}" "`echo '/boot/grub2' | sed "s,//*,/,g"`" /usr/share/grub ; do
  156.         for basename in unicode unifont ascii; do
  157.         path="${dir}/${basename}.pf2"
  158.         if is_path_readable_by_grub "${path}" > /dev/null ; then
  159.             font_path="${path}"
  160.         else
  161.             continue
  162.         fi
  163.         break 2
  164.         done
  165.     done
  166.     if [ -n "${font_path}" ] ; then
  167.     cat << EOF
  168. if [ x\$feature_default_font_path = xy ] ; then
  169.    font=unicode
  170. else
  171. EOF
  172.                 # Make the font accessible
  173.         prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
  174.     cat << EOF
  175.     font="`make_system_path_relative_to_its_root "${font_path}"`"
  176. fi
  177.  
  178. if loadfont \$font ; then
  179. EOF
  180.         else
  181.     cat << EOF
  182. if loadfont unicode ; then
  183. EOF
  184.         fi
  185.     fi
  186.  
  187.     cat << EOF
  188.   set gfxmode=${GRUB_GFXMODE}
  189.   load_video
  190.   insmod gfxterm
  191. EOF
  192.  
  193. # Gettext variables and module
  194. if [ "x${LANG}" != "xC" ] ; then
  195.   cat << EOF
  196.   set locale_dir=\$prefix/locale
  197.   set lang=${grub_lang}
  198.   insmod gettext
  199. EOF
  200. fi
  201.  
  202. cat <<EOF
  203. fi
  204. EOF
  205. fi
  206.  
  207. case x${GRUB_TERMINAL_INPUT} in
  208.   x)
  209.     # Just use the native terminal
  210.   ;;
  211.   x*)
  212.     cat << EOF
  213. terminal_input ${GRUB_TERMINAL_INPUT}
  214. EOF
  215.   ;;
  216. esac
  217.  
  218. case x${GRUB_TERMINAL_OUTPUT} in
  219.   x)
  220.     # Just use the native terminal
  221.   ;;
  222.   x*)
  223.     cat << EOF
  224. terminal_output ${GRUB_TERMINAL_OUTPUT}
  225. EOF
  226.   ;;
  227. esac
  228.  
  229. if [ "x$gfxterm" = x1 ]; then
  230.     if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  231.     && is_path_readable_by_grub "$GRUB_THEME"; then
  232.     gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
  233.  
  234.     prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  235.     cat << EOF
  236. insmod gfxmenu
  237. EOF
  238.     themedir="`dirname "$GRUB_THEME"`"
  239.     for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  240.         if [ -f "$x" ]; then
  241.         cat << EOF
  242. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  243. EOF
  244.         fi
  245.     done
  246.     if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  247.         cat << EOF
  248. insmod jpeg
  249. EOF
  250.     fi
  251.     if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  252.         cat << EOF
  253. insmod png
  254. EOF
  255.     fi
  256.     if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  257.         cat << EOF
  258. insmod tga
  259. EOF
  260.     fi
  261.        
  262.     cat << EOF
  263. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  264. export theme
  265. EOF
  266.     elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  267.         && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  268.     gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
  269.     case "$GRUB_BACKGROUND" in
  270.         *.png)         reader=png ;;
  271.         *.tga)         reader=tga ;;
  272.         *.jpg|*.jpeg)  reader=jpeg ;;
  273.         *)             gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
  274.     esac
  275.     prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  276.     cat << EOF
  277. insmod $reader
  278. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  279. EOF
  280.     fi
  281. fi
  282.  
  283. make_timeout ()
  284. {
  285.     if [ "x${1}" != "x" ] ; then
  286.     if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  287.         verbose=
  288.     else
  289.         verbose=" --verbose"
  290.     fi
  291.     cat << EOF
  292. if sleep$verbose --interruptible ${1} ; then
  293.   set timeout=${2}
  294. fi
  295. EOF
  296.     else
  297.     cat << EOF
  298. set timeout=${2}
  299. EOF
  300.     fi
  301. }
  302.  
  303. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  304.     cat <<EOF
  305. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  306. EOF
  307. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}"
  308. echo else
  309. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
  310. echo fi
  311. else
  312. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
  313. fi
  314.  
  315. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  316.     cat <<EOF
  317. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  318. EOF
  319. fi
  320.  
  321. # Play an initial tune
  322. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  323.   echo "play ${GRUB_INIT_TUNE}"
  324. fi
  325.  
  326. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  327.   echo "badram ${GRUB_BADRAM}"
  328. fi
  329. #! /bin/sh
  330. set -e
  331.  
  332. # grub-mkconfig helper script.
  333. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  334. #
  335. # GRUB is free software: you can redistribute it and/or modify
  336. # it under the terms of the GNU General Public License as published by
  337. # the Free Software Foundation, either version 3 of the License, or
  338. # (at your option) any later version.
  339. #
  340. # GRUB is distributed in the hope that it will be useful,
  341. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  342. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  343. # GNU General Public License for more details.
  344. #
  345. # You should have received a copy of the GNU General Public License
  346. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  347.  
  348. prefix="/usr"
  349. exec_prefix="/usr"
  350. datarootdir="${prefix}/share"
  351.  
  352. . "/usr/share/grub/grub-mkconfig_lib"
  353.  
  354. export TEXTDOMAIN=grub
  355. export TEXTDOMAINDIR="${datarootdir}/locale"
  356.  
  357. CLASS="--class gnu-linux --class gnu --class os"
  358.  
  359. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  360.   OS="$(sed 's, release .*$,,g' /etc/system-release)"
  361. else
  362.   OS="${GRUB_DISTRIBUTOR}"
  363.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
  364. fi
  365.  
  366. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  367. # the initrds that Linux uses don't like that.
  368. case ${GRUB_DEVICE} in
  369.   /dev/loop/*|/dev/loop[0-9])
  370.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  371.   ;;
  372. esac
  373.  
  374. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  375.     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  376.     || uses_abstraction "${GRUB_DEVICE}" lvm; then
  377.   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  378. else
  379.   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  380. fi
  381.  
  382. GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
  383.  
  384. if [ x"$GRUBFS" = x ]; then
  385.     GRUBFS="$(stat -f --printf=%T / || true)"
  386. fi
  387.  
  388. case x"$GRUBFS" in
  389.     xbtrfs)
  390.     rootsubvol="`make_system_path_relative_to_its_root /`"
  391.     rootsubvol="${rootsubvol#/}"
  392.     if [ "x${rootsubvol}" != x ]; then
  393.         GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  394.     fi;;
  395.     xzfs)
  396.     rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  397.     bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  398.     LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  399.     ;;
  400. esac
  401.  
  402. title_correction_code=
  403.  
  404. linux_entry ()
  405. {
  406.   os="$1"
  407.   version="$2"
  408.   type="$3"
  409.   args="$4"
  410.  
  411.   if [ -z "$boot_device_id" ]; then
  412.       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  413.   fi
  414.   if [ x$type != xsimple ] ; then
  415.       case $type in
  416.       recovery)
  417.           title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
  418.       *)
  419.           title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
  420.      esac
  421.      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  422.       replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  423.       quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  424.       title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  425.       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")"
  426.      fi
  427.      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  428.  else
  429.      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  430.  fi      
  431.  if [ x$type != xrecovery ] ; then
  432.      save_default_entry | grub_add_tab
  433.  fi
  434.  
  435.  # Use ELILO's generic "efifb" when it's known to be available.
  436.  # FIXME: We need an interface to select vesafb in case efifb can't be used.
  437.  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  438.       echo "    load_video" | sed "s/^/$submenu_indentation/"
  439.      if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  440.       && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  441.       echo "    set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  442.      fi
  443.  else
  444.      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  445.       echo "    load_video" | sed "s/^/$submenu_indentation/"
  446.      fi
  447.       echo "    set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  448.  fi
  449.  
  450.   echo "    insmod gzio" | sed "s/^/$submenu_indentation/"
  451.  
  452.  if [ x$dirname = x/ ]; then
  453.    if [ -z "${prepare_root_cache}" ]; then
  454.      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  455.    fi
  456.    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  457.  else
  458.    if [ -z "${prepare_boot_cache}" ]; then
  459.      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  460.    fi
  461.    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  462.  fi
  463.  if [ -d /sys/firmware/efi ]; then
  464.    sed "s/^/$submenu_indentation/" << EOF
  465.     linuxefi ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  466. EOF
  467.  else
  468.    sed "s/^/$submenu_indentation/" << EOF
  469.     linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  470. EOF
  471.  fi
  472.  if test -n "${initrd}" ; then
  473.    if [ -d /sys/firmware/efi ]; then
  474.      sed "s/^/$submenu_indentation/" << EOF
  475.     initrdefi ${rel_dirname}/${initrd}
  476. EOF
  477.    else
  478.      sed "s/^/$submenu_indentation/" << EOF
  479.     initrd  ${rel_dirname}/${initrd}
  480. EOF
  481.    fi
  482.  fi
  483.  sed "s/^/$submenu_indentation/" << EOF
  484. }
  485. EOF
  486. }
  487.  
  488. machine=`uname -m`
  489. case "x$machine" in
  490.    xi?86 | xx86_64)
  491.     list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  492.                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  493.              done` ;;
  494.    *)
  495.     list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  496.                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  497.          done` ;;
  498. esac
  499.  
  500. case "$machine" in
  501.    i?86) GENKERNEL_ARCH="x86" ;;
  502.    mips|mips64) GENKERNEL_ARCH="mips" ;;
  503.    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  504.    arm*) GENKERNEL_ARCH="arm" ;;
  505.    *) GENKERNEL_ARCH="$machine" ;;
  506. esac
  507.  
  508. prepare_boot_cache=
  509. prepare_root_cache=
  510. boot_device_id=
  511. title_correction_code=
  512.  
  513. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  514. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  515. submenu_indentation=""
  516.  
  517. is_first_entry=true
  518. while [ "x$list" != "x" ] ; do
  519.  linux=`version_find_latest $list`
  520.  gettext_printf "Found linux image: %s\n" "$linux" >&2
  521.  basename=`basename $linux`
  522.  dirname=`dirname $linux`
  523.  rel_dirname=`make_system_path_relative_to_its_root $dirname`
  524.  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  525.  alt_version=`echo $version | sed -e "s,\.old$,,g"`
  526.  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  527.  
  528.  initrd=
  529.  for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  530.        "initrd-${version}" "initramfs-${version}.img" \
  531.        "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  532.        "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  533.        "initramfs-genkernel-${version}" \
  534.        "initramfs-genkernel-${alt_version}" \
  535.        "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  536.        "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  537.    if test -e "${dirname}/${i}" ; then
  538.      initrd="$i"
  539.      break
  540.    fi
  541.  done
  542.  
  543.  config=
  544.  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  545.    if test -e "${i}" ; then
  546.      config="${i}"
  547.      break
  548.    fi
  549.  done
  550.  
  551.  initramfs=
  552.  if test -n "${config}" ; then
  553.      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  554.  fi
  555.  
  556.  if test -n "${initrd}" ; then
  557.    gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  558.  elif test -z "${initramfs}" ; then
  559.    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
  560.    # no initrd or builtin initramfs, it can't work here.
  561.    linux_root_device_thisversion=${GRUB_DEVICE}
  562.  fi
  563.  
  564.  if [ "x${GRUB_DISABLE_SUBMENU}" = x ]; then
  565.    if [ "x$is_first_entry" = xtrue ]; then
  566.      linux_entry "${OS}" "${version}" simple \
  567.      "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  568.  
  569.      submenu_indentation="$grub_tab"
  570.    
  571.      if [ -z "$boot_device_id" ]; then
  572.       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  573.      fi
  574.      # TRANSLATORS: %s is replaced with an OS name
  575.      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  576.    fi
  577.  fi
  578.  
  579.  linux_entry "${OS}" "${version}" advanced \
  580.              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  581.  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  582.    linux_entry "${OS}" "${version}" recovery \
  583.                "single ${GRUB_CMDLINE_LINUX}"
  584.  fi
  585.  
  586.  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  587.  is_first_entry=false
  588. done
  589.  
  590. # If at least one kernel was found, then we need to
  591. # add a closing '}' for the submenu command.
  592. if [ "x${GRUB_DISABLE_SUBMENU}" = x ]; then
  593.  if [ x"$is_first_entry" != xtrue ]; then
  594.    echo '}'
  595.  fi
  596. fi
  597.  
  598. echo "$title_correction_code"
  599. #! /bin/sh
  600. set -e
  601.  
  602. # grub-mkconfig helper script.
  603. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  604. #
  605. # GRUB is free software: you can redistribute it and/or modify
  606. # it under the terms of the GNU General Public License as published by
  607. # the Free Software Foundation, either version 3 of the License, or
  608. # (at your option) any later version.
  609. #
  610. # GRUB is distributed in the hope that it will be useful,
  611. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  612. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  613. # GNU General Public License for more details.
  614. #
  615. # You should have received a copy of the GNU General Public License
  616. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  617.  
  618. prefix="/usr"
  619. exec_prefix="/usr"
  620. datarootdir="${prefix}/share"
  621.  
  622. . "/usr/share/grub/grub-mkconfig_lib"
  623.  
  624. export TEXTDOMAIN=grub
  625. export TEXTDOMAINDIR="${datarootdir}/locale"
  626.  
  627. CLASS="--class gnu-linux --class gnu --class os --class xen"
  628.  
  629. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  630.  OS="$(sed 's, release .*$,,g' /etc/system-release)"
  631. else
  632.  OS="${GRUB_DISTRIBUTOR}"
  633.  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
  634. fi
  635.  
  636. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  637. # the initrds that Linux uses don't like that.
  638. case ${GRUB_DEVICE} in
  639.  /dev/loop/*|/dev/loop[0-9])
  640.    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  641.  ;;
  642. esac
  643.  
  644. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  645.    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  646.    || uses_abstraction "${GRUB_DEVICE}" lvm; then
  647.  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  648. else
  649.  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  650. fi
  651.  
  652. # Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
  653. if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
  654.  GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
  655. fi
  656. if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
  657.  GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
  658. fi
  659.  
  660. GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
  661.  
  662. if [ x"$GRUBFS" = x ]; then
  663.    GRUBFS="$(stat -f --printf=%T /)"
  664. fi
  665.  
  666. case x"$GRUBFS" in
  667.    xbtrfs)
  668.     rootsubvol="`make_system_path_relative_to_its_root /`"
  669.     rootsubvol="${rootsubvol#/}"
  670.     if [ "x${rootsubvol}" != x ]; then
  671.         GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  672.     fi;;
  673.    xzfs)
  674.     rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  675.     bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  676.     LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  677.     ;;
  678. esac
  679.  
  680. title_correction_code=
  681.  
  682. linux_entry ()
  683. {
  684.  os="$1"
  685.  version="$2"
  686.  xen_version="$3"
  687.  type="$4"
  688.  args="$5"
  689.  xen_args="$6"
  690.  if [ -z "$boot_device_id" ]; then
  691.      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  692.  fi
  693.  if [ x$type != xsimple ] ; then
  694.      if [ x$type = xrecovery ] ; then
  695.       title="$(gettext_printf "%s, with Xen %s and Linux %s (recovery mode)" "${os}" "${xen_version}" "${version}")"
  696.      else
  697.       title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
  698.      fi
  699.      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  700.      if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  701.         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  702.         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  703.         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")"
  704.      fi
  705.      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  706.  else
  707.      title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
  708.      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  709.  fi
  710.  if [ x$type != xrecovery ] ; then
  711.      save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
  712.  fi
  713.  
  714.  if [ -z "${prepare_boot_cache}" ]; then
  715.    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  716.  fi
  717.  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  718.  xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
  719.  lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
  720.  sed "s/^/$submenu_indentation/" << EOF
  721.     echo    '$(echo "$xmessage" | grub_quote)'
  722.        if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
  723.            xen_rm_opts=
  724.        else
  725.            xen_rm_opts="no-real-mode edd=off"
  726.        fi
  727.     multiboot   ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
  728.     echo    '$(echo "$lmessage" | grub_quote)'
  729.     module  ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
  730. EOF
  731.  if test -n "${initrd}" ; then
  732.    # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  733.    message="$(gettext_printf "Loading initial ramdisk ...")"
  734.    sed "s/^/$submenu_indentation/" << EOF
  735.     echo    '$(echo "$message" | grub_quote)'
  736.     module  ${rel_dirname}/${initrd}
  737. EOF
  738.  fi
  739.  sed "s/^/$submenu_indentation/" << EOF
  740. }
  741. EOF
  742. }
  743.  
  744. linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
  745.    if grub_file_is_not_garbage "$i"; then
  746.         basename=$(basename $i)
  747.     version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
  748.     dirname=$(dirname $i)
  749.     config=
  750.     for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  751.         if test -e "${j}" ; then
  752.         config="${j}"
  753.         break
  754.         fi
  755.     done
  756.        if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
  757.    fi
  758.    done`
  759. if [ "x${linux_list}" = "x" ] ; then
  760.    exit 0
  761. fi
  762.  
  763. file_is_not_sym () {
  764.    case "$1" in
  765.     */xen-syms-*)
  766.         return 1;;
  767.     *)
  768.         return 0;;
  769.    esac
  770. }
  771.  
  772. xen_list=`for i in /boot/xen*; do
  773.        if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then echo -n "$i " ; fi
  774.      done`
  775. prepare_boot_cache=
  776. boot_device_id=
  777.  
  778. title_correction_code=
  779.  
  780. machine=`uname -m`
  781.  
  782. case "$machine" in
  783.    i?86) GENKERNEL_ARCH="x86" ;;
  784.    mips|mips64) GENKERNEL_ARCH="mips" ;;
  785.    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  786.    arm*) GENKERNEL_ARCH="arm" ;;
  787.    *) GENKERNEL_ARCH="$machine" ;;
  788. esac
  789.  
  790. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  791. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  792. submenu_indentation=""
  793.  
  794. is_first_entry=true
  795.  
  796. while [ "x${xen_list}" != "x" ] ; do
  797.    list="${linux_list}"
  798.    current_xen=`version_find_latest $xen_list`
  799.    xen_basename=`basename ${current_xen}`
  800.    xen_dirname=`dirname ${current_xen}`
  801.    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
  802.    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
  803.    if [ -z "$boot_device_id" ]; then
  804.     boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  805.    fi
  806.    if [ "x$is_first_entry" != xtrue ]; then
  807.     echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
  808.    fi
  809.    while [ "x$list" != "x" ] ; do
  810.     linux=`version_find_latest $list`
  811.     gettext_printf "Found linux image: %s\n" "$linux" >&2
  812.     basename=`basename $linux`
  813.     dirname=`dirname $linux`
  814.     rel_dirname=`make_system_path_relative_to_its_root $dirname`
  815.     version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  816.     alt_version=`echo $version | sed -e "s,\.old$,,g"`
  817.     linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  818.  
  819.     initrd=
  820.     for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  821.        "initrd-${version}" "initramfs-${version}.img" \
  822.        "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  823.        "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  824.        "initramfs-genkernel-${version}" \
  825.        "initramfs-genkernel-${alt_version}" \
  826.        "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  827.        "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
  828.         if test -e "${dirname}/${i}" ; then
  829.         initrd="$i"
  830.         break
  831.         fi
  832.     done
  833.     if test -n "${initrd}" ; then
  834.         gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  835.     else
  836.    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
  837.         linux_root_device_thisversion=${GRUB_DEVICE}
  838.     fi
  839.  
  840.     if [ "x$is_first_entry" = xtrue ]; then
  841.         linux_entry "${OS}" "${version}" "${xen_version}" simple \
  842.         "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  843.  
  844.         submenu_indentation="$grub_tab$grub_tab"
  845.    
  846.         if [ -z "$boot_device_id" ]; then
  847.         boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  848.         fi
  849.            # TRANSLATORS: %s is replaced with an OS name
  850.         echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  851.     echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
  852.     fi
  853.     is_first_entry=false
  854.  
  855.     linux_entry "${OS}" "${version}" "${xen_version}" advanced \
  856.         "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  857.     if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  858.         linux_entry "${OS}" "${version}" "${xen_version}" recovery \
  859.         "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
  860.     fi
  861.  
  862.     list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  863.    done
  864.    if [ x"$is_first_entry" != xtrue ]; then
  865.     echo '  }'
  866.    fi
  867.    xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
  868. done
  869.  
  870. # If at least one kernel was found, then we need to
  871. # add a closing '}' for the submenu command.
  872. if [ x"$is_first_entry" != xtrue ]; then
  873.  echo '}'
  874. fi
  875.  
  876. echo "$title_correction_code"
  877. #! /bin/sh
  878. set -e
  879.  
  880. # grub-mkconfig helper script.
  881. # Copyright (C) 2011  Michal Ambroz <[email protected]>
  882. #
  883. # you can redistribute it and/or modify
  884. # it under the terms of the GNU General Public License as published by
  885. # the Free Software Foundation, either version 3 of the License, or
  886. # (at your option) any later version.
  887. #
  888. # Distributed in the hope that it will be useful,
  889. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  890. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  891. # GNU General Public License for more details.
  892. #
  893. # You should have received a copy of the GNU General Public License
  894. # along with the script.  If not, see <http://www.gnu.org/licenses/>.
  895.  
  896. prefix=/usr
  897. exec_prefix=/usr
  898. bindir=/usr/bin
  899. grublibdir=/usr/share/grub
  900. . ${grublibdir}/grub-mkconfig_lib
  901.  
  902. export TEXTDOMAIN=grub
  903. export TEXTDOMAINDIR=${prefix}/share/locale
  904.  
  905. CLASS=""
  906.  
  907. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  908.  OS=Memtest
  909. else
  910.  OS="${GRUB_DISTRIBUTOR} Memtest"
  911. fi
  912.  
  913. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  914. # the initrds that Linux uses don't like that.
  915. case ${GRUB_DEVICE} in
  916.  /dev/loop/*|/dev/loop[0-9])
  917.    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  918.  ;;
  919. esac
  920.  
  921. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  922.    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  923.    || uses_abstraction "${GRUB_DEVICE}" lvm; then
  924.  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  925. else
  926.  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  927. fi
  928.  
  929. if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
  930.  rootsubvol="`make_system_path_relative_to_its_root /`"
  931.  rootsubvol="${rootsubvol#/}"
  932.  if [ "x${rootsubvol}" != x ]; then
  933.    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  934.  fi
  935. fi
  936.  
  937. memtest_entry ()
  938. {
  939.  os="$1"
  940.  version="$2"
  941.  recovery="$3"
  942.  args="$4"
  943.  title="$(gettext_quoted "%s %s")"
  944.  printf "menuentry '${title}' {\n" "${os}" "${version}"
  945.  
  946.  
  947.  if [ x$dirname = x/ ]; then
  948.    if [ -z "${prepare_root_cache}" ]; then
  949.      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
  950.    fi
  951.    printf '%s\n' "${prepare_root_cache}"
  952.  else
  953.    if [ -z "${prepare_boot_cache}" ]; then
  954.      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  955.    fi
  956.    printf '%s\n' "${prepare_boot_cache}"
  957.  fi
  958.  message="$(gettext_printf "Loading %s %s ..." ${os} ${version})"
  959.  cat << EOF
  960.     insmod bsd
  961.     echo    '$message'
  962.     knetbsd ${rel_dirname}/${basename}
  963. }
  964. EOF
  965. }
  966.  
  967. case x`uname -m` in
  968.    xi?86 | xx86_64)
  969.     list=`for i in /boot/elf-memtest* ; do
  970.                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  971.              done` ;;
  972.    *)
  973.     list=`for i in /boot/elf-memtest* ; do
  974.                  if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  975.          done` ;;
  976. esac
  977.  
  978. prepare_boot_cache=
  979. prepare_root_cache=
  980.  
  981. while [ "x$list" != "x" ] ; do
  982.  linux=`version_find_latest $list`
  983.  echo "Found memtest image: $linux" >&2
  984.  basename=`basename $linux`
  985.  dirname=`dirname $linux`
  986.  rel_dirname=`make_system_path_relative_to_its_root $dirname`
  987.  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  988.  alt_version=`echo $version | sed -e "s,\.old$,,g"`
  989.  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  990.  
  991.  
  992.  memtest_entry "${OS}" "${version}" false \
  993.      "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  994.  
  995.  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  996. done
  997. #! /bin/sh
  998. set -e
  999.  
  1000. # grub-mkconfig helper script.
  1001. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  1002. #
  1003. # GRUB is free software: you can redistribute it and/or modify
  1004. # it under the terms of the GNU General Public License as published by
  1005. # the Free Software Foundation, either version 3 of the License, or
  1006. # (at your option) any later version.
  1007. #
  1008. # GRUB is distributed in the hope that it will be useful,
  1009. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  1010. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1011. # GNU General Public License for more details.
  1012. #
  1013. # You should have received a copy of the GNU General Public License
  1014. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  1015.  
  1016. prefix=/usr
  1017. exec_prefix=/usr
  1018. bindir=/usr/bin
  1019. libdir=/usr/lib
  1020. . "/usr/share/grub/grub-mkconfig_lib"
  1021.  
  1022. export TEXTDOMAIN=grub
  1023. export TEXTDOMAINDIR=${prefix}/share/locale
  1024.  
  1025. X=80
  1026. Y=24
  1027. TERMINAL=ofconsole
  1028.  
  1029. argument () {
  1030.  opt=$1
  1031.  shift
  1032.  
  1033.  if test $# -eq 0; then
  1034.      echo "$0: option requires an argument -- '$opt'" 1>&2
  1035.      exit 1
  1036.  fi
  1037.  echo $1
  1038. }
  1039.  
  1040. check_terminfo () {
  1041.  
  1042.  while test $# -gt 0
  1043.  do
  1044.    option=$1
  1045.    shift
  1046.  
  1047.    case "$option" in
  1048.    terminfo | TERMINFO)
  1049.        ;;
  1050.  
  1051.    -g)
  1052.        NEWXY=`argument $option "$@"`
  1053.        NEWX=`echo $NEWXY | cut -d x -f 1`
  1054.        NEWY=`echo $NEWXY | cut -d x -f 2`
  1055.  
  1056.        if [ ${NEWX} -ge 80 ] ; then
  1057.          X=${NEWX}
  1058.        else
  1059.          echo "Warning: ${NEWX} is less than the minimum size of 80"
  1060.        fi
  1061.  
  1062.        if [ ${NEWY} -ge 24 ] ; then
  1063.          Y=${NEWY}
  1064.        else
  1065.          echo "Warning: ${NEWY} is less than the minimum size of 24"
  1066.        fi
  1067.  
  1068.        shift
  1069.        ;;
  1070.  
  1071.    *)
  1072. #       # accept console or ofconsole
  1073. #       if [ "$option" != "console" -a "$option" != "ofconsole" ] ; then
  1074. #         echo "Error: GRUB_TERMINFO unknown console: $option"
  1075. #         exit 1
  1076. #       fi
  1077. #       # perfer console
  1078. #       TERMINAL=console
  1079.        # accept ofconsole
  1080.        if [ "$option" != "ofconsole" ] ; then
  1081.          echo "Error: GRUB_TERMINFO unknown console: $option"
  1082.          exit 1
  1083.        fi
  1084.        # perfer console
  1085.        TERMINAL=ofconsole
  1086.        ;;
  1087.    esac
  1088.  
  1089.  done
  1090.  
  1091. }
  1092.  
  1093. if ! uname -m | grep -q ppc ; then
  1094.  exit 0
  1095. fi
  1096.  
  1097. if [ "x${GRUB_TERMINFO}" != "x" ] ; then
  1098.  F1=`echo ${GRUB_TERMINFO} | cut -d " " -f 1`
  1099.  
  1100.  if [ "${F1}" != "terminfo" ] ; then
  1101.    echo "Error: GRUB_TERMINFO is set to \"${GRUB_TERMINFO}\" The first word should be terminfo."
  1102.    exit 1
  1103.  fi
  1104.  
  1105.  check_terminfo ${GRUB_TERMINFO}
  1106. fi
  1107.  
  1108. cat << EOF
  1109.  terminfo -g ${X}x${Y} ${TERMINAL}
  1110. EOF
  1111. #! /bin/sh
  1112. set -e
  1113.  
  1114. # grub-mkconfig helper script.
  1115. # Copyright (C) 2006,2007,2008,2009  Free Software Foundation, Inc.
  1116. #
  1117. # GRUB is free software: you can redistribute it and/or modify
  1118. # it under the terms of the GNU General Public License as published by
  1119. # the Free Software Foundation, either version 3 of the License, or
  1120. # (at your option) any later version.
  1121. #
  1122. # GRUB is distributed in the hope that it will be useful,
  1123. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  1124. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1125. # GNU General Public License for more details.
  1126. #
  1127. # You should have received a copy of the GNU General Public License
  1128. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  1129.  
  1130. prefix="/usr"
  1131. exec_prefix="/usr"
  1132. datarootdir="${prefix}/share"
  1133.  
  1134. export TEXTDOMAIN=grub
  1135. export TEXTDOMAINDIR="${datarootdir}/locale"
  1136.  
  1137. . "/usr/share/grub/grub-mkconfig_lib"
  1138.  
  1139. if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
  1140.  exit 0
  1141. fi
  1142.  
  1143. if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
  1144.  # missing os-prober and/or linux-boot-prober
  1145.  exit 0
  1146. fi
  1147.  
  1148. OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
  1149. if [ -z "${OSPROBED}" ] ; then
  1150.  # empty os-prober output, nothing doing
  1151.  exit 0
  1152. fi
  1153.  
  1154. osx_entry() {
  1155.    if [ x$2 = x32 ]; then
  1156.        # TRANSLATORS: it refers to kernel architecture (32-bit)
  1157.     bitstr="$(gettext "(32-bit)")"
  1158.    else
  1159.        # TRANSLATORS: it refers to kernel architecture (64-bit)
  1160.     bitstr="$(gettext "(64-bit)")"
  1161.    fi
  1162.    # TRANSLATORS: it refers on the OS residing on device %s
  1163.    onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  1164.        cat << EOF
  1165. menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
  1166. EOF
  1167.     save_default_entry | grub_add_tab
  1168.     prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  1169.     cat << EOF
  1170.        load_video
  1171.        set do_resume=0
  1172.        if [ /var/vm/sleepimage -nt10 / ]; then
  1173.           if xnu_resume /var/vm/sleepimage; then
  1174.             set do_resume=1
  1175.           fi
  1176.        fi
  1177.        if [ \$do_resume = 0 ]; then
  1178.           xnu_uuid ${OSXUUID} uuid
  1179.           if [ -f /Extra/DSDT.aml ]; then
  1180.              acpi -e /Extra/DSDT.aml
  1181.           fi
  1182.           if [ /kernelcache -nt /System/Library/Extensions ]; then
  1183.              $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
  1184.           else
  1185.              $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
  1186.              if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
  1187.                xnu_mkext /System/Library/Extensions.mkext
  1188.              else
  1189.                xnu_kextdir /System/Library/Extensions
  1190.              fi
  1191.           fi
  1192.           if [ -f /Extra/Extensions.mkext ]; then
  1193.              xnu_mkext /Extra/Extensions.mkext
  1194.           fi
  1195.           if [ -d /Extra/Extensions ]; then
  1196.              xnu_kextdir /Extra/Extensions
  1197.           fi
  1198.           if [ -f /Extra/devprop.bin ]; then
  1199.              xnu_devprop_load /Extra/devprop.bin
  1200.           fi
  1201.           if [ -f /Extra/splash.jpg ]; then
  1202.              insmod jpeg
  1203.              xnu_splash /Extra/splash.jpg
  1204.           fi
  1205.           if [ -f /Extra/splash.png ]; then
  1206.              insmod png
  1207.              xnu_splash /Extra/splash.png
  1208.           fi
  1209.           if [ -f /Extra/splash.tga ]; then
  1210.              insmod tga
  1211.              xnu_splash /Extra/splash.tga
  1212.           fi
  1213.        fi
  1214. }
  1215. EOF
  1216. }
  1217.  
  1218. used_osprober_linux_ids=
  1219.  
  1220. for OS in ${OSPROBED} ; do
  1221.  DEVICE="`echo ${OS} | cut -d ':' -f 1`"
  1222.  LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
  1223.  LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
  1224.  BOOT="`echo ${OS} | cut -d ':' -f 4`"
  1225.  BTRFS="`echo ${OS} | cut -d ':' -f 5`"
  1226.  if [ "x$BTRFS" = "xbtrfs" ]; then
  1227.     BTRFSuuid="`echo ${OS} | cut -d ':' -f 6`"
  1228.     BTRFSsubvol="`echo ${OS} | cut -d ':' -f 7`"
  1229.  fi
  1230.  
  1231.  if [ -z "${LONGNAME}" ] ; then
  1232.    LONGNAME="${LABEL}"
  1233.  fi
  1234.  
  1235.  gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2
  1236.  
  1237.  case ${BOOT} in
  1238.    chain)
  1239.  
  1240.       onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  1241.      cat << EOF
  1242. menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
  1243. EOF
  1244.      save_default_entry | grub_add_tab
  1245.      prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  1246.  
  1247.      case ${LONGNAME} in
  1248.     Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
  1249.     ;;
  1250.     *)
  1251.       cat << EOF
  1252.     drivemap -s (hd0) \${root}
  1253. EOF
  1254.     ;;
  1255.      esac
  1256.  
  1257.      cat <<EOF
  1258.     chainloader +1
  1259. }
  1260. EOF
  1261.    ;;
  1262.    linux)
  1263.      if [ "x$BTRFS" = "xbtrfs" ]; then
  1264.         LINUXPROBED="`linux-boot-prober btrfs ${BTRFSuuid} ${BTRFSsubvol}  2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
  1265.      else
  1266.         LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
  1267.      fi
  1268.      prepare_boot_cache=
  1269.      boot_device_id=
  1270.      is_first_entry=true
  1271.      title_correction_code=
  1272.      OS="${LONGNAME}"
  1273.  
  1274.      for LINUX in ${LINUXPROBED} ; do
  1275.        LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
  1276.        LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
  1277.        LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
  1278.        LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
  1279.        LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
  1280.        LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
  1281.  
  1282.        if [ -z "${LLABEL}" ] ; then
  1283.          LLABEL="${LONGNAME}"
  1284.        fi
  1285.  
  1286.     if [ "${LROOT}" != "${LBOOT}" ]; then
  1287.       LKERNEL="${LKERNEL#/boot}"
  1288.       LINITRD="${LINITRD#/boot}"
  1289.     fi
  1290.  
  1291.     onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  1292.     recovery_params="$(echo "${LPARAMS}" | grep single)" || true
  1293.     counter=1
  1294.     while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
  1295.         counter=$((counter+1));
  1296.     done
  1297.     if [ -z "$boot_device_id" ]; then
  1298.         boot_device_id="$(grub_get_device_id "${DEVICE}")"
  1299.     fi
  1300.     used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
  1301.  
  1302.     if [ -z "${prepare_boot_cache}" ]; then
  1303.       prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)"
  1304.     fi
  1305.  
  1306.     if [ "x$is_first_entry" = xtrue ]; then
  1307.            cat << EOF
  1308. menuentry '$(echo "$OS $onstr" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
  1309. EOF
  1310.         save_default_entry | grub_add_tab
  1311.         printf '%s\n' "${prepare_boot_cache}"
  1312.         cat <<  EOF
  1313.     linux ${LKERNEL} ${LPARAMS}
  1314. EOF
  1315.            if [ -n "${LINITRD}" ] ; then
  1316.          cat << EOF
  1317.     initrd ${LINITRD}
  1318. EOF
  1319.            fi
  1320.        cat << EOF
  1321. }
  1322. EOF
  1323.         echo "submenu '$(gettext_printf "Advanced options for %s" "${OS} $onstr" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
  1324.         is_first_entry=false
  1325.     fi
  1326.     title="${LLABEL} $onstr"
  1327.        cat << EOF
  1328.     menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
  1329. EOF
  1330.     save_default_entry | sed -e "s/^/$grub_tab$grub_tab/"
  1331.     printf '%s\n' "${prepare_boot_cache}" | grub_add_tab
  1332.     cat <<  EOF
  1333.         linux ${LKERNEL} ${LPARAMS}
  1334. EOF
  1335.        if [ -n "${LINITRD}" ] ; then
  1336.            cat << EOF
  1337.         initrd ${LINITRD}
  1338. EOF
  1339.        fi
  1340.        cat << EOF
  1341.     }
  1342. EOF
  1343.     if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  1344.         replacement_title="$(echo "Advanced options for ${OS} $onstr" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  1345.         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  1346.         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  1347.         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")"
  1348.     fi
  1349.      done
  1350.      if [ x"$is_first_entry" != xtrue ]; then
  1351.       echo '}'
  1352.      fi
  1353.      echo "$title_correction_code"
  1354.    ;;
  1355.    macosx)
  1356.      OSXUUID="`${grub_probe} --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
  1357.      osx_entry xnu_kernel 32
  1358.      osx_entry xnu_kernel64 64
  1359.    ;;
  1360.    hurd)
  1361.      onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
  1362.      cat << EOF
  1363. menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
  1364. EOF
  1365.      save_default_entry | grub_add_tab
  1366.      prepare_grub_to_access_device ${DEVICE} | grub_add_tab
  1367.      grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
  1368.      mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
  1369.      grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
  1370.       case "${grub_fs}" in
  1371.     *fs)    hurd_fs="${grub_fs}" ;;
  1372.     *)  hurd_fs="${grub_fs}fs" ;;
  1373.       esac
  1374.       cat << EOF
  1375.     multiboot /boot/gnumach.gz root=device:${mach_device}
  1376.     module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
  1377.             --multiboot-command-line='\${kernel-command-line}' \\
  1378.             --host-priv-port='\${host-port}' \\
  1379.             --device-master-port='\${device-port}' \\
  1380.             --exec-server-task='\${exec-task}' -T typed '\${root}' \\
  1381.             '\$(task-create)' '\$(task-resume)'
  1382.     module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
  1383. }
  1384. EOF
  1385.     ;;
  1386.     *)
  1387.       case ${DEVICE} in
  1388.     *.efi)
  1389.       cat << EOF
  1390. menuentry '$(echo "${LONGNAME}" | grub_quote)' {
  1391. EOF
  1392.       save_default_entry | grub_add_tab
  1393.       cat << EOF
  1394.       chainloader /EFI/${DEVICE}
  1395.       boot
  1396. }
  1397. EOF
  1398.       ;;
  1399.     *)
  1400.           echo -n "  "
  1401.           # TRANSLATORS: %s is replaced by OS name.
  1402.           gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2
  1403.         ;;
  1404.       esac
  1405.   esac
  1406. done
  1407. #!/bin/sh
  1408. exec tail -n +3 $0
  1409. # This file provides an easy way to add custom menu entries.  Simply type the
  1410. # menu entries you want to add after this comment.  Be careful not to change
  1411. # the 'exec tail' line above.
  1412. #!/bin/sh
  1413. cat <<EOF
  1414. if [ -f  \${config_directory}/custom.cfg ]; then
  1415.   source \${config_directory}/custom.cfg
  1416. elif [ -z "\${config_directory}" -a -f  \$prefix/custom.cfg ]; then
  1417.   source \$prefix/custom.cfg;
  1418. fi
  1419. EOF
  1420.  
  1421.  
  1422. All executable files in this directory are processed in shell expansion order.
  1423.  
  1424.   00_*: Reserved for 00_header.
  1425.   10_*: Native boot entries.
  1426.   20_*: Third party apps (e.g. memtest86+).
  1427.  
  1428. The number namespace in-between is configurable by system installer and/or
  1429. administrator.  For example, you can add an entry to boot another OS as
  1430. 01_otheros, 11_otheros, etc, depending on the position you want it to occupy in
  1431. the menu; and then adjust the default setting via /etc/default/grub.
Advertisement
Add Comment
Please, Sign In to add comment