--- trunk/grubby/grubby.c 2017/06/27 14:43:04 3026 +++ trunk/grubby/grubby.c 2017/06/27 14:45:42 3027 @@ -2525,6 +2525,9 @@ struct singleEntry *bootEntry, *newDefault; int indexToVerify, firstKernelEntryIndex, currentLookupIndex; + /* initialize */ + currentLookupIndex = FIRST_ENTRY_INDEX; + /* handle the two cases where the user explictly picks the default * boot entry index as it would exist post-modification */ @@ -2590,8 +2593,30 @@ config->defaultImage++; } } else { - /* use pre-existing default entry */ - currentLookupIndex = config->defaultImage; + /* check to see if the default is stored in the environment */ + if (config->defaultImage < FIRST_ENTRY_INDEX) { + if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2) + { + if (config->cfi->defaultIsSaved) { + if (config->cfi->getEnv) { + char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry"); + + if (defaultTitle) { + if (isnumber(defaultTitle)) { + currentLookupIndex = atoi(defaultTitle); + } else { + findEntryByTitle(config, defaultTitle, ¤tLookupIndex); + } + /* set the default Image to an actual index */ + config->defaultImage = currentLookupIndex; + } + } + } + } + } else { + /* use pre-existing default entry from the file*/ + currentLookupIndex = config->defaultImage; + } if (isAddingBootEntry && (newBootEntryIndex <= config->defaultImage)) {