/grub.d/10_linux

http://github.com/brinkman83/bashrc · Shell · 153 lines · 116 code · 16 blank · 21 comment · 24 complexity · 937e21c78def99a9cf22d2c95280ef88 MD5 · raw file

  1. #! /bin/sh -e
  2. # grub-mkconfig helper script.
  3. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  4. #
  5. # GRUB is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # GRUB is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. prefix=/usr
  18. exec_prefix=${prefix}
  19. bindir=${exec_prefix}/bin
  20. libdir=${exec_prefix}/lib
  21. . ${libdir}/grub/grub-mkconfig_lib
  22. export TEXTDOMAIN=grub
  23. export TEXTDOMAINDIR=@LOCALEDIR@
  24. CLASS="--class gnu-linux --class gnu --class os"
  25. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  26. OS=GNU/Linux
  27. else
  28. OS="${GRUB_DISTRIBUTOR}"
  29. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
  30. fi
  31. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  32. # the initrds that Linux uses don't like that.
  33. case ${GRUB_DEVICE} in
  34. /dev/loop/*|/dev/loop[0-9])
  35. GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  36. # We can't cope with devices loop-mounted from files here.
  37. case ${GRUB_DEVICE} in
  38. /dev/*) ;;
  39. *) exit 0 ;;
  40. esac
  41. ;;
  42. esac
  43. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  44. || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  45. || [ "`grub-probe -t abstraction --device ${GRUB_DEVICE} | sed -e 's,.*\(lvm\).*,\1,'`" = "lvm" ] ; then
  46. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  47. else
  48. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  49. fi
  50. # add crashkernel option if we have the required tools
  51. if [ -x "/usr/bin/makedumpfile" ] && [ -x "/sbin/kexec" ]; then
  52. GRUB_CMDLINE_EXTRA="$GRUB_CMDLINE_EXTRA crashkernel=384M-2G:64M,2G-:128M"
  53. fi
  54. linux_entry ()
  55. {
  56. os="$1"
  57. version="$2"
  58. recovery="$3"
  59. args="$4"
  60. if ${recovery} ; then
  61. title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
  62. else
  63. title="$(gettext_quoted "%s, with Linux %s")"
  64. fi
  65. printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  66. cat << EOF
  67. recordfail
  68. EOF
  69. save_default_entry | sed -e "s/^/\t/"
  70. if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then
  71. cat << EOF
  72. set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
  73. EOF
  74. fi
  75. if [ -z "${prepare_boot_cache}" ]; then
  76. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  77. fi
  78. printf '%s\n' "${prepare_boot_cache}"
  79. if [ "x$5" != "xquiet" ]; then
  80. cat << EOF
  81. echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
  82. EOF
  83. fi
  84. cat << EOF
  85. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  86. EOF
  87. if [ "x$5" != "xquiet" ]; then
  88. cat << EOF
  89. echo '$(gettext_quoted "Loading initial ramdisk ...")'
  90. EOF
  91. fi
  92. if test -n "${initrd}" ; then
  93. cat << EOF
  94. initrd ${rel_dirname}/${initrd}
  95. EOF
  96. fi
  97. cat << EOF
  98. }
  99. EOF
  100. }
  101. list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
  102. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  103. done`
  104. prepare_boot_cache=
  105. while [ "x$list" != "x" ] ; do
  106. linux=`version_find_latest $list`
  107. echo "Found linux image: $linux" >&2
  108. basename=`basename $linux`
  109. dirname=`dirname $linux`
  110. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  111. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  112. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  113. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  114. initrd=
  115. for i in "initrd.img-${version}" "initrd-${version}.img" \
  116. "initrd-${version}" "initrd.img-${alt_version}" \
  117. "initrd-${alt_version}.img" "initrd-${alt_version}"; do
  118. if test -e "${dirname}/${i}" ; then
  119. initrd="$i"
  120. break
  121. fi
  122. done
  123. if test -n "${initrd}" ; then
  124. echo "Found initrd image: ${dirname}/${initrd}" >&2
  125. else
  126. # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
  127. linux_root_device_thisversion=${GRUB_DEVICE}
  128. fi
  129. linux_entry "${OS}" "${version}" false \
  130. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}" \
  131. quiet
  132. if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
  133. linux_entry "${OS}" "${version}" true \
  134. "single ${GRUB_CMDLINE_LINUX}"
  135. fi
  136. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  137. done