When using the following command to add an initrd for the kernel. grubby --update-kernel=/boot/vmlinuz-2.6.32-431.17.1.el6.x86_64.debug --initrd /boot/initramfs-2.6.32-431.17.1.el6.x86_64.debug.img --add-multiboot=/boot/tboot.gz The multiboot image /boot/tboot.gz is used as the key to search the configure entry in grub.conf, this is wrong. There may be other kernels also configure multiboot with the same name tboot.gz, if their index are smaller than the target one, then that will make the initrd added to the wrong kernel. Fix it to use kernel name as the search key.
Signed-off-by: Junxiao Bi junxiao.bi@oracle.com --- grubby.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/grubby.c b/grubby.c index 88a1f08..2d7ab62 100644 --- a/grubby.c +++ b/grubby.c @@ -3309,7 +3309,7 @@ int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,
if (!image) return 0;
- for (; (entry = findEntryByPath(cfg, newMBKernel, prefix, &index)); index++) { + for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { kernelLine = getLineByType(LT_MBMODULE, entry->lines); if (!kernelLine) continue;
When tboot is used, there is no line with LT_KERNEL* flag in grubConfig, so "kernelLine" will be null, this will cause updateInitrd() fail without setting the initrd. The "kernelLine" is used here to get the initrd configure line's type and indent, the initrd configure type should be LT_MBMODULE when tboot is used, or it is preferredLineType(LT_INITRD, cfg->cfi). The initrd configure indent is cfg->secondaryIndent. So remove "kernelLine".
Signed-off-by: Junxiao Bi junxiao.bi@oracle.com --- grubby.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/grubby.c b/grubby.c index 2d7ab62..491b07d 100644 --- a/grubby.c +++ b/grubby.c @@ -3340,15 +3340,12 @@ int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel, int updateInitrd(struct grubConfig * cfg, const char * image, const char * prefix, const char * initrd) { struct singleEntry * entry; - struct singleLine * line, * kernelLine, *endLine = NULL; + struct singleLine * line, *endLine = NULL; int index = 0;
if (!image) return 0;
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { - kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); - if (!kernelLine) continue; - line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); if (line) removeLine(entry, line); @@ -3360,21 +3357,14 @@ int updateInitrd(struct grubConfig * cfg, const char * image, endLine = getLineByType(LT_ENTRY_END, entry->lines); if (endLine) removeLine(entry, endLine); + enum lineType_e lt; - switch(kernelLine->type) { - case LT_KERNEL: - lt = LT_INITRD; - break; - case LT_KERNEL_EFI: - lt = LT_INITRD_EFI; - break; - case LT_KERNEL_16: - lt = LT_INITRD_16; - break; - default: + if (entry->multiboot && getKeywordByType(LT_MBMODULE, cfg->cfi)) + lt = LT_MBMODULE; + else lt = preferredLineType(LT_INITRD, cfg->cfi); - } - line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd); + + line = addLine(entry, cfg->cfi, lt, cfg->secondaryIndent, initrd); if (!line) return 1; if (endLine) {
The configure line of kernel should have the same indent with the one of hypervisor. The reset is no needed.
Signed-off-by: Junxiao Bi junxiao.bi@oracle.com --- grubby.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/grubby.c b/grubby.c index 491b07d..6e91cae 100644 --- a/grubby.c +++ b/grubby.c @@ -3791,9 +3791,6 @@ int addNewKernel(struct grubConfig * config, struct singleEntry * template, newLine = addLine(new, config->cfi, LT_HYPER, tmplLine->indent, newMBKernel + strlen(prefix)); - /* set up for adding the kernel line */ - free(tmplLine->indent); - tmplLine->indent = strdup(config->secondaryIndent); needs &= ~NEED_MB; } if (needs & NEED_KERNEL) {
anaconda-devel@lists.stg.fedoraproject.org