This pairs with --default-index, allowing the user to specify the entry to make the default using and index rather than a kernel. Signed-off-by: Cleber Rosa <crosa@xxxxxxxxxx> --- grubby.8 | 11 ++++++++--- grubby.c | 29 +++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/grubby.8 b/grubby.8 index fe60892..43c141d 100644 --- a/grubby.8 +++ b/grubby.8 @@ -11,9 +11,10 @@ grubby \- command line tool for configuring grub, lilo, and elilo [--info=\fIkernel-path\fR] [--initrd=\fIinitrd-path\fR] [--make-default] [-o path] [--version] [--remove-kernel=\fIkernel-path\fR] [--remove-args=\fIargs\fR] - [--set-default=\fIkernel-path\fR] [--title=entry-title] - [--add-multiboot=\fImultiboot-path\fR] [--mbargs=\fIargs\fR] - [--remove-multiboot=\fImultiboot-path\fR] [--remove-mbargs=\fIargs\fR] + [--set-default=\fIkernel-path\fR] [--set-default-index=\fientry-index\fR] + [--title=entry-title] [--add-multiboot=\fImultiboot-path\fR] + [--mbargs=\fIargs\fR] [--remove-multiboot=\fImultiboot-path\fR] + [--remove-mbargs=\fIargs\fR] .SH DESCRIPTION \fBgrubby\fR is a command line tool for updating and displaying information @@ -154,6 +155,10 @@ The first entry which boots the specified kernel is made the default boot entry. .TP +\fB-\-set-default-index\fR=\fIentry-index\fR +Makes the given entry number the default boot entry. + +.TP \fB-\-title\fR=\fIentry-title\fR When a new kernel entry is added \fIentry-title\fR is used as the title (\fBlilo\fR label) for the entry. If \fIentry-title\fR is longer then maximum diff --git a/grubby.c b/grubby.c index 9bf6140..686511c 100644 --- a/grubby.c +++ b/grubby.c @@ -1879,13 +1879,19 @@ void markRemovedImage(struct grubConfig * cfg, const char * image, void setDefaultImage(struct grubConfig * config, int hasNew, const char * defaultKernelPath, int newIsDefault, - const char * prefix, int flags) { + const char * prefix, int flags, int index) { struct singleEntry * entry, * entry2, * newDefault; int i, j; if (newIsDefault) { config->defaultImage = 0; return; + } else if ((index >= 0) && config->cfi->defaultIsIndex) { + if (findEntryByIndex(config, index)) + config->defaultImage = index; + else + config->defaultImage = -1; + return; } else if (defaultKernelPath) { i = 0; if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { @@ -3751,6 +3757,7 @@ int main(int argc, const char ** argv) { int displayDefault = 0; int displayDefaultIndex = 0; int displayDefaultTitle = 0; + int defaultIndex = -1; struct poptOption options[] = { { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0, _("add an entry for the specified kernel"), _("kernel-path") }, @@ -3823,6 +3830,9 @@ int main(int argc, const char ** argv) { { "set-default", 0, POPT_ARG_STRING, &defaultKernel, 0, _("make the first entry referencing the specified kernel " "the default"), _("kernel-path") }, + { "set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0, + _("make the given entry index the default entry"), + _("entry-index") }, { "silo", 0, POPT_ARG_NONE, &configureSilo, 0, _("configure silo bootloader") }, { "title", 0, POPT_ARG_STRING, &newKernelTitle, 0, @@ -3931,8 +3941,9 @@ int main(int argc, const char ** argv) { } if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || - newKernelPath || removeKernelPath || makeDefault || - defaultKernel || displayDefaultIndex || displayDefaultTitle)) { + newKernelPath || removeKernelPath || makeDefault || + defaultKernel || displayDefaultIndex || displayDefaultTitle || + (defaultIndex >= 0))) { fprintf(stderr, _("grubby: --bootloader-probe may not be used with " "specified option")); return 1; @@ -3974,6 +3985,11 @@ int main(int argc, const char ** argv) { makeDefault = 1; defaultKernel = NULL; } + else if (defaultKernel && (defaultIndex >= 0)) { + fprintf(stderr, _("grubby: --set-default and --set-default-index " + "may not be used together\n")); + return 1; + } if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) { fprintf(stderr, _("grubby: output file must be specified if stdin " @@ -3982,8 +3998,9 @@ int main(int argc, const char ** argv) { } if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel - && !kernelInfo && !bootloaderProbe && !updateKernelPath - && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) { + && !kernelInfo && !bootloaderProbe && !updateKernelPath + && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle + && (defaultIndex == -1)) { fprintf(stderr, _("grubby: no action specified\n")); return 1; } @@ -4142,7 +4159,7 @@ int main(int argc, const char ** argv) { markRemovedImage(config, removeKernelPath, bootPrefix); markRemovedImage(config, removeMBKernel, bootPrefix); setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault, - bootPrefix, flags); + bootPrefix, flags, defaultIndex); setFallbackImage(config, newKernelPath != NULL); if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; -- 1.7.10.2 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list