grub-bios-install.sh (1669B)
- #!/bin/sh
- # grub-install replacement for BIOS systems, assumes an encrypted /boot
- # Copyright ⓒ 2024 Haelwenn (lanodan) Monnier <contact+grub-nomagic-scripts@hacktivis.me>
- # SPDX-License-Identifier: MIT
- die() {
- echo "$@"
- exit 1
- }
- load_cfg() {
- if [ -e "$1" ] ; then
- . "$1"
- else
- die "grub-bios-install: Error, couldn't load configuration, file not found: $1"
- fi
- }
- command -v lsblk || die 'grub-bios-install: Error, command not found: lsblk'
- load_cfg ~/.config/grub-nomagic/env
- rsync -rav --exclude '*.module' /usr/lib/grub/i386-pc /boot/grub/ || die "grub-bios-install: Failed to copy grub modules from current installation"
- test -z "${DISK}" && die '$DISK needs to be set to a disk blockdevice, for example: /dev/sda'
- test -z "${ROOT_BLOCK}" && die '$ROOT_BLOCK needs to be set to your root filesystem blockdevice, for example: /dev/sda2'
- 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'
- test -z "${GRUB_CORE_MODULES}" && die '$GRUB_CORE_MODULES needs to be set to the grub modules required to decrypt /boot'
- set -x -e
- : ${ROOT_UUID:=$(lsblk -n -o uuid ${ROOT_BLOCK} | head -1)}
- : ${GRUB_PREFIX:=(cryptouuid/${ROOT_UUID//-/}${GRUB_ROOT}/grub/}
- echo "cryptomount -u ${ROOT_UUID//-/}" > /boot/grub/i386-pc/load.cfg
- #echo 'cryptomount hd0,msdos2' > /boot/grub/i386-pc/load.cfg
- grub-mkimage \
- --format 'i386-pc' \
- --output '/boot/grub/i386-pc/core.img' \
- --config '/boot/grub/i386-pc/load.cfg' \
- --prefix "${GRUB_PREFIX}" \
- ${GRUB_CORE_MODULES}
- grub-bios-setup \
- --directory='/boot/grub/i386-pc' \
- --device-map='/boot/grub/device.map' \
- "${DISK}"