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-bios-install.sh (1669B)


  1. #!/bin/sh
  2. # grub-install replacement for BIOS systems, assumes an encrypted /boot
  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. command -v lsblk || die 'grub-bios-install: Error, command not found: lsblk'
  17. load_cfg ~/.config/grub-nomagic/env
  18. rsync -rav --exclude '*.module' /usr/lib/grub/i386-pc /boot/grub/ || die "grub-bios-install: Failed to copy grub modules from current installation"
  19. test -z "${DISK}" && die '$DISK needs to be set to a disk blockdevice, for example: /dev/sda'
  20. test -z "${ROOT_BLOCK}" && die '$ROOT_BLOCK needs to be set to your root filesystem blockdevice, for example: /dev/sda2'
  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. test -z "${GRUB_CORE_MODULES}" && die '$GRUB_CORE_MODULES needs to be set to the grub modules required to decrypt /boot'
  23. set -x -e
  24. : ${ROOT_UUID:=$(lsblk -n -o uuid ${ROOT_BLOCK} | head -1)}
  25. : ${GRUB_PREFIX:=(cryptouuid/${ROOT_UUID//-/}${GRUB_ROOT}/grub/}
  26. echo "cryptomount -u ${ROOT_UUID//-/}" > /boot/grub/i386-pc/load.cfg
  27. #echo 'cryptomount hd0,msdos2' > /boot/grub/i386-pc/load.cfg
  28. grub-mkimage \
  29. --format 'i386-pc' \
  30. --output '/boot/grub/i386-pc/core.img' \
  31. --config '/boot/grub/i386-pc/load.cfg' \
  32. --prefix "${GRUB_PREFIX}" \
  33. ${GRUB_CORE_MODULES}
  34. grub-bios-setup \
  35. --directory='/boot/grub/i386-pc' \
  36. --device-map='/boot/grub/device.map' \
  37. "${DISK}"