Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Stuff
Tuesday, July 10th, 2012 at 10:29:49am UTC 

  1. #! /bin/sh
  2. set -e
  3.  
  4. # grub-mkconfig helper script.
  5. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  6. #
  7. # GRUB is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # GRUB is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. prefix="/usr"
  21. exec_prefix="${prefix}"
  22. datarootdir="${prefix}/share"
  23.  
  24. . "${datarootdir}/grub/grub-mkconfig_lib"
  25.  
  26. export TEXTDOMAIN=grub
  27. export TEXTDOMAINDIR="${datarootdir}/locale"
  28.  
  29. CLASS="--class gnu-linux --class gnu --class os"
  30.  
  31. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  32.   OS=GNU/Linux
  33. else
  34.   OS="${GRUB_DISTRIBUTOR}"
  35.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
  36. fi
  37.  
  38. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  39. # the initrds that Linux uses don't like that.
  40. case ${GRUB_DEVICE} in
  41.   /dev/loop/*|/dev/loop[0-9])
  42.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  43.     # We can't cope with devices loop-mounted from files here.
  44.     case ${GRUB_DEVICE} in
  45.       /dev/*) ;;
  46.       *) exit 0 ;;
  47.     esac
  48.   ;;
  49. esac
  50.  
  51. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  52.     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  53.     || uses_abstraction "${GRUB_DEVICE}" lvm; then
  54.   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  55. else
  56.   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  57. fi
  58.  
  59. if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ] \
  60.     || [ "x`stat -f --printf=%T /`" = xbtrfs ]; then
  61.   rootsubvol="`make_system_path_relative_to_its_root /`"
  62.   rootsubvol="${rootsubvol#/}"
  63.   if [ "x${rootsubvol}" != x ]; then
  64.     GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  65.   fi
  66. fi
  67.  
  68. for word in $GRUB_CMDLINE_LINUX_DEFAULT; do
  69.   if [ "$word" = splash ]; then
  70.     GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT \$vt_handoff"
  71.   fi
  72. done
  73.  
  74. # add crashkernel option if we have the required tools
  75. if [ -x "/usr/bin/makedumpfile" ] && [ -x "/sbin/kexec" ]; then
  76.     GRUB_CMDLINE_EXTRA="$GRUB_CMDLINE_EXTRA crashkernel=384M-2G:64M,2G-:128M"
  77. fi
  78.  
  79. linux_entry ()
  80. {
  81.   os="$1"
  82.   version="$2"
  83.   recovery="$3"
  84.   args="$4"
  85.   if ${recovery} ; then
  86.     title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
  87.   else
  88.     title="$(gettext_quoted "%s, with Linux %s")"
  89.   fi
  90.   printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  91.   cat << EOF
  92.         recordfail
  93. EOF
  94.   if ! ${recovery} ; then
  95.       save_default_entry | sed -e "s/^/\t/"
  96.  
  97.       cat << EOF
  98.         EOF
  99.   fi
  100.  
  101.   cat << EOF
  102.         insmod gzio
  103. EOF
  104.  
  105.   if [ x$dirname = x/ ]; then
  106.     if [ -z "${prepare_root_cache}" ]; then
  107.       prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
  108.     fi
  109.     printf '%s\n' "${prepare_root_cache}"
  110.   else
  111.     if [ -z "${prepare_boot_cache}" ]; then
  112.       prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  113.     fi
  114.     printf '%s\n' "${prepare_boot_cache}"
  115.   fi
  116.   if [ "x$5" != "xquiet" ]; then
  117.     message="$(gettext_printf "Loading Linux %s ..." ${version})"
  118.     cat << EOF
  119.         echo    '$message'
  120. EOF
  121.   fi
  122.   cat << EOF
  123.         linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  124. EOF
  125.   if test -n "${initrd}" ; then
  126.     if [ "x$5" != "xquiet" ]; then
  127.       message="$(gettext_printf "Loading initial ramdisk ...")"
  128.       cat << EOF
  129.         echo    '$message'
  130. EOF
  131.     fi
  132.     cat << EOF
  133.         initrd  ${rel_dirname}/${initrd}
  134. EOF
  135.   fi
  136.   cat << EOF
  137. }
  138. EOF
  139. }
  140.  
  141. case x`uname -m` in
  142.     xi?86 | xx86_64)
  143.         list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  144.                   if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  145.               done` ;;
  146.     *)
  147.         list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  148.                   if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  149.              done` ;;
  150. esac
  151.  
  152. prepare_boot_cache=
  153. prepare_root_cache=
  154.  
  155. cat << 'EOF'
  156. function gfxmode {
  157.         set gfxpayload="${1}"
  158.         if [ "${1}" = "keep" ]; then
  159.                 set vt_handoff=vt.handoff=7
  160.         else
  161.                 set vt_handoff=
  162.         fi
  163. }
  164. EOF
  165.  
  166. # Use ELILO's generic "efifb" when it's known to be available.
  167. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  168. if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then
  169.   echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
  170. else
  171.   cat << EOF
  172. if [ "\${recordfail}" != 1 ]; then
  173.   if [ -e \${prefix}/gfxblacklist.txt ]; then
  174.     if hwmatch \${prefix}/gfxblacklist.txt 3; then
  175.       if [ \${match} = 0 ]; then
  176.         set linux_gfx_mode=keep
  177.       else
  178.         set linux_gfx_mode=text
  179.       fi
  180.     else
  181.       set linux_gfx_mode=text
  182.     fi
  183.   else
  184.     set linux_gfx_mode=keep
  185.   fi
  186. else
  187.   set linux_gfx_mode=text
  188. fi
  189. EOF
  190. fi
  191. cat << EOF
  192. export linux_gfx_mode
  193. if [ "\${linux_gfx_mode}" != "text" ]; then load_video; fi
  194. EOF
  195.  
  196. in_submenu=false
  197. while [ "x$list" != "x" ] ; do
  198.   linux=`version_find_latest $list`
  199.   echo "Found linux image: $linux" >&2
  200.   basename=`basename $linux`
  201.   dirname=`dirname $linux`
  202.   rel_dirname=`make_system_path_relative_to_its_root $dirname`
  203.   version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  204.   alt_version=`echo $version | sed -e "s,\.old$,,g"`
  205.   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  206.  
  207.   initrd=
  208.   for i in "initrd.img-${version}" "initrd-${version}.img" \
  209.            "initrd-${version}" "initramfs-${version}.img" \
  210.            "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  211.            "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  212.            "initramfs-genkernel-${version}" \
  213.            "initramfs-genkernel-${alt_version}"; do
  214.     if test -e "${dirname}/${i}" ; then
  215.       initrd="$i"
  216.       break
  217.     fi
  218.   done
  219.  
  220.   config=
  221.   for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  222.     if test -e "${i}" ; then
  223.       config="${i}"
  224.       break
  225.     fi
  226.   done
  227.  
  228.   initramfs=
  229.   if test -n "${config}" ; then
  230.       initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  231.   fi
  232.  
  233.   if test -n "${initrd}" ; then
  234.     echo "Found initrd image: ${dirname}/${initrd}" >&2
  235.   elif test -z "${initramfs}" ; then
  236.     # "UUID=" magic is parsed by initrd or initramfs.  Since there's
  237.     # no initrd or builtin initramfs, it can't work here.
  238.     linux_root_device_thisversion=${GRUB_DEVICE}
  239.   fi
  240.  
  241.   linux_entry "${OS}" "${version}" false \
  242.       "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}" \
  243.       quiet
  244.   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  245.     if [ -x /lib/recovery-mode/recovery-menu ]; then
  246.       linux_entry "${OS}" "${version}" true \
  247.         "recovery nomodeset ${GRUB_CMDLINE_LINUX}"
  248.     else
  249.       linux_entry "${OS}" "${version}" true \
  250.         "single nomodeset ${GRUB_CMDLINE_LINUX}"
  251.     fi
  252.   fi
  253.  
  254.   list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  255.  
  256.   if [ "$list" ] && ! $in_submenu; then
  257.     echo "submenu \"Previous Linux versions\" {"
  258.     in_submenu=:
  259.   fi
  260. done
  261.  
  262. if $in_submenu; then
  263.   echo "}"
  264. fi

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right