Guest User

grubd10

a guest
Aug 28th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.96 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="/usr/share"
  23. quiet_boot="1"
  24.  
  25. . "$pkgdatadir/grub-mkconfig_lib"
  26.  
  27. export TEXTDOMAIN=grub
  28. export TEXTDOMAINDIR="${datarootdir}/locale"
  29.  
  30. CLASS="--class gnu-linux --class gnu --class os"
  31.  
  32. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  33. OS=Linux
  34. else
  35. OS="${GRUB_DISTRIBUTOR} Linux"
  36. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
  37. fi
  38.  
  39. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  40. # the initrds that Linux uses don't like that.
  41. case ${GRUB_DEVICE} in
  42. /dev/loop/*|/dev/loop[0-9])
  43. GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  44. ;;
  45. esac
  46.  
  47. # Default to disabling partition uuid support to maintian compatibility with
  48. # older kernels.
  49. GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
  50.  
  51. # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
  52. # and mounting btrfs requires user space scanning, so force UUID in this case.
  53. if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
  54. || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  55. && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
  56. || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  57. && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
  58. || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
  59. LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  60. elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
  61. || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
  62. LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
  63. else
  64. LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  65. fi
  66.  
  67. case x"$GRUB_FS" in
  68. xbtrfs)
  69. rootsubvol="`make_system_path_relative_to_its_root /`"
  70. rootsubvol="${rootsubvol#/}"
  71. if [ "x${rootsubvol}" != x ]; then
  72. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  73. fi;;
  74. xzfs)
  75. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  76. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  77. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
  78. ;;
  79. esac
  80.  
  81. title_correction_code=
  82.  
  83. linux_entry ()
  84. {
  85. os="$1"
  86. version="$2"
  87. type="$3"
  88. args="$4"
  89.  
  90. if [ -z "$boot_device_id" ]; then
  91. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  92. fi
  93. if [ x$type != xsimple ] ; then
  94. case $type in
  95. recovery)
  96. title="$(gettext_printf "%s (Kernel: %s - recovery mode)" "${os}" "${version}")" ;;
  97. fallback)
  98. title="$(gettext_printf "%s (Kernel: %s - fallback initramfs)" "${os}" "${version}")" ;;
  99. *)
  100. title="$(gettext_printf "%s (Kernel: %s)" "${os}" "${version}")" ;;
  101. esac
  102. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  103. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  104. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  105. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  106. 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")"
  107. fi
  108. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  109. else
  110. echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  111. fi
  112. if [ x$type != xrecovery ] && [ x$type != xfallback ] ; then
  113. save_default_entry | grub_add_tab
  114. fi
  115.  
  116. # Use ELILO's generic "efifb" when it's known to be available.
  117. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  118. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
  119. echo " load_video" | sed "s/^/$submenu_indentation/"
  120. if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
  121. && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
  122. echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
  123. fi
  124. else
  125. if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
  126. echo " load_video" | sed "s/^/$submenu_indentation/"
  127. fi
  128. echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
  129. fi
  130.  
  131.  
  132. echo " outb 0x728 1" | sed "s/^/$submenu_indentation/"
  133. echo " outb 0x710 2" | sed "s/^/$submenu_indentation/"
  134. echo " outb 0x740 2" | sed "s/^/$submenu_indentation/"
  135. echo " outb 0x750 0" | sed "s/^/$submenu_indentation/"
  136. echo " insmod gzio" | sed "s/^/$submenu_indentation/"
  137.  
  138. if [ x$dirname = x/ ]; then
  139. if [ -z "${prepare_root_cache}" ]; then
  140. prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
  141. fi
  142. printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
  143. else
  144. if [ -z "${prepare_boot_cache}" ]; then
  145. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  146. fi
  147. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  148. fi
  149.  
  150. if [ x"$quiet_boot" = x0 ]; then
  151. message="$(gettext_printf "Loading Linux %s ..." "${version}")"
  152. sed "s/^/$submenu_indentation/" << EOF
  153. echo '$(echo "$message" | grub_quote)'
  154.  
  155. fi
  156. sed "s/^/$submenu_indentation/" << EOF
  157. linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args}
  158. EOF
  159. if test -n "${initrd}" ; then
  160. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  161. message="$(gettext_printf "Loading initial ramdisk ...")"
  162. initrd_path=
  163. for i in ${initrd}; do
  164. initrd_path="${initrd_path} ${rel_dirname}/${i}"
  165. done
  166. if [ x"$quiet_boot" = x0 ]; then
  167. sed "s/^/$submenu_indentation/" << EOF
  168. echo '$(echo "$message" | grub_quote)'
  169. EOF
  170. fi
  171. sed "s/^/$submenu_indentation/" << EOF
  172. initrd $(echo $initrd_path)
  173. EOF
  174. fi
  175. sed "s/^/$submenu_indentation/" << EOF
  176. }
  177. EOF
  178.  
  179.  
  180. machine=`uname -m`
  181. case "x$machine" in
  182. xi?86 | xx86_64)
  183. list=
  184. for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  185. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  186. done ;;
  187. *)
  188. list=
  189. for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  190. if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
  191. done ;;
  192. esac
  193.  
  194. case "$machine" in
  195. i?86) GENKERNEL_ARCH="x86" ;;
  196. mips|mips64) GENKERNEL_ARCH="mips" ;;
  197. mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
  198. arm*) GENKERNEL_ARCH="arm" ;;
  199. *) GENKERNEL_ARCH="$machine" ;;
  200. esac
  201.  
  202. prepare_boot_cache=
  203. prepare_root_cache=
  204. boot_device_id=
  205. title_correction_code=
  206.  
  207. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  208. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  209. submenu_indentation=""
  210.  
  211. is_top_level=true
  212. while [ "x$list" != "x" ] ; do
  213. linux=`version_find_latest $list`
  214. gettext_printf "Found linux image: %s\n" "$linux" >&2
  215. basename=`basename $linux`
  216. dirname=`dirname $linux`
  217. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  218. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  219. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  220. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  221.  
  222. if test -e "/etc/manjaro-release" ; then
  223. kbasename="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g'`"
  224. if test -e "${dirname}/${kbasename}.kver" ; then
  225. version="$(cat ${dirname}/${kbasename}.kver)"
  226. fi
  227. kbasename2="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g'`"
  228. if test -e "${dirname}/${kbasename2}.kver" ; then
  229. version="$(cat ${dirname}/${kbasename2}.kver)"
  230. fi
  231. kbasename3="`echo "${basename}" | sed -e 's,vmlinuz-,linux,g' | sed -e 's,\.,,g'`"
  232. if test -e "${dirname}/${kbasename3}.kver" ; then
  233. version="$(cat ${dirname}/${kbasename3}.kver)"
  234. fi
  235. kbasename4="`echo "${basename}" | sed -e 's,vmlinuz-,linux-,g' | sed -e 's,\.,,g'`"
  236. if test -e "${dirname}/${kbasename4}.kver" ; then
  237. version="$(cat ${dirname}/${kbasename4}.kver)"
  238. fi
  239. fi
  240.  
  241. initrd_early=
  242. for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
  243. ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
  244. if test -e "${dirname}/${i}" ; then
  245. initrd_early="${initrd_early} ${i}"
  246. fi
  247. done
  248.  
  249. initrd_real=
  250. initramfs_manjaro="`echo "${basename}" | sed -e 's,vmlinuz,initramfs,g'`"
  251. for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  252. "initrd-${version}" "initramfs-${version}.img" \
  253. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  254. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  255. "initramfs-genkernel-${version}" \
  256. "initramfs-genkernel-${alt_version}" \
  257. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  258. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" \
  259. "${initramfs_manjaro}.img" ; do
  260. if test -e "${dirname}/${i}" ; then
  261. initrd_real="${i}"
  262. break
  263. fi
  264. done
  265.  
  266. initrd=
  267. if test -n "${initrd_early}" || test -n "${initrd_real}"; then
  268. initrd="${initrd_early} ${initrd_real}"
  269.  
  270. initrd_display=
  271. for i in ${initrd}; do
  272. initrd_display="${initrd_display} ${dirname}/${i}"
  273. done
  274. gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
  275. fi
  276.  
  277. config=
  278. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  279. if test -e "${i}" ; then
  280. config="${i}"
  281. break
  282. fi
  283. done
  284.  
  285. initramfs=
  286. if test -n "${config}" ; then
  287. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  288. fi
  289.  
  290. if test -z "${initramfs}" && test -z "${initrd_real}" ; then
  291. # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
  292. # no initrd or builtin initramfs, it can't work here.
  293. if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
  294. || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
  295.  
  296. linux_root_device_thisversion=${GRUB_DEVICE}
  297. else
  298. linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
  299. fi
  300. fi
  301.  
  302. # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
  303. # mentioned in the documentation that has to be set to 'y' instead of 'true' to
  304. # enable it. This caused a lot of confusion to users that set the option to 'y',
  305. # 'yes' or 'true'. This was fixed but all of these values must be supported now.
  306. if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then
  307. GRUB_DISABLE_SUBMENU="true"
  308. fi
  309.  
  310. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
  311. linux_entry "${OS}" "${version}" simple \
  312. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  313.  
  314. submenu_indentation="$grub_tab"
  315.  
  316. if [ -z "$boot_device_id" ]; then
  317. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  318. fi
  319. # TRANSLATORS: %s is replaced with an OS name
  320. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  321. is_top_level=false
  322. fi
  323.  
  324. linux_entry "${OS}" "${version}" advanced \
  325. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  326.  
  327. for i in "${initramfs_manjaro}-fallback.img" "initramfs-${version}-fallback.img" ; do
  328. if test -e "${dirname}/${i}" ; then
  329. initrd="${i}"
  330. gettext_printf "Found initrd fallback image: %s\n" "${dirname}/${initrd}" >&2
  331. linux_entry "${OS}" "${version}" fallback \
  332. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  333. break
  334. fi
  335. done
  336.  
  337. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  338. linux_entry "${OS}" "${version}" recovery \
  339. "single ${GRUB_CMDLINE_LINUX}"
  340. fi
  341.  
  342. list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
  343. done
  344.  
  345. # If at least one kernel was found, then we need to
  346. # add a closing '}' for the submenu command.
  347. if [ x"$is_top_level" != xtrue ]; then
  348. echo '}'
  349. fi
  350.  
  351. echo "$title_correction_code"
  352. done
Add Comment
Please, Sign In to add comment