logo

grub-nomagic-scripts

Automagic-free replacement scripts for GRUB grub-mkconfig and grub-install.git clone https://hacktivis.me/git/grub-nomagic-scripts.git

grub-cfg.sh (1497B)


  1. #!/bin/sh
  2. # /boot/grub/grub.cfg config manager
  3. # Copyright ⓒ 2024 Haelwenn (lanodan) Monnier <contact+grub-nomagic-scripts@hacktivis.me>
  4. # SPDX-License-Identifier: MIT
  5. die() {
  6. echo "$@"
  7. exit 1
  8. }
  9. load_cfg() {
  10. if [ -e "$1" ] ; then
  11. . "$1"
  12. else
  13. die "grub-bios-install: Error, couldn't load configuration, file not found: $1"
  14. fi
  15. }
  16. set -e
  17. load_cfg ~/.config/grub-nomagic/env
  18. cd /boot
  19. test -z "${CMDLINE}" && die '$CMDLINE needs to be set to the kernel cmdline, for example the root variable for the kernel'
  20. test -z "${MICROCODE}" && die '$MICROCODE needs to be set, for example: amc-uc.img'
  21. test -z "${GRUB_ROOT}" && die '$GRUB_ROOT needs to be set to the boottime grub root relative to the boot disk, for example: /ROOT/gentoo/@/boot'
  22. cp grub/grub.cfg.head grub/grub.cfg || die 'grub/grub.cfg.head is required for initial configuration (such as modules and variables)'
  23. if test ! -f "/boot/${MICROCODE}"
  24. then
  25. echo "/boot/${MICROCODE}: File not found (microcode)"
  26. exit 1
  27. fi
  28. : ${INITRD_EXT:=.img}
  29. for kernel in $(ls -t vmlinuz*)
  30. do
  31. version="${kernel#vmlinuz}"
  32. : ${INITRD:=initramfs${version}${INITRD_EXT}}
  33. if test -e "${INITRD}"
  34. then
  35. echo "${kernel} + ${MICROCODE} + ${INITRD}"
  36. else
  37. echo "${kernel} ignored"
  38. continue
  39. fi
  40. cat >>grub/grub.cfg <<EOF
  41. menuentry 'Linux${version:- Default}' {
  42. linux ${grub_root}/${kernel} ${CMDLINE}
  43. initrd ${grub_root}/${MICROCODE} ${grub_root}/${INITRD}
  44. }
  45. EOF
  46. done
  47. test -f grub/grub.cfg.tail && cat grub/grub.cfg.tail >> grub/grub.cfg