Advertisement
Guest User

10_linux

a guest
Mar 25th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 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="${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} GNU/Linux"
  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. linux_entry ()
  69. {
  70. os="$1"
  71. version="$2"
  72. recovery="$3"
  73. args="$4"
  74. if ${recovery} ; then
  75. title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
  76. else
  77. title="$(gettext_quoted "%s, with Linux %s")"
  78. fi
  79. printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  80. if ! ${recovery} ; then
  81. save_default_entry | sed -e "s/^/\t/"
  82. fi
  83.  
  84. # Use ELILO's generic "efifb" when it's known to be available.
  85. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  86. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  87. cat << EOF
  88. load_video
  89. EOF
  90. else
  91. if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  92. cat << EOF
  93. load_video
  94. EOF
  95. fi
  96. cat << EOF
  97. set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
  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. message="$(gettext_printf "Loading Linux %s ..." ${version})"
  117. cat << EOF
  118. echo '$message'
  119. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  120. EOF
  121. if test -n "${initrd}" ; then
  122. message="$(gettext_printf "Loading initial ramdisk ...")"
  123. cat << EOF
  124. echo '$message'
  125. initrd ${rel_dirname}/${initrd}
  126. EOF
  127. fi
  128. cat << EOF
  129. }
  130. EOF
  131. }
  132.  
  133. case x`uname -m` in
  134. xi?86 | xx86_64)
  135. list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  136. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  137. done` ;;
  138. *)
  139. list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  140. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  141. done` ;;
  142. esac
  143.  
  144. prepare_boot_cache=
  145. prepare_root_cache=
  146.  
  147. while [ "x$list" != "x" ] ; do
  148. linux=`version_find_latest $list`
  149. echo "Found linux image: $linux" >&2
  150. basename=`basename $linux`
  151. dirname=`dirname $linux`
  152. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  153. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  154. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  155. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  156.  
  157. initrd=
  158. for i in "initrd.img-${version}" "initrd-${version}.img" \
  159. "initrd-${version}" "initramfs-${version}.img" \
  160. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  161. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  162. "initramfs-genkernel-${version}" \
  163. "initramfs-genkernel-${alt_version}"; do
  164. if test -e "${dirname}/${i}" ; then
  165. initrd="$i"
  166. break
  167. fi
  168. done
  169.  
  170. config=
  171. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  172. if test -e "${i}" ; then
  173. config="${i}"
  174. break
  175. fi
  176. done
  177.  
  178. initramfs=
  179. if test -n "${config}" ; then
  180. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  181. fi
  182.  
  183. if test -n "${initrd}" ; then
  184. echo "Found initrd image: ${dirname}/${initrd}" >&2
  185. elif test -z "${initramfs}" ; then
  186. # "UUID=" magic is parsed by initrd or initramfs. Since there's
  187. # no initrd or builtin initramfs, it can't work here.
  188. linux_root_device_thisversion=${GRUB_DEVICE}
  189. fi
  190.  
  191. linux_entry "${OS}" "${version}" false \
  192. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  193. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  194. linux_entry "${OS}" "${version}" true \
  195. "single ${GRUB_CMDLINE_LINUX}"
  196. fi
  197.  
  198. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  199. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement