barjac

10_linux (labels)

Oct 27th, 2010
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. #! /bin/sh -e
  2.  
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. prefix=/usr
  20. exec_prefix=/usr
  21. bindir=/usr/bin
  22. libdir=/usr/lib
  23. . ${libdir}/grub/grub-mkconfig_lib
  24.  
  25. export TEXTDOMAIN=grub
  26. export TEXTDOMAINDIR=@LOCALEDIR@
  27.  
  28. CLASS="--class gnu-linux --class gnu --class os"
  29.  
  30. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  31. OS=GNU/Linux
  32. else
  33. OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  34. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]') ${CLASS}"
  35. fi
  36.  
  37. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  38. # the initrds that Linux uses don't like that.
  39. case ${GRUB_DEVICE} in
  40. /dev/loop/*|/dev/loop[0-9])
  41. GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  42. ;;
  43. esac
  44.  
  45. # If device has no uuid OR GRUB_DISABLE_LINUX_UUID is true OR search for dev with uuid fails (bcj)
  46. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  47. || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then
  48. # Use /dev/xxx (bcj)
  49. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  50. else
  51. # If A label exists and grub-mkconfig was run with -l option (bcj)
  52. if [ "x${GRUB_DEVICE_LABEL}" != "x" ] && [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then
  53. LINUX_ROOT_DEVICE=LABEL=${GRUB_DEVICE_LABEL}
  54. else
  55. # Use UUID (bcj)
  56. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  57. fi
  58. fi
  59.  
  60. linux_entry ()
  61. {
  62. os="$1"
  63. version="$2"
  64. recovery="$3"
  65. args="$4"
  66. if ${recovery} ; then
  67. title="$(gettext "%s, with Linux %s (recovery mode)")"
  68. else
  69. title="$(gettext "%s, with Linux %s")"
  70. fi
  71. printf "menuentry \"${title}\" ${CLASS} {\n" "${os}" "${version}"
  72. save_default_entry | sed -e "s/^/\t/"
  73.  
  74. # Use ELILO's generic "efifb" when it's known to be available.
  75. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  76. # if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  77. # if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \
  78. # && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then
  79. # cat << EOF
  80. # set gfxpayload=keep
  81. #EOF
  82. # fi
  83. # else
  84. # cat << EOF
  85. # set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
  86. #EOF
  87. # fi
  88.  
  89. if [ -z "${prepare_boot_cache}" ]; then
  90. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  91. fi
  92. printf '%s\n' "${prepare_boot_cache}"
  93. cat << EOF
  94. echo $(printf "$(gettext "Loading Linux %s ...")" ${version})
  95. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  96. EOF
  97. if test -n "${initrd}" ; then
  98. cat << EOF
  99. echo $(gettext "Loading initial ramdisk ...")
  100. initrd ${rel_dirname}/${initrd}
  101. EOF
  102. fi
  103. cat << EOF
  104. }
  105. EOF
  106. }
  107.  
  108. list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
  109. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  110. done`
  111. prepare_boot_cache=
  112.  
  113. while [ "x$list" != "x" ] ; do
  114. linux=`version_find_latest $list`
  115. echo "Found linux image: $linux" >&2
  116. basename=`basename $linux`
  117. dirname=`dirname $linux`
  118. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  119. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  120. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  121. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  122. initrd=
  123. for i in "initrd.img-${version}" "initrd-${version}.img" \
  124. "initrd-${version}" "initrd.img-${alt_version}" \
  125. "initrd-${alt_version}.img" "initrd-${alt_version}"; do
  126. if test -e "${dirname}/${i}" ; then
  127. initrd="$i"
  128. break
  129. fi
  130. done
  131. if test -n "${initrd}" ; then
  132. echo "Found initrd image: ${dirname}/${initrd}" >&2
  133. else
  134. # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
  135. linux_root_device_thisversion=${GRUB_DEVICE}
  136. fi
  137.  
  138. linux_entry "${OS}" "${version}" false \
  139. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  140. if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
  141. linux_entry "${OS}" "${version}" true \
  142. "single ${GRUB_CMDLINE_LINUX}"
  143. fi
  144.  
  145. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  146. done
Add Comment
Please, Sign In to add comment