Advertisement
Minty95

linux.bak

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