Boot another OS after hibernate

I want to be able to choose what kernel or OS to boot in GRUB 2 boot menu. I have Windows on another HDD & I want hibernate
openSUSE, turn on PC & boot Windows. What I have found is file grub2.sleep in /usr/lib/systemd/system-sleep.
There is function called prepare-grub which sets what menu entry to boot after sleep, I have deleted code that calls prepare-grub,
but nothing changed.

#############################################################################
# if we did not find a kernel (or BOOT_LOADER is not GRUB) check,
# if the running kernel is still the one that will (probably) be booted for
# resume (default entry in menu.lst or, if there is none, the kernel file

# /boot/vmlinuz points to.)
# This will only work, if you use "original" SUSE kernels.
# you can always override with the config variable set to "yes"
prepare-grub()
{
        echo "INFO: Running prepare-grub .."
        check-system
        get-kernels
        RUNNING=`uname -r`
        find-kernel-entry

        if  -z "$NEXT_BOOT" ]; then
                # which kernel is booted with the default entry?
                BOOTING="${KERNELS$DEFAULT_BOOT]}"
                # if there is no default entry (no menu.lst?) we fall back to
                # the default of /boot/vmlinuz.
                 -z "$BOOTING" ] && BOOTING="vmlinuz"
                if IMAGE=`readlink /boot/$BOOTING` &&  -e "/boot/${IMAGE##*/}" ]; then
                        BOOTING=$IMAGE
                fi
                BOOTING="${BOOTING#*vmlinuz-}"
                echo  "running kernel: '$RUNNING', probably booting kernel: '$BOOTING'"
                if  "$BOOTING" != "$RUNNING" ]; then
                        error_quit "ERROR: kernel version mismatch, cannot suspend to disk"
                fi
        else
                # set the bootloader to the running kernel
                echo "  preparing boot-loader: selecting entry $NEXT_BOOT, kernel /boot/$BOOTING"
                T1=`date +"%s%N"`
                sync; sync; sync # this is needed to speed up grub-once on reiserfs
                T2=`date +"%s%N"`
                echo "  running $GRUB_ONCE \"${NEXT_BOOT}\""
                ${GRUB_ONCE} "$NEXT_BOOT"
                T3=`date +"%s%N"`
                S=$(((T2-T1)/100000000)); S="$((S/10)).${S:0-1}"
                G=$(((T3-T2)/100000000)); G="$((G/10)).${G:0-1}"
                echo "    time needed for sync: $S seconds, time needed for grub: $G seconds."
        fi

        echo "INFO: Done."
}


###### main()


if  "$1" = pre ] ; then
    prepare-grub
fi
if  "$1" = post ] ; then
    grub-once-restore
fi

First and foremost, there’s a reason why you normally cannot choose a boot entry on resume.
Booting a different OS may easily lead to data corruption, it can destroy your partitions beyond repair (even your Windows partition if you had it mounted in Linux).

If you really want to, just remove the file altogether.

Or, from reading the code it should also be disabled if you set LOADER_TYPE=“None” in /etc/sysconfig/bootloader. But that means that you have to manage the bootloader and menu yourself, it won’t get updated when a kernel update is installed.

If you remove the call to “prepare-grub”, it should not set a menu entry to boot either.

But if the script you posted is how it looks after your changes, then you did not remove the call to “prepare-grub”… :wink:


###### main()


if  "$1" = pre ] ; then
    prepare-grub
fi
if  "$1" = post ] ; then
    grub-once-restore
fi

Removing prepare-grub function call has no effect but LOADER_TYPE=“None” satisfied my desire. And this is about 42.2.