Advertisement
Guest User

10_lupin

a guest
Jul 28th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 KB | None | 0 0
  1. #! /bin/sh
  2. set -e
  3.  
  4. # grub-mkconfig helper script for lupin. Some of this is based on 10_linux,
  5. # but with irrelevant bits removed and the rest extended to cope with
  6. # loopback mounts.
  7. #
  8. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  9. # Copyright (C) 2009 Canonical Ltd.
  10. #
  11. # GRUB is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # GRUB is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  23.  
  24. prefix="/usr"
  25. exec_prefix="${prefix}"
  26. data otdir="${prefix}/share"
  27.  
  28. . "${datarootdir}/grub/grub-mkconfig_lib"
  29.  
  30. export TEXTDOMAIN=grub
  31. export TEXTDOMAINDIR="${datarootdir}/locale"
  32.  
  33. CLASS="--class gnu-linux --class gnu --class os"
  34.  
  35. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  36. OS=GNU/Linux
  37. else
  38. OS="${GRUB_DISTRIBUTOR}"
  39. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
  40. fi
  41.  
  42. case ${GRUB_DEVICE} in
  43. /dev/loop/*|/dev/loop[0-9])
  44. loop_file=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  45. ;;
  46. esac
  47.  
  48. # Is the root filesystem loop-mounted from a file on another filesystem?
  49. if [ "x${loop_file}" = x ] || [ ! -f "${loop_file}" ]; then
  50. exit 0
  51. fi
  52. dev_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $1";"$2 }' /proc/mounts | tail -n1)"
  53. host_device="${dev_mountpoint%;*}"
  54. host_mountpoint="${dev_mountpoint#*;}"
  55. if [ "x${host_device}" = x ]; then
  56. exit 0
  57. fi
  58. loop_file_relative="${loop_file#$host_mountpoint}"
  59.  
  60. # Device containing the host filesystem.
  61. host_device_uuid="`${grub_probe} --device "${host_device}" --target=fs_uuid 2> /dev/null`" || true
  62.  
  63. if [ "x${host_device_uuid}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  64. || ! test -e "/dev/disk/by-uuid/${host_device_uuid}" \
  65. || [ "`${grub_probe} -t abstraction --device ${host_device} | sed -e 's,.*\(lvm\).*,\1,'`" = "lvm" ] ; then
  66. LINUX_HOST_DEVICE=${host_device}
  67. else
  68. LINUX_HOST_DEVICE=UUID=${host_device_uuid}
  69. fi
  70.  
  71. GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
  72.  
  73. if [ x"$GRUBFS" = x ]; then
  74. GRUBFS="$(stat -f --printf=%T / || true)"
  75. fi
  76.  
  77. case x"$GRUBFS" in
  78. xbtrfs)
  79. rootsubvol="`make_system_path_relative_to_its_root /`"
  80. rootsubvol="${rootsubvol#/}"
  81. if [ "x${rootsubvol}" != x ]; then
  82. GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  83. fi;;
  84. xzfs)
  85. rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
  86. bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
  87. LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  88. ;;
  89. esac
  90.  
  91. title_correction_code=
  92.  
  93. for word in $GRUB_CMDLINE_LINUX_DEFAULT; do
  94. if [ "$word" = splash ]; then
  95. GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT \$vt_handoff"
  96. fi
  97. done
  98.  
  99. # add crashkernel option if we have the required tools
  100. if [ -x "/usr/bin/makedumpfile" ] && [ -x "/sbin/kexec" ]; then
  101. GRUB_CMDLINE_EXTRA="$GRUB_CMDLINE_EXTRA crashkernel=384M-2G:64M,2G-:128M"
  102. fi
  103.  
  104. lupin_entry ()
  105. {
  106. os="$1"
  107. version="$2"
  108. type="$3"
  109. args="$4"
  110.  
  111. if [ -z "$boot_device_id" ]; then
  112. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  113. fi
  114. if [ x$type != xsimple ] ; then
  115. case $type in
  116. recovery)
  117. title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
  118. *)
  119. title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
  120. esac
  121. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  122. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  123. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  124. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  125. 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")"
  126. fi
  127. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  128. else
  129. echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  130. fi
  131. if [ x$type != xrecovery ] ; then
  132. save_default_entry | sed -e "s/^/\t/"
  133.  
  134. echo " gfxmode \$linux_gfx_mode" | sed "s/^/$submenu_indentation/"
  135. fi
  136.  
  137. echo " insmod gzio" | sed "s/^/$submenu_indentation/"
  138.  
  139. if [ -z "${prepare_boot_cache}" ]; then
  140. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  141. fi
  142. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  143. if [ x$type != xsimple ]; then
  144. message="$(gettext_printf "Loading Linux %s ..." ${version})"
  145. sed "s/^/$submenu_indentation/" << EOF
  146. echo '$(echo "$message" | grub_quote)'
  147. EOF
  148. fi
  149. sed "s/^/$submenu_indentation/" << EOF
  150. linux ${rel_dirname}/${basename} root=${LINUX_HOST_DEVICE} loop=${loop_file_relative} ro ${args}
  151. EOF
  152. if test -n "${initrd}" ; then
  153. # TRANSLATORS: ramdisk isn't identifier. Should be translated.
  154. if [ x$type != xsimple ]; then
  155. message="$(gettext_printf "Loading initial ramdisk ...")"
  156. sed "s/^/$submenu_indentation/" << EOF
  157. echo '$(echo "$message" | grub_quote)'
  158. EOF
  159. fi
  160. sed "s/^/$submenu_indentation/" << EOF
  161. initrd ${rel_dirname}/${initrd}
  162. EOF
  163. fi
  164. sed "s/^/$submenu_indentation/" << EOF
  165. }
  166. EOF
  167. }
  168.  
  169. machine=`uname -m`
  170. case "x$machine" in
  171. xi?86 | xx86_64)
  172. list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
  173. if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  174. done` ;;
  175. *)
  176. list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
  177. if grub_file_is_not_garbage "$i" ; then echo -n "$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. boot_device_id=
  191. title_correction_code=
  192.  
  193. cat << 'EOF'
  194. function gfxmode {
  195. set gfxpayload="${1}"
  196. if [ "${1}" = "keep" ]; then
  197. set vt_handoff=vt.handoff=7
  198. else
  199. set vt_handoff=
  200. fi
  201. }
  202. EOF
  203.  
  204. # Use ELILO's generic "efifb" when it's known to be available.
  205. # FIXME: We need an interface to select vesafb in case efifb can't be used.
  206. if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then
  207. echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
  208. else
  209. cat << EOF
  210. if [ "\${recordfail}" != 1 ]; then
  211. if [ -e \${prefix}/gfxblacklist.txt ]; then
  212. if hwmatch \${prefix}/gfxblacklist.txt 3; then
  213. if [ \${match} = 0 ]; then
  214. set linux_gfx_mode=keep
  215. else
  216. set linux_gfx_mode=text
  217. fi
  218. else
  219. set linux_gfx_mode=text
  220. fi
  221. else
  222. set linux_gfx_mode=keep
  223. fi
  224. else
  225. set linux_gfx_mode=text
  226. fi
  227. EOF
  228. fi
  229. cat << EOF
  230. export linux_gfx_mode
  231. if [ "\${linux_gfx_mode}" != "text" ]; then load_video; fi
  232. EOF
  233.  
  234. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  235. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  236. submenu_indentation=""
  237.  
  238. is_first_entry=true
  239. while [ "x$list" != "x" ] ; do
  240. linux=`version_find_latest $list`
  241. gettext_printf "Found linux image: %s\n" "$linux" >&2
  242. basename=`basename $linux`
  243. dirname=`dirname $linux`
  244. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  245. version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  246. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  247. linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  248.  
  249. initrd=
  250. for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
  251. "initrd-${version}" "initramfs-${version}.img" \
  252. "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
  253. "initrd-${alt_version}" "initramfs-${alt_version}.img" \
  254. "initramfs-genkernel-${version}" \
  255. "initramfs-genkernel-${alt_version}" \
  256. "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
  257. "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
  258. if test -e "${dirname}/${i}" ; then
  259. initrd="$i"
  260. break
  261. fi
  262. done
  263.  
  264. config=
  265. for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  266. if test -e "${i}" ; then
  267. config="${i}"
  268. break
  269. fi
  270. done
  271.  
  272. initramfs=
  273. if test -n "${config}" ; then
  274. initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
  275. fi
  276.  
  277. if test -n "${initrd}" ; then
  278. gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
  279. else
  280. # None of this can work without an initrd, so don't even bother.
  281. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  282. continue
  283. fi
  284.  
  285. if [ "x$is_first_entry" = xtrue ]; then
  286. lupin_entry "${OS}" "${version}" simple \
  287. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  288.  
  289. submenu_indentation="\t"
  290.  
  291. if [ -z "$boot_device_id" ]; then
  292. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  293. fi
  294. # TRANSLATORS: %s is replaced with an OS name
  295. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
  296. fi
  297.  
  298. lupin_entry "${OS}" "${version}" advanced \
  299. "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  300. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  301. if [ -x /lib/recovery-mode/recovery-menu ]; then
  302. lupin_entry "${OS}" "${version}" recovery \
  303. "recovery nomodeset ${GRUB_CMDLINE_LINUX}"
  304. else
  305. lupin_entry "${OS}" "${version}" recovery \
  306. "single nomodeset ${GRUB_CMDLINE_LINUX}"
  307. fi
  308. fi
  309.  
  310. list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  311. is_first_entry=false
  312. done
  313.  
  314. # If at least one kernel was found, then we need to
  315. # add a closing '}' for the submenu command.
  316. if [ x"$is_first_entry" != xtrue ]; then
  317. echo '}'
  318. fi
  319.  
  320. echo "$title_correction_code"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement