09_parabola 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/usr/bin/env bash
  2. ##
  3. ## grub-mkconfig helper script specific to Parabola GNU/Linux-libre
  4. ## Contributed by "Keshav Amburay" <the ddoott ridikulus ddoott rat aatt geemmayil ddoott ccoomm>
  5. ## Rebranded for Parabola by "André Silva" <emulatorman@parabola.nu>
  6. ## Updated on 08 February 2014
  7. ##
  8. ## Script based on do_grub_config() function in Arch Archboot ISO Installer/Setup script
  9. ## Some parts taken from /etc/grub.d/10_linux script shipped by GRUB(2) upstream
  10. ##
  11. ## This script can be freely distributed and/or modified
  12. ## 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. ## This script 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. _FUNC_GRUB_FILE_PRESENT() {
  22. [[ -z "${GRUB_PLATFORM}" ]] && GRUB_PLATFORM="x86"
  23. if [[ "${GRUB_PLATFORM}" == "x86" ]]; then
  24. check="--is-x86-linux32"
  25. elif [[ "${GRUB_PLATFORM}" == "i386-xen-pae" ]]; then
  26. check="--is-i386-xen-pae-domu"
  27. elif [[ "${GRUB_PLATFORM}" == "x86_64-xen" ]]; then
  28. check="--is-x86_64-xen-domu"
  29. else
  30. check="--is-${GRUB_PLATFORM}-linux"
  31. fi
  32. case "${GRUB_PLATFORM}" in
  33. x86)
  34. list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do
  35. if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi
  36. done)" ;;
  37. *)
  38. list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do
  39. if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi
  40. done)" ;;
  41. esac
  42. }
  43. set -e
  44. prefix="/usr"
  45. exec_prefix="${prefix}"
  46. datarootdir="/usr/share"
  47. datadir="${datarootdir}"
  48. sysconfdir="/etc"
  49. . "${datarootdir}/grub/grub-mkconfig_lib"
  50. . "${sysconfdir}/default/grub"
  51. export TEXTDOMAIN="grub"
  52. export TEXTDOMAINDIR="${datarootdir}/locale"
  53. CLASS="--class parabola --class gnu-linux --class gnu --class os"
  54. [[ "${grub_file}" != "" ]] && _FUNC_GRUB_FILE_PRESENT
  55. BOOT_PART_FS_UUID="$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)"
  56. BOOT_PART_HINTS_STRING="$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null || true)"
  57. BOOT_PART_FS="$(${grub_probe} --target="fs" "/boot" 2>/dev/null)"
  58. ROOT_PART_GRUB_DEVICE="$(${grub_probe} --target=device / || true)"
  59. ROOT_PART_FS="$(${grub_probe} --device ${ROOT_PART_GRUB_DEVICE} --target=fs 2> /dev/null || echo "unknown")"
  60. if [[ "${GRUB_LINUX_ROOT_DEVICE}" == "" ]]; then
  61. case "${ROOT_PART_FS}" in
  62. btrfs)
  63. rootsubvol="$(make_system_path_relative_to_its_root /)"
  64. rootsubvol="${rootsubvol#/}"
  65. if [[ "${rootsubvol}" != "" ]]; then
  66. GRUB_LINUX_ROOT_DEVICE="subvol=${rootsubvol}"
  67. fi
  68. ;;
  69. zfs)
  70. rpool="$(${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true)"
  71. bootfs="$(make_system_path_relative_to_its_root / | sed -e "s,@$,,")"
  72. GRUB_LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
  73. ;;
  74. esac
  75. if [[ "${GRUB_DEVICE_UUID}" == "" ]] || \
  76. [[ "${GRUB_DISABLE_LINUX_UUID}" == "true" ]] || \
  77. [[ ! -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ]] || \
  78. uses_abstraction "${GRUB_DEVICE}" lvm ; then
  79. GRUB_LINUX_ROOT_DEVICE="${GRUB_DEVICE}"
  80. else
  81. GRUB_LINUX_ROOT_DEVICE="UUID=${GRUB_DEVICE_UUID}"
  82. fi
  83. fi
  84. [[ "${GRUB_LINUX_PARAMS}" == "" ]] && GRUB_LINUX_PARAMS="${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
  85. for _KERNEL_ in ${list} ; do
  86. echo "Found linux image: ${_KERNEL_}" >&2
  87. basename="$(basename "${_KERNEL_}")"
  88. dirname="$(dirname "${_KERNEL_}")"
  89. REAL_DIR="$(make_system_path_relative_to_its_root "${dirname}")"
  90. _KERNEL_FILE_="$(echo ${_KERNEL_} | sed 's,/boot/,,g')"
  91. _KERNEL_PKG_="pkg-$(echo ${_KERNEL_FILE_} | sed 's,vmlinuz-,,g')"
  92. _INITRAMFS_="${_KERNEL_FILE_/vmlinuz-/initramfs-}.img"
  93. if [[ -e "/boot/${_INITRAMFS_}" ]]; then
  94. echo "Found initramfs image: /boot/${_INITRAMFS_}" >&2
  95. cat << EOF
  96. menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel" ${CLASS} {
  97. $(save_default_entry)
  98. if [ x\$feature_all_video_module = xy ]; then
  99. insmod all_video
  100. fi
  101. set gfxpayload=keep
  102. insmod ${BOOT_PART_FS}
  103. if [ x\$feature_platform_search_hint = xy ]; then
  104. search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
  105. else
  106. search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID}
  107. fi
  108. echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
  109. linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
  110. echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel initramfs ...'
  111. initrd ${REAL_DIR}/${_INITRAMFS_}
  112. }
  113. EOF
  114. fi
  115. _INITRAMFS_FALLBACK_="${_KERNEL_FILE_/vmlinuz-/initramfs-}-fallback.img"
  116. if [[ -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then
  117. echo "Found fallback initramfs image: /boot/${_INITRAMFS_FALLBACK_}" >&2
  118. cat << EOF
  119. menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel (fallback initramfs)" ${CLASS} {
  120. $(save_default_entry)
  121. if [ x\$feature_all_video_module = xy ]; then
  122. insmod all_video
  123. fi
  124. set gfxpayload=keep
  125. insmod ${BOOT_PART_FS}
  126. if [ x\$feature_platform_search_hint = xy ]; then
  127. search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
  128. else
  129. search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID}
  130. fi
  131. echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
  132. linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
  133. echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel fallback initramfs ...'
  134. initrd ${REAL_DIR}/${_INITRAMFS_FALLBACK_}
  135. }
  136. EOF
  137. fi
  138. if [[ ! -e "/boot/${_INITRAMFS_}" ]] && [[ ! -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then
  139. cat << EOF
  140. menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel (no initramfs)" ${CLASS} {
  141. $(save_default_entry)
  142. if [ x\$feature_all_video_module = xy ]; then
  143. insmod all_video
  144. fi
  145. set gfxpayload=keep
  146. insmod ${BOOT_PART_FS}
  147. if [ x\$feature_platform_search_hint = xy ]; then
  148. search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
  149. else
  150. search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID}
  151. fi
  152. echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
  153. linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
  154. }
  155. EOF
  156. fi
  157. done