• Boot help script for UEFI systems

    Hi all!
    There have been so many booting problems lately that I wrote a small bash script that might help people in UEFI systems.
    The script can also be used on a working system for generating additional boot entries that boot directly to the selected operating system.

    This script only creates a new file /boot/grub/custom.cfg to your system, so nothing disruptive is done. And no need to run ‘grub-mkconfig’ afterwards. You’ll just see new boot entries like ‘custom_antergos’, ‘custom_Microsoft’ etc.

    Copy the script below to a text file. You can make it executable:

    chmod +x script_name

    and run it like any program, or run it using bash:

    bash script_name

    Change the script_name above to your liking.

    Disclaimer: you may use it at your own risk!

    # Generate /boot/grub/custom.cfg (see TARGET below) for UEFI systems.
    # Possible existing TARGET file is backed up.
    # Either use this script in your daily linux installation, or
    # chroot to a non-booting linux and run this script.
        echo "$*" >> "$TARGET"
        if [ "$(id -u)" != "0" ] ; then
            echo "Root permissions needed to run this program!"
            return 1
        local xx yy
        local dev
        local mountpoint=/root/mountpoint.$$
        local linux_efis windows_efis
        local efi
        local name_prefix="custom_"
        # look for .efi files
        for xx in $(lsblk -lo NAME,FSTYPE | grep vfat | awk '{print $1}')
            mkdir -p "$mountpoint"
            mount "$dev" "$mountpoint"
            # look for linux efi files
            for yy in grubx64.efi
                efi=$(find "$mountpoint" -type f -iname "$yy" | sed 's|'$mountpoint'|'$dev'@|')
                if [ "$efi" != "" ] ; then
                    linux_efis+="$efi "
            # look for windows efi files
            for yy in bootmgfw.efi bootx64.efi
                efi=$(find "$mountpoint" -type f -iname "$yy" | sed 's|'$mountpoint'|'$dev'@|')
                if [ "$efi" != "" ] ; then
                    windows_efis+="$efi "
                    break   # the first is enough!
            umount "$mountpoint"
        if [ -d "$mountpoint" ] ; then
            rmdir "$mountpoint"
        echo "Found (Linux):"
        for xx in $linux_efis
            echo "  $xx"
        echo "Found (Windows):"
        for xx in $windows_efis
            echo "  $xx"
        if [ "$linux_efis" = "" ] && [ "$windows_efis" = "" ] ; then
            echo "Nothing to generate!"
            return 1
        # Generate menu entries.
        # Backup the old file if it exists.
        if [ -e "$TARGET" ] ; then
            mv "$TARGET" "$TARGET".$(date +%Y%m%d-%H%M%S)
        Generate "# Generated by $0 at $(date)"
        Generate "#"
        for xx in $linux_efis $windows_efis
            yy="$name_prefix""$(echo "$xx" | sed 's|^.*/[eE][fF][iI]/\([^/]*\)/.*$|\1|')"
            Generate "menuentry \"$yy\" {"
            Generate "  savedefault"
            yy=$(echo "$xx" | sed 's|^.*\@||')
            Generate "  set file=\"$yy\""
            Generate "  search --set --file \${file}"
            Generate "  chainloader \${file}"
            Generate "}"
        # Show where the resulting file resides.
        ls -l "$TARGET"
  • may package this one after some testers ?

    Also something wewhat should be nice for a antergos-rescue-ISO @keegan

  • It could be packaged, but as you know, I’m quite slow to do that. I’d appreciate any help on this, maybe @Keegan or anybody else with UEFI computers?

    Of course some testing should be done first, the more testers the better. This particular script should not break anything since it writes only one file (and creates a backup if the file already exists). But I have tested it only on one machine, so it really needs more testing.

  • i think only that this will help mostly users with not so much experience, and so it will be nice to simple install it over packagemanager and run it… instead of copy paste and the need of some more knowledge tomake it run…

  • @joekamprad
    Yes, people new to Antergos/Arch/Linux would benefit the most out of this script probably, and sure, the best would be to have it as an already existing package. Best would be in the ISO installer as one of the helper tools.

  • @joekamprad said in Boot help script for UEFI systems:

    Also something wewhat should be nice for a antergos-rescue-ISO @keegan

    Good idea😀. Sadly, I am too busy right now to do that, but hopefully life slows down soon!

    I’d appreciate any help on this, maybe @Keegan or anybody else with UEFI computers?

    I’m really sorry, but again, I’m just swamped with work😞. Perhaps some other time though!

boot320 uefi43 systems3 Posts 6Views 571
Log in to reply
Bloom Email Optin Plugin

Looks like your connection to Antergos Community Forum was lost, please wait while we try to reconnect.