Guest User

grub linux

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