diff --git a/config/grub/config/grub.cfg b/config/grub/config/grub.cfg index 648116198ba9d8ea231ad6c481c2b2e6b78e6e78..7935560cb468dca2cc7e1e4434321c53f28720b3 100644 --- a/config/grub/config/grub.cfg +++ b/config/grub/config/grub.cfg @@ -46,38 +46,57 @@ set medianums="20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0" # Loads into a variable all the medias from * function mediadetect { - unset media_devlist - set media_devlist=* + unset media_devlist + set media_devlist=* } -# Fills a variable containing possible partition list from a specified and previously detected media kind -function enum_tgt { - unset tgt_medias - for media_item in ${media_devlist}; do +# Fills a variable containing possible partition list from a specified and previously detected physical media kind +function list_pmedia { + unset tgt_medias + for media_item in ${media_devlist}; do for device_kind in ${1}; do for num in $medianums; do # If media number is an existent detected media - if [ $media_item == "($device_kind$num)" ]; then + if [ $media_item == "($device_kind$num)" ]; then # Add raw media tgt_medias="${tgt_medias} (${device_kind}${num})" # Add every possible partition for part in ${partnums}; do tgt_medias="${tgt_medias} (${device_kind}${num},${part})" done - fi + fi done done - done + done + echo $tgt_medias +} + +set lvmnames="crypt-bootvol crypt-rootvol crypt-boot crypt-root grubcrypt-bootvol grubcrypt-rootvol" + +# Fills a variable containing possible partition list from a specified and previously detected logic media kind +function list_lmedia { + unset tgt_medias + for media_item in $media_devlist; do + for device_kind in ${1}; do + for num in ${lvmnames}; do + if [ $media_item == "($device_kind/$num)" ]; then + tgt_medias="${tgt_medias} (${device_kind}/${num})" + fi + done + done + done echo $tgt_medias } mediadetect menuentry "Media detection test" { -enum_tgt ata -enum_tgt ahci -set pager=1 -read +cryptomount -a -p assword +#list_pmedia ata +list_lmedia lvm +for i in ${tgt_medias}; do + grub_create_menu ${i} +done } # FIXME Make an automatic override for BTRFS directories instead of copypasting with a "@/" in front of every element @@ -87,6 +106,28 @@ set grub_dirs="boot grub grub2 boot/grub boot/grub2 @/boot @/grub @/grub2 @/boot # Default list of GRUB possible config files prefixes set grub_conf_names="'' osboot_ autoboot_ libreboot_ coreboot_" +function grub_create_menu { + echo "[GRUB] Looking on ${1}" + set root="${1}" + # The @/... entries are for cases where the BTRFS filesystem is being used + for dir in ${grub_dirs}; do + # In order to save time, we do not attempt anything on non existing directory. + if [ -d / ]; then + if [ -d /"${dir}"/ ]; then + for name in '' ${grub_conf_names}; do + if [ -f /"${dir}"/"${name}"grub.cfg ]; then + menuentry "${1} load GRUB" ${1} /"${dir}"/"${name}"grub.cfg { + set root="${2}" + unset superusers + configfile ${3} + } + fi + done + fi + fi + done +} + function try_user_grub_config { set root="${1}" for dir in ${grub_dirs}; do