void-minecraft-usb/opt/grub-config

105 lines
3.0 KiB
Plaintext
Raw Normal View History

2023-06-20 13:17:45 +02:00
#!/usr/bin/env bash
OS_NAME="Void Linux USB"
GRUB_PREFIX="/boot/efi/LOADER/grub"
CFG_CUSTOM_BEFORE="custom_before.cfg"
CFG_CUSTOM_AFTER="custom_after.cfg"
LINUX_CMDLINE="root=/dev/loop0 ro"
2023-06-20 13:17:45 +02:00
DEFAULT_LINUX=/boot/vmlinu?
if [ ! -f "$DEFAULT_LINUX" ]; then
# in cases where its a .gz or .xz or whatever
DEFAULT_LINUX=$(find /boot -type l -name "vmlinu*" 2>/dev/null | sort | head -n1)
fi
DEFAULT_LINUX="$(sed 's|^/boot/||' <<< "$DEFAULT_LINUX")"
2023-06-20 13:17:45 +02:00
DEFAULT_INITRAMFS=/boot/initramfs.img
if [ ! -f "$DEFAULT_INITRAMFS" ]; then
# hope to find anything named initramfs or initrd
DEFAULT_INITRAMFS=$(find /boot -type l -name "init*" 2>/dev/null | sort | head -n1)
fi
DEFAULT_INITRAMFS="$(sed 's|^/boot/||' <<< "$DEFAULT_INITRAMFS")"
2023-06-20 13:17:45 +02:00
function make_menuentry {
# $1 is the kernel path
# We dont want duplicate entries for /boot/vmlinuz symlink
2023-06-21 07:08:00 +02:00
if [ -L "$1" ]; then
2023-06-20 13:17:45 +02:00
return 0
fi
# exclude garbage globbing results
2023-06-21 07:08:00 +02:00
if [ ! -f "$1" ]; then
2023-06-20 13:17:45 +02:00
return 0
fi
LINUX="$(basename "$1")"
LINUX_VERSION="$(sed 's/^kernel//;s/^vm//;s/^linuz//;s/^linux//;s/^-//' <<< "$LINUX")"
if grep -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" >/dev/null 2>&1 <<< "$LINUX"; then
LINUX_VERSION="$(sed 's/[^.]*$//;s/.$//' <<< "$LINUX_VERSION")"
fi
INITRAMFS="$(basename "$(find /boot -name "init*$LINUX_VERSION*" 2>/dev/null | sort | head -n1)")"
# user output
echo " -> Found $LINUX (version $LINUX_VERSION, initramfs $INITRAMFS)"
# grub.cfg
echo "
menuentry 'Linux $LINUX_VERSION' {
echo 'Loading $LINUX...'
linux /$LINUX $LINUX_CMDLINE
echo 'Loading initial ramdisk...'
initrd /$INITRAMFS
}" >> "$GRUB_PREFIX/grub.cfg"
}
# user output
echo "Generating grub config..."
# grub.cfg
echo "# This file is auto-generated by $0.
# Changes will be overwritten automatically.
# If you want to add custom entries or other changes, add them to
# $GRUB_PREFIX/$CFG_CUSTOM_BEFORE or
# $GRUB_PREFIX/$CFG_CUSTOM_AFTER
search --fs-uuid --set=root $(blkid --output value --match-tag UUID "$(grep " /boot " /proc/mounts | sed -e 's/ .*//')")
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
timeout=5
if [ -f \${config_directory}/$CFG_CUSTOM_BEFORE ]; then
source \${config_directory}/$CFG_CUSTOM_BEFORE
elif [ -z \"\${config_directory}\" -a -f \$prefix/$CFG_CUSTOM_BEFORE ]; then
source \$prefix/$CFG_CUSTOM_BEFORE
fi
menuentry '$OS_NAME' {
echo 'Loading Linux...'
linux /$DEFAULT_LINUX $LINUX_CMDLINE
2023-06-20 13:17:45 +02:00
echo 'Loading initial ramdisk...'
initrd /$DEFAULT_INITRAMFS
2023-06-20 13:17:45 +02:00
}
submenu 'Choose kernel version...' {" > "$GRUB_PREFIX/grub.cfg"
for FILE in /boot/{vm,}linu{x,z}* /boot/kernel*; do
make_menuentry "$FILE"
done
# grub.cfg
echo "
}
if [ -f \${config_directory}/$CFG_CUSTOM_AFTER ]; then
source \${config_directory}/$CFG_CUSTOM_AFTER
elif [ -z \"\${config_directory}\" -a -f \$prefix/$CFG_CUSTOM_AFTER ]; then
source \$prefix/$CFG_CUSTOM_AFTER
fi" >> "$GRUB_PREFIX/grub.cfg"
# user output
echo "done"