diff --git a/mbusb.cfg b/mbusb.cfg index 346df545..579b4a1d 100644 --- a/mbusb.cfg +++ b/mbusb.cfg @@ -1,7 +1,9 @@ # Partition holding files +regexp --set=rootdisk "^(.*),.*" "$root" +regexp --set=rootpartnum "^.*,.*([0-9]+)" "$root" probe -u $root --set=rootuuid set imgdevpath="/dev/disk/by-uuid/$rootuuid" -export imgdevpath rootuuid +export imgdevpath rootuuid rootdisk rootpartnum # Custom variables set isopath="/boot/isos" @@ -16,8 +18,85 @@ if [ -e "$prefix/mbusb.cfg.local" ]; then source "$prefix/mbusb.cfg.local" fi +# Function to look for boot files +function search_files { + root="$1" + found="" + + insmod bitmap + insmod jpeg + insmod png + insmod tga + + for grubfile in \ + /boot/grub/loopback.cfg \ + /boot/grub/grub.cfg \ + /boot/grub/x86_64-efi/grub.cfg \ + /EFI/BOOT/grub.cfg; do + if [ -e "$grubfile" ]; then + found="found" + menuentry "GRUB boot ($grubfile)" "$grubfile" { + grub_file="$2" + configfile "$grub_file" + } + fi + done + + for syslinuxfile in \ + /isolinux.cfg \ + /syslinux.cfg \ + /isolinux/isolinux.cfg \ + /isolinux/syslinux.cfg \ + /syslinux/isolinux.cfg \ + /boot/isolinux.cfg \ + /boot/isolinux/isolinux.cfg \ + /boot/syslinux.cfg \ + /boot/syslinux/isolinux.cfg \ + /boot/syslinux/syslinux.cfg; do + if [ -e "$syslinuxfile" ]; then + found="found" + menuentry "SYSLINUX boot ($syslinuxfile)" "$syslinuxfile" { + syslinux_file="$2" + syslinux_configfile -i "$syslinux_file" + } + fi + done + + for legacyfile in \ + /boot/grub/menu.lst \ + /menu.lst; do + if [ -e "$legacyfile" ]; then + found="found" + menuentry "GRUB legacy boot ($legacyfile)" "$legacyfile" { + legacy_file="$2" + legacy_configfile "$legacy_file" + } + fi + done + + if [ "x$grub_platform" == "xefi" ]; then + for efifile in \ + /efi/boot/bootx64.efi \ + /efi/microsoft/boot/bootmgfw.efi; do + if [ -e "$efifile" ]; then + found="found" + menuentry "EFI boot ($efifile)" "$efifile" { + efi_file="$2" + chainloader "$efi_file" + } + fi + done + fi + if [ "x$found" == "x" ]; then + echo "no bootable things found on $root" + sleep -v -i 5 + fi + +} + # MultiBoot USB menu submenu "Multiboot ->" { + # Warning for 32-bit systems if ! cpuid -l; then clear @@ -30,9 +109,76 @@ submenu "Multiboot ->" { echo fi - # Load configuration files - echo -n "Loading configuration files... " - for cfgfile in $prefix/mbusb.d/*.d/*.cfg; do - source "$cfgfile" - done + # Load configuration for ISO/kernel files + submenu "Boot supported ISO/kernel files ->" { + echo -n "Loading configuration files... " + for cfgfile in $prefix/mbusb.d/*.d/*.cfg; do + source "$cfgfile" + done + } + + # Search partitions for boot files + submenu "Auto-detect bootable partitions ->" { + echo -n "Searching pendrive's partitions... " + for part in ($rootdisk,*); do + regexp --set=partnum "^.*,.*([0-9]+)" "$part" + if [ "$partnum" -le "$rootpartnum" ]; then continue; fi + submenu "$part ->" "$part" { + part_name="$2" + probe --fs-uuid $part_name --set=part_uuid + search --fs-uuid --no-floppy --hint=$part_name --set=root $part_uuid + # Look for boot files + search_files $root + } + done + } + + # Search ISO files for boot files + submenu "Auto-detect ISO's configfiles ->" { + echo -n "Looking for ISO files... " + for isofile in $isopath/*.iso $isopath/*.img; do + if [ -e "$isofile" ]; then + regexp --set=isoname "$isopath/(.*)" "$isofile" + submenu "$isoname ->" "$isofile" { + iso_path="$2" + export iso_path + search --set=root --file "$iso_path" + loopback loop "$iso_path" + root=(loop) + # Look for boot files + search_files $root + } + fi + done + } + + # Use MEMDISK to load ISO files + submenu "Use MEMDISK to boot ISO files ->" { + echo -n "Looking for ISO files... " + for isofile in $isopath/*.iso; do + if [ -e "$isofile" ]; then + regexp --set=isoname "$isopath/(.*)" "$isofile" + menuentry "$isoname" "$isofile" { + iso_path="$2" + bootoptions="iso raw" + linux16 $prefix/memdisk $bootoptions + initrd16 $iso_path + } + fi + done + echo + echo -n "Looking for ISO files... " + for imgfile in $isopath/*.img; do + if [ -e "$imgfile" ]; then + regexp --set=imgname "$isopath/(.*)" "$imgfile" + menuentry "$imgname" "$imgfile" { + img_path="$2" + bootoptions="raw" + linux16 $prefix/memdisk $bootoptions + initrd16 $img_path + } + fi + done + } + }