Magellan Linux

Diff of /tags/grubby-8_32/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1849 by niro, Mon Jul 2 13:08:29 2012 UTC revision 2058 by niro, Wed Feb 20 14:06:30 2013 UTC
# Line 56  int debug = 0; /* Currently just for tem Line 56  int debug = 0; /* Currently just for tem
56  #define NOOP_OPCODE 0x90  #define NOOP_OPCODE 0x90
57  #define JMP_SHORT_OPCODE 0xeb  #define JMP_SHORT_OPCODE 0xeb
58    
59    int isEfi = 0;
60    
61  /* comments get lumped in with indention */  /* comments get lumped in with indention */
62  struct lineElement {  struct lineElement {
63      char * item;      char * item;
# Line 82  enum lineType_e { Line 84  enum lineType_e {
84      LT_MENUENTRY    = 1 << 17,      LT_MENUENTRY    = 1 << 17,
85      LT_ENTRY_END    = 1 << 18,      LT_ENTRY_END    = 1 << 18,
86      LT_SET_VARIABLE = 1 << 19,      LT_SET_VARIABLE = 1 << 19,
87      LT_UNKNOWN      = 1 << 20,      LT_KERNEL_EFI   = 1 << 20,
88        LT_INITRD_EFI   = 1 << 21,
89        LT_UNKNOWN      = 1 << 22,
90  };  };
91    
92  struct singleLine {  struct singleLine {
# Line 134  struct configFileInfo { Line 138  struct configFileInfo {
138      findConfigFunc findConfig;      findConfigFunc findConfig;
139      writeLineFunc writeLine;      writeLineFunc writeLine;
140      struct keywordTypes * keywords;      struct keywordTypes * keywords;
141        int caseInsensitive;
142      int defaultIsIndex;      int defaultIsIndex;
143      int defaultIsVariable;      int defaultIsVariable;
144      int defaultSupportSaved;      int defaultSupportSaved;
# Line 164  struct keywordTypes grubKeywords[] = { Line 169  struct keywordTypes grubKeywords[] = {
169    
170  const char *grubFindConfig(struct configFileInfo *cfi) {  const char *grubFindConfig(struct configFileInfo *cfi) {
171      static const char *configFiles[] = {      static const char *configFiles[] = {
  "/etc/grub.conf",  
172   "/boot/grub/grub.conf",   "/boot/grub/grub.conf",
173   "/boot/grub/menu.lst",   "/boot/grub/menu.lst",
174     "/etc/grub.conf",
175   NULL   NULL
176      };      };
177      static int i = -1;      static int i = -1;
# Line 205  struct keywordTypes grub2Keywords[] = { Line 210  struct keywordTypes grub2Keywords[] = {
210      { "default",    LT_DEFAULT,     ' ' },      { "default",    LT_DEFAULT,     ' ' },
211      { "fallback",   LT_FALLBACK,    ' ' },      { "fallback",   LT_FALLBACK,    ' ' },
212      { "linux",      LT_KERNEL,      ' ' },      { "linux",      LT_KERNEL,      ' ' },
213        { "linuxefi",   LT_KERNEL_EFI,  ' ' },
214      { "initrd",     LT_INITRD,      ' ', ' ' },      { "initrd",     LT_INITRD,      ' ', ' ' },
215        { "initrdefi",  LT_INITRD_EFI,  ' ', ' ' },
216      { "module",     LT_MBMODULE,    ' ' },      { "module",     LT_MBMODULE,    ' ' },
217      { "kernel",     LT_HYPER,       ' ' },      { "kernel",     LT_HYPER,       ' ' },
218      { NULL, 0, 0 },      { NULL, 0, 0 },
# Line 271  static int isquote(char q) Line 278  static int isquote(char q)
278      return 0;      return 0;
279  }  }
280    
281    static int iskernel(enum lineType_e type) {
282        return (type == LT_KERNEL || type == LT_KERNEL_EFI);
283    }
284    
285    static int isinitrd(enum lineType_e type) {
286        return (type == LT_INITRD || type == LT_INITRD_EFI);
287    }
288    
289  char *grub2ExtractTitle(struct singleLine * line) {  char *grub2ExtractTitle(struct singleLine * line) {
290      char * current;      char * current;
291      char * current_indent;      char * current_indent;
# Line 482  struct configFileInfo ziplConfigType = { Line 497  struct configFileInfo ziplConfigType = {
497  struct configFileInfo extlinuxConfigType = {  struct configFileInfo extlinuxConfigType = {
498      .defaultConfig = "/boot/extlinux/extlinux.conf",      .defaultConfig = "/boot/extlinux/extlinux.conf",
499      .keywords = extlinuxKeywords,      .keywords = extlinuxKeywords,
500        .caseInsensitive = 1,
501      .entryStart = LT_TITLE,      .entryStart = LT_TITLE,
502      .needsBootPrefix = 1,      .needsBootPrefix = 1,
503      .maxTitleLength = 255,      .maxTitleLength = 255,
# Line 570  static char * sdupprintf(const char *for Line 586  static char * sdupprintf(const char *for
586      return buf;      return buf;
587  }  }
588    
589    static enum lineType_e preferredLineType(enum lineType_e type,
590     struct configFileInfo *cfi) {
591        if (isEfi && cfi == &grub2ConfigType) {
592     switch (type) {
593     case LT_KERNEL:
594        return LT_KERNEL_EFI;
595     case LT_INITRD:
596        return LT_INITRD_EFI;
597     default:
598        return type;
599     }
600        }
601        return type;
602    }
603    
604  static struct keywordTypes * getKeywordByType(enum lineType_e type,  static struct keywordTypes * getKeywordByType(enum lineType_e type,
605        struct configFileInfo * cfi) {        struct configFileInfo * cfi) {
606      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {
# Line 603  static char * getuuidbydev(char *device) Line 634  static char * getuuidbydev(char *device)
634  static enum lineType_e getTypeByKeyword(char * keyword,  static enum lineType_e getTypeByKeyword(char * keyword,
635   struct configFileInfo * cfi) {   struct configFileInfo * cfi) {
636      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {
637   if (!strcmp(keyword, kw->key))   if (cfi->caseInsensitive) {
638      return kw->type;      if (!strcasecmp(keyword, kw->key))
639                    return kw->type;
640     } else {
641        if (!strcmp(keyword, kw->key))
642            return kw->type;
643     }
644      }      }
645      return LT_UNKNOWN;      return LT_UNKNOWN;
646  }  }
# Line 994  static struct grubConfig * readConfig(co Line 1030  static struct grubConfig * readConfig(co
1030      cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;      cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;
1031      defaultLine = line;      defaultLine = line;
1032    
1033          } else if (line->type == LT_KERNEL) {          } else if (iskernel(line->type)) {
1034      /* if by some freak chance this is multiboot and the "module"      /* if by some freak chance this is multiboot and the "module"
1035       * lines came earlier in the template, make sure to use LT_HYPER       * lines came earlier in the template, make sure to use LT_HYPER
1036       * instead of LT_KERNEL now       * instead of LT_KERNEL now
# Line 1011  static struct grubConfig * readConfig(co Line 1047  static struct grubConfig * readConfig(co
1047      for (struct singleLine *l = entry->lines; l; l = l->next) {      for (struct singleLine *l = entry->lines; l; l = l->next) {
1048   if (l->type == LT_HYPER)   if (l->type == LT_HYPER)
1049      break;      break;
1050   else if (l->type == LT_KERNEL) {   else if (iskernel(l->type)) {
1051      l->type = LT_HYPER;      l->type = LT_HYPER;
1052      break;      break;
1053   }   }
# Line 1310  static int writeConfig(struct grubConfig Line 1346  static int writeConfig(struct grubConfig
1346    
1347      /* most likely the symlink is relative, so change our      /* most likely the symlink is relative, so change our
1348         directory to the dir of the symlink */         directory to the dir of the symlink */
1349              rc = chdir(dirname(outName));      char *dir = strdupa(outName);
1350        rc = chdir(dirname(dir));
1351      do {      do {
1352   buf = alloca(len + 1);   buf = alloca(len + 1);
1353   rc = readlink(basename(outName), buf, len);   rc = readlink(basename(outName), buf, len);
# Line 1564  int suitableImage(struct singleEntry * e Line 1601  int suitableImage(struct singleEntry * e
1601   return 0;   return 0;
1602      }      }
1603    
1604      line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines);      line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);
1605      if (!line) {      if (!line) {
1606   notSuitablePrintf(entry, "no line found\n");   notSuitablePrintf(entry, "no line found\n");
1607   return 0;   return 0;
# Line 1694  struct singleEntry * findEntryByPath(str Line 1731  struct singleEntry * findEntryByPath(str
1731   entry = findEntryByIndex(config, indexVars[i]);   entry = findEntryByIndex(config, indexVars[i]);
1732   if (!entry) return NULL;   if (!entry) return NULL;
1733    
1734   line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines);   line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);
1735   if (!line) return NULL;   if (!line) return NULL;
1736    
1737   if (index) *index = indexVars[i];   if (index) *index = indexVars[i];
# Line 1743  struct singleEntry * findEntryByPath(str Line 1780  struct singleEntry * findEntryByPath(str
1780    
1781      /* check all the lines matching checkType */      /* check all the lines matching checkType */
1782      for (line = entry->lines; line; line = line->next) {      for (line = entry->lines; line; line = line->next) {
1783   line = getLineByType(entry->multiboot && checkType == LT_KERNEL ?   enum lineType_e ct = checkType;
1784       LT_KERNEL|LT_MBMODULE|LT_HYPER :   if (entry->multiboot && checkType == LT_KERNEL)
1785       checkType, line);      ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER;
1786   if (!line) break;  /* not found in this entry */   else if (checkType & LT_KERNEL)
1787        ct = checkType | LT_KERNEL_EFI;
1788     line = getLineByType(ct, line);
1789     if (!line)
1790        break;  /* not found in this entry */
1791    
1792   if (line && line->type != LT_MENUENTRY &&   if (line && line->type != LT_MENUENTRY &&
1793   line->numElements >= 2) {   line->numElements >= 2) {
# Line 1765  struct singleEntry * findEntryByPath(str Line 1806  struct singleEntry * findEntryByPath(str
1806       * non-Linux boot entries (could find netbsd etc, though, which is       * non-Linux boot entries (could find netbsd etc, though, which is
1807       * unfortunate)       * unfortunate)
1808       */       */
1809      if (line && getLineByType(LT_KERNEL|LT_HYPER, entry->lines))      if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines))
1810   break; /* found 'im! */   break; /* found 'im! */
1811   }   }
1812    
# Line 1867  void markRemovedImage(struct grubConfig Line 1908  void markRemovedImage(struct grubConfig
1908    
1909  void setDefaultImage(struct grubConfig * config, int hasNew,  void setDefaultImage(struct grubConfig * config, int hasNew,
1910       const char * defaultKernelPath, int newIsDefault,       const char * defaultKernelPath, int newIsDefault,
1911       const char * prefix, int flags) {       const char * prefix, int flags, int index) {
1912      struct singleEntry * entry, * entry2, * newDefault;      struct singleEntry * entry, * entry2, * newDefault;
1913      int i, j;      int i, j;
1914    
1915      if (newIsDefault) {      if (newIsDefault) {
1916   config->defaultImage = 0;   config->defaultImage = 0;
1917   return;   return;
1918        } else if ((index >= 0) && config->cfi->defaultIsIndex) {
1919     if (findEntryByIndex(config, index))
1920        config->defaultImage = index;
1921     else
1922        config->defaultImage = -1;
1923     return;
1924      } else if (defaultKernelPath) {      } else if (defaultKernelPath) {
1925   i = 0;   i = 0;
1926   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {   if (findEntryByPath(config, defaultKernelPath, prefix, &i)) {
# Line 1948  void displayEntry(struct singleEntry * e Line 1995  void displayEntry(struct singleEntry * e
1995    
1996      printf("index=%d\n", index);      printf("index=%d\n", index);
1997    
1998      line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines);      line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);
1999      if (!line) {      if (!line) {
2000          printf("non linux entry\n");          printf("non linux entry\n");
2001          return;          return;
# Line 2013  void displayEntry(struct singleEntry * e Line 2060  void displayEntry(struct singleEntry * e
2060   printf("root=%s\n", s);   printf("root=%s\n", s);
2061      }      }
2062    
2063      line = getLineByType(LT_INITRD, entry->lines);      line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);
2064    
2065      if (line && line->numElements >= 2) {      if (line && line->numElements >= 2) {
2066   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))
# Line 2038  void displayEntry(struct singleEntry * e Line 2085  void displayEntry(struct singleEntry * e
2085      }      }
2086  }  }
2087    
2088    int isSuseSystem(void) {
2089        const char * path;
2090        const static char default_path[] = "/etc/SuSE-release";
2091    
2092        if ((path = getenv("GRUBBY_SUSE_RELEASE")) == NULL)
2093     path = default_path;
2094    
2095        if (!access(path, R_OK))
2096     return 1;
2097        return 0;
2098    }
2099    
2100    int isSuseGrubConf(const char * path) {
2101        FILE * grubConf;
2102        char * line = NULL;
2103        size_t len = 0, res = 0;
2104    
2105        grubConf = fopen(path, "r");
2106        if (!grubConf) {
2107            dbgPrintf("Could not open SuSE configuration file '%s'\n", path);
2108     return 0;
2109        }
2110    
2111        while ((res = getline(&line, &len, grubConf)) != -1) {
2112     if (!strncmp(line, "setup", 5)) {
2113        fclose(grubConf);
2114        free(line);
2115        return 1;
2116     }
2117        }
2118    
2119        dbgPrintf("SuSE configuration file '%s' does not appear to be valid\n",
2120          path);
2121    
2122        fclose(grubConf);
2123        free(line);
2124        return 0;
2125    }
2126    
2127    int suseGrubConfGetLba(const char * path, int * lbaPtr) {
2128        FILE * grubConf;
2129        char * line = NULL;
2130        size_t res = 0, len = 0;
2131    
2132        if (!path) return 1;
2133        if (!lbaPtr) return 1;
2134    
2135        grubConf = fopen(path, "r");
2136        if (!grubConf) return 1;
2137    
2138        while ((res = getline(&line, &len, grubConf)) != -1) {
2139     if (line[res - 1] == '\n')
2140        line[res - 1] = '\0';
2141     else if (len > res)
2142        line[res] = '\0';
2143     else {
2144        line = realloc(line, res + 1);
2145        line[res] = '\0';
2146     }
2147    
2148     if (!strncmp(line, "setup", 5)) {
2149        if (strstr(line, "--force-lba")) {
2150            *lbaPtr = 1;
2151        } else {
2152            *lbaPtr = 0;
2153        }
2154        dbgPrintf("lba: %i\n", *lbaPtr);
2155        break;
2156     }
2157        }
2158    
2159        free(line);
2160        fclose(grubConf);
2161        return 0;
2162    }
2163    
2164    int suseGrubConfGetInstallDevice(const char * path, char ** devicePtr) {
2165        FILE * grubConf;
2166        char * line = NULL;
2167        size_t res = 0, len = 0;
2168        char * lastParamPtr = NULL;
2169        char * secLastParamPtr = NULL;
2170        char installDeviceNumber = '\0';
2171        char * bounds = NULL;
2172    
2173        if (!path) return 1;
2174        if (!devicePtr) return 1;
2175    
2176        grubConf = fopen(path, "r");
2177        if (!grubConf) return 1;
2178    
2179        while ((res = getline(&line, &len, grubConf)) != -1) {
2180     if (strncmp(line, "setup", 5))
2181        continue;
2182    
2183     if (line[res - 1] == '\n')
2184        line[res - 1] = '\0';
2185     else if (len > res)
2186        line[res] = '\0';
2187     else {
2188        line = realloc(line, res + 1);
2189        line[res] = '\0';
2190     }
2191    
2192     lastParamPtr = bounds = line + res;
2193    
2194     /* Last parameter in grub may be an optional IMAGE_DEVICE */
2195     while (!isspace(*lastParamPtr))
2196        lastParamPtr--;
2197     lastParamPtr++;
2198    
2199     secLastParamPtr = lastParamPtr - 2;
2200     dbgPrintf("lastParamPtr: %s\n", lastParamPtr);
2201    
2202     if (lastParamPtr + 3 > bounds) {
2203        dbgPrintf("lastParamPtr going over boundary");
2204        fclose(grubConf);
2205        free(line);
2206        return 1;
2207     }
2208     if (!strncmp(lastParamPtr, "(hd", 3))
2209        lastParamPtr += 3;
2210     dbgPrintf("lastParamPtr: %c\n", *lastParamPtr);
2211    
2212     /*
2213     * Second last parameter will decide wether last parameter is
2214     * an IMAGE_DEVICE or INSTALL_DEVICE
2215     */
2216     while (!isspace(*secLastParamPtr))
2217        secLastParamPtr--;
2218     secLastParamPtr++;
2219    
2220     if (secLastParamPtr + 3 > bounds) {
2221        dbgPrintf("secLastParamPtr going over boundary");
2222        fclose(grubConf);
2223        free(line);
2224        return 1;
2225     }
2226     dbgPrintf("secLastParamPtr: %s\n", secLastParamPtr);
2227     if (!strncmp(secLastParamPtr, "(hd", 3)) {
2228        secLastParamPtr += 3;
2229        dbgPrintf("secLastParamPtr: %c\n", *secLastParamPtr);
2230        installDeviceNumber = *secLastParamPtr;
2231     } else {
2232        installDeviceNumber = *lastParamPtr;
2233     }
2234    
2235     *devicePtr = malloc(6);
2236     snprintf(*devicePtr, 6, "(hd%c)", installDeviceNumber);
2237     dbgPrintf("installDeviceNumber: %c\n", installDeviceNumber);
2238     fclose(grubConf);
2239     free(line);
2240     return 0;
2241        }
2242    
2243        free(line);
2244        fclose(grubConf);
2245        return 1;
2246    }
2247    
2248    int grubGetBootFromDeviceMap(const char * device,
2249         char ** bootPtr) {
2250        FILE * deviceMap;
2251        char * line = NULL;
2252        size_t res = 0, len = 0;
2253        char * devicePtr;
2254        char * bounds = NULL;
2255        const char * path;
2256        const static char default_path[] = "/boot/grub/device.map";
2257    
2258        if (!device) return 1;
2259        if (!bootPtr) return 1;
2260    
2261        if ((path = getenv("GRUBBY_GRUB_DEVICE_MAP")) == NULL)
2262     path = default_path;
2263    
2264        dbgPrintf("opening grub device.map file from: %s\n", path);
2265        deviceMap = fopen(path, "r");
2266        if (!deviceMap)
2267     return 1;
2268    
2269        while ((res = getline(&line, &len, deviceMap)) != -1) {
2270            if (!strncmp(line, "#", 1))
2271        continue;
2272    
2273     if (line[res - 1] == '\n')
2274        line[res - 1] = '\0';
2275     else if (len > res)
2276        line[res] = '\0';
2277     else {
2278        line = realloc(line, res + 1);
2279        line[res] = '\0';
2280     }
2281    
2282     devicePtr = line;
2283     bounds = line + res;
2284    
2285     while ((isspace(*line) && ((devicePtr + 1) <= bounds)))
2286        devicePtr++;
2287     dbgPrintf("device: %s\n", devicePtr);
2288    
2289     if (!strncmp(devicePtr, device, strlen(device))) {
2290        devicePtr += strlen(device);
2291        while (isspace(*devicePtr) && ((devicePtr + 1) <= bounds))
2292            devicePtr++;
2293    
2294        *bootPtr = strdup(devicePtr);
2295        break;
2296     }
2297        }
2298    
2299        free(line);
2300        fclose(deviceMap);
2301        return 0;
2302    }
2303    
2304    int suseGrubConfGetBoot(const char * path, char ** bootPtr) {
2305        char * grubDevice;
2306    
2307        if (suseGrubConfGetInstallDevice(path, &grubDevice))
2308     dbgPrintf("error looking for grub installation device\n");
2309        else
2310     dbgPrintf("grubby installation device: %s\n", grubDevice);
2311    
2312        if (grubGetBootFromDeviceMap(grubDevice, bootPtr))
2313     dbgPrintf("error looking for grub boot device\n");
2314        else
2315     dbgPrintf("grubby boot device: %s\n", *bootPtr);
2316    
2317        free(grubDevice);
2318        return 0;
2319    }
2320    
2321    int parseSuseGrubConf(int * lbaPtr, char ** bootPtr) {
2322        /*
2323         * This SuSE grub configuration file at this location is not your average
2324         * grub configuration file, but instead the grub commands used to setup
2325         * grub on that system.
2326         */
2327        const char * path;
2328        const static char default_path[] = "/etc/grub.conf";
2329    
2330        if ((path = getenv("GRUBBY_SUSE_GRUB_CONF")) == NULL)
2331     path = default_path;
2332    
2333        if (!isSuseGrubConf(path)) return 1;
2334    
2335        if (lbaPtr) {
2336            *lbaPtr = 0;
2337            if (suseGrubConfGetLba(path, lbaPtr))
2338                return 1;
2339        }
2340    
2341        if (bootPtr) {
2342            *bootPtr = NULL;
2343            suseGrubConfGetBoot(path, bootPtr);
2344        }
2345    
2346        return 0;
2347    }
2348    
2349  int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) {  int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) {
2350      FILE * in;      FILE * in;
2351      char buf[1024];      char buf[1024];
# Line 2086  int parseSysconfigGrub(int * lbaPtr, cha Line 2394  int parseSysconfigGrub(int * lbaPtr, cha
2394  }  }
2395    
2396  void dumpSysconfigGrub(void) {  void dumpSysconfigGrub(void) {
2397      char * boot;      char * boot = NULL;
2398      int lba;      int lba;
2399    
2400      if (!parseSysconfigGrub(&lba, &boot)) {      if (isSuseSystem()) {
2401   if (lba) printf("lba\n");          if (parseSuseGrubConf(&lba, &boot)) {
2402   if (boot) printf("boot=%s\n", boot);      free(boot);
2403        return;
2404     }
2405        } else {
2406            if (parseSysconfigGrub(&lba, &boot)) {
2407        free(boot);
2408        return;
2409     }
2410        }
2411    
2412        if (lba) printf("lba\n");
2413        if (boot) {
2414     printf("boot=%s\n", boot);
2415     free(boot);
2416      }      }
2417  }  }
2418    
# Line 2140  struct singleLine * addLineTmpl(struct s Line 2461  struct singleLine * addLineTmpl(struct s
2461  {  {
2462      struct singleLine * newLine = lineDup(tmplLine);      struct singleLine * newLine = lineDup(tmplLine);
2463    
2464        if (isEfi && cfi == &grub2ConfigType) {
2465     enum lineType_e old = newLine->type;
2466     newLine->type = preferredLineType(newLine->type, cfi);
2467     if (old != newLine->type)
2468        newLine->elements[0].item = getKeyByType(newLine->type, cfi);
2469        }
2470    
2471      if (val) {      if (val) {
2472   /* override the inherited value with our own.   /* override the inherited value with our own.
2473   * This is a little weak because it only applies to elements[1]   * This is a little weak because it only applies to elements[1]
# Line 2149  struct singleLine * addLineTmpl(struct s Line 2477  struct singleLine * addLineTmpl(struct s
2477   insertElement(newLine, val, 1, cfi);   insertElement(newLine, val, 1, cfi);
2478    
2479   /* but try to keep the rootspec from the template... sigh */   /* but try to keep the rootspec from the template... sigh */
2480   if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD)) {   if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI)) {
2481      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);
2482      if (rootspec != NULL) {      if (rootspec != NULL) {
2483   free(newLine->elements[1].item);   free(newLine->elements[1].item);
# Line 2186  struct singleLine *  addLine(struct sing Line 2514  struct singleLine *  addLine(struct sing
2514      /* NB: This function shouldn't allocate items on the heap, rather on the      /* NB: This function shouldn't allocate items on the heap, rather on the
2515       * stack since it calls addLineTmpl which will make copies.       * stack since it calls addLineTmpl which will make copies.
2516       */       */
   
2517      if (type == LT_TITLE && cfi->titleBracketed) {      if (type == LT_TITLE && cfi->titleBracketed) {
2518   /* we're doing a bracketed title (zipl) */   /* we're doing a bracketed title (zipl) */
2519   tmpl.type = type;   tmpl.type = type;
# Line 2520  int updateActualImage(struct grubConfig Line 2847  int updateActualImage(struct grubConfig
2847      firstElement = 2;      firstElement = 2;
2848    
2849   } else {   } else {
2850      line = getLineByType(LT_KERNEL|LT_MBMODULE, entry->lines);      line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI, entry->lines);
2851      if (!line) {      if (!line) {
2852   /* no LT_KERNEL or LT_MBMODULE in this entry? */   /* no LT_KERNEL or LT_MBMODULE in this entry? */
2853   continue;   continue;
# Line 2685  int updateInitrd(struct grubConfig * cfg Line 3012  int updateInitrd(struct grubConfig * cfg
3012      if (!image) return 0;      if (!image) return 0;
3013    
3014      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {
3015          kernelLine = getLineByType(LT_KERNEL, entry->lines);          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines);
3016          if (!kernelLine) continue;          if (!kernelLine) continue;
3017    
3018          line = getLineByType(LT_INITRD, entry->lines);          line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);
3019          if (line)          if (line)
3020              removeLine(entry, line);              removeLine(entry, line);
3021          if (prefix) {          if (prefix) {
# Line 2699  int updateInitrd(struct grubConfig * cfg Line 3026  int updateInitrd(struct grubConfig * cfg
3026   endLine = getLineByType(LT_ENTRY_END, entry->lines);   endLine = getLineByType(LT_ENTRY_END, entry->lines);
3027   if (endLine)   if (endLine)
3028      removeLine(entry, endLine);      removeLine(entry, endLine);
3029          line = addLine(entry, cfg->cfi, LT_INITRD, kernelLine->indent, initrd);          line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi),
3030     kernelLine->indent, initrd);
3031          if (!line)          if (!line)
3032      return 1;      return 1;
3033   if (endLine) {   if (endLine) {
# Line 2905  int checkForGrub(struct grubConfig * con Line 3233  int checkForGrub(struct grubConfig * con
3233      int fd;      int fd;
3234      unsigned char bootSect[512];      unsigned char bootSect[512];
3235      char * boot;      char * boot;
3236        int onSuse = isSuseSystem();
3237    
3238      if (parseSysconfigGrub(NULL, &boot))  
3239   return 0;      if (onSuse) {
3240     if (parseSuseGrubConf(NULL, &boot))
3241        return 0;
3242        } else {
3243     if (parseSysconfigGrub(NULL, &boot))
3244        return 0;
3245        }
3246    
3247      /* assume grub is not installed -- not an error condition */      /* assume grub is not installed -- not an error condition */
3248      if (!boot)      if (!boot)
# Line 2926  int checkForGrub(struct grubConfig * con Line 3261  int checkForGrub(struct grubConfig * con
3261      }      }
3262      close(fd);      close(fd);
3263    
3264        /* The more elaborate checks do not work on SuSE. The checks done
3265         * seem to be reasonble (at least for now), so just return success
3266         */
3267        if (onSuse)
3268     return 2;
3269    
3270      return checkDeviceBootloader(boot, bootSect);      return checkDeviceBootloader(boot, bootSect);
3271  }  }
3272    
# Line 2959  int checkForExtLinux(struct grubConfig * Line 3300  int checkForExtLinux(struct grubConfig *
3300      return checkDeviceBootloader(boot, bootSect);      return checkDeviceBootloader(boot, bootSect);
3301  }  }
3302    
3303    int checkForYaboot(struct grubConfig * config) {
3304        /*
3305         * This is a simplistic check that we consider good enough for own puporses
3306         *
3307         * If we were to properly check if yaboot is *installed* we'd need to:
3308         * 1) get the system boot device (LT_BOOT)
3309         * 2) considering it's a raw filesystem, check if the yaboot binary matches
3310         *    the content on the boot device
3311         * 3) if not, copy the binary to a temporary file and run "addnote" on it
3312         * 4) check again if binary and boot device contents match
3313         */
3314        if (!access("/etc/yaboot.conf", R_OK))
3315     return 2;
3316    
3317        return 1;
3318    }
3319    
3320    int checkForElilo(struct grubConfig * config) {
3321        if (!access("/etc/elilo.conf", R_OK))
3322     return 2;
3323    
3324        return 1;
3325    }
3326    
3327  static char * getRootSpecifier(char * str) {  static char * getRootSpecifier(char * str) {
3328      char * idx, * rootspec = NULL;      char * idx, * rootspec = NULL;
3329    
# Line 3075  int addNewKernel(struct grubConfig * con Line 3440  int addNewKernel(struct grubConfig * con
3440      while (*chptr && isspace(*chptr)) chptr++;      while (*chptr && isspace(*chptr)) chptr++;
3441      if (*chptr == '#') continue;      if (*chptr == '#') continue;
3442    
3443      if (tmplLine->type == LT_KERNEL &&      if (iskernel(tmplLine->type) && tmplLine->numElements >= 2) {
     tmplLine->numElements >= 2) {  
3444   if (!template->multiboot && (needs & NEED_MB)) {   if (!template->multiboot && (needs & NEED_MB)) {
3445      /* it's not a multiboot template and this is the kernel      /* it's not a multiboot template and this is the kernel
3446       * line.  Try to be intelligent about inserting the       * line.  Try to be intelligent about inserting the
# Line 3153  int addNewKernel(struct grubConfig * con Line 3517  int addNewKernel(struct grubConfig * con
3517      /* template is multi but new is not,      /* template is multi but new is not,
3518       * insert the kernel in the first module slot       * insert the kernel in the first module slot
3519       */       */
3520      tmplLine->type = LT_KERNEL;      tmplLine->type = preferredLineType(LT_KERNEL, config->cfi);
3521      free(tmplLine->elements[0].item);      free(tmplLine->elements[0].item);
3522      tmplLine->elements[0].item =      tmplLine->elements[0].item =
3523   strdup(getKeywordByType(LT_KERNEL, config->cfi)->key);   strdup(getKeywordByType(tmplLine->type,
3524     config->cfi)->key);
3525      newLine = addLineTmpl(new, tmplLine, newLine,      newLine = addLineTmpl(new, tmplLine, newLine,
3526    newKernelPath + strlen(prefix), config->cfi);    newKernelPath + strlen(prefix),
3527      config->cfi);
3528      needs &= ~NEED_KERNEL;      needs &= ~NEED_KERNEL;
3529   } else if (needs & NEED_INITRD) {   } else if (needs & NEED_INITRD) {
3530      char *initrdVal;      char *initrdVal;
3531      /* template is multi but new is not,      /* template is multi but new is not,
3532       * insert the initrd in the second module slot       * insert the initrd in the second module slot
3533       */       */
3534      tmplLine->type = LT_INITRD;      tmplLine->type = preferredLineType(LT_INITRD, config->cfi);
3535      free(tmplLine->elements[0].item);      free(tmplLine->elements[0].item);
3536      tmplLine->elements[0].item =      tmplLine->elements[0].item =
3537   strdup(getKeywordByType(LT_INITRD, config->cfi)->key);   strdup(getKeywordByType(tmplLine->type,
3538     config->cfi)->key);
3539      initrdVal = getInitrdVal(config, prefix, tmplLine, newKernelInitrd, extraInitrds, extraInitrdCount);      initrdVal = getInitrdVal(config, prefix, tmplLine, newKernelInitrd, extraInitrds, extraInitrdCount);
3540      newLine = addLineTmpl(new, tmplLine, newLine, initrdVal, config->cfi);      newLine = addLineTmpl(new, tmplLine, newLine, initrdVal, config->cfi);
3541      free(initrdVal);      free(initrdVal);
3542      needs &= ~NEED_INITRD;      needs &= ~NEED_INITRD;
3543   }   }
3544    
3545      } else if (tmplLine->type == LT_INITRD &&      } else if (isinitrd(tmplLine->type) && tmplLine->numElements >= 2) {
        tmplLine->numElements >= 2) {  
3546   if (needs & NEED_INITRD &&   if (needs & NEED_INITRD &&
3547      new->multiboot && !template->multiboot &&      new->multiboot && !template->multiboot &&
3548      config->cfi->mbInitRdIsModule) {      config->cfi->mbInitRdIsModule) {
# Line 3230  int addNewKernel(struct grubConfig * con Line 3596  int addNewKernel(struct grubConfig * con
3596      static const char *prefix = "'Loading ";      static const char *prefix = "'Loading ";
3597      if (tmplLine->numElements > 1 &&      if (tmplLine->numElements > 1 &&
3598      strstr(tmplLine->elements[1].item, prefix) &&      strstr(tmplLine->elements[1].item, prefix) &&
3599      masterLine->next && masterLine->next->type == LT_KERNEL) {      masterLine->next &&
3600        iskernel(masterLine->next->type)) {
3601   char *newTitle = malloc(strlen(prefix) +   char *newTitle = malloc(strlen(prefix) +
3602   strlen(newKernelTitle) + 2);   strlen(newKernelTitle) + 2);
3603    
# Line 3257  int addNewKernel(struct grubConfig * con Line 3624  int addNewKernel(struct grubConfig * con
3624   */   */
3625   switch (config->cfi->entryStart) {   switch (config->cfi->entryStart) {
3626      case LT_KERNEL:      case LT_KERNEL:
3627        case LT_KERNEL_EFI:
3628   if (new->multiboot && config->cfi->mbHyperFirst) {   if (new->multiboot && config->cfi->mbHyperFirst) {
3629      /* fall through to LT_HYPER */      /* fall through to LT_HYPER */
3630   } else {   } else {
3631      newLine = addLine(new, config->cfi, LT_KERNEL,      newLine = addLine(new, config->cfi,
3632              preferredLineType(LT_KERNEL, config->cfi),
3633        config->primaryIndent,        config->primaryIndent,
3634        newKernelPath + strlen(prefix));        newKernelPath + strlen(prefix));
3635      needs &= ~NEED_KERNEL;      needs &= ~NEED_KERNEL;
# Line 3336  int addNewKernel(struct grubConfig * con Line 3705  int addNewKernel(struct grubConfig * con
3705      if (needs & NEED_KERNEL) {      if (needs & NEED_KERNEL) {
3706   newLine = addLine(new, config->cfi,   newLine = addLine(new, config->cfi,
3707    (new->multiboot && getKeywordByType(LT_MBMODULE,    (new->multiboot && getKeywordByType(LT_MBMODULE,
3708        config->cfi)) ?        config->cfi))
3709    LT_MBMODULE : LT_KERNEL,     ? LT_MBMODULE
3710     : preferredLineType(LT_KERNEL, config->cfi),
3711    config->secondaryIndent,    config->secondaryIndent,
3712    newKernelPath + strlen(prefix));    newKernelPath + strlen(prefix));
3713   needs &= ~NEED_KERNEL;   needs &= ~NEED_KERNEL;
# Line 3353  int addNewKernel(struct grubConfig * con Line 3723  int addNewKernel(struct grubConfig * con
3723   initrdVal = getInitrdVal(config, prefix, NULL, newKernelInitrd, extraInitrds, extraInitrdCount);   initrdVal = getInitrdVal(config, prefix, NULL, newKernelInitrd, extraInitrds, extraInitrdCount);
3724   newLine = addLine(new, config->cfi,   newLine = addLine(new, config->cfi,
3725    (new->multiboot && getKeywordByType(LT_MBMODULE,    (new->multiboot && getKeywordByType(LT_MBMODULE,
3726        config->cfi)) ?        config->cfi))
3727    LT_MBMODULE : LT_INITRD,     ? LT_MBMODULE
3728       : preferredLineType(LT_INITRD, config->cfi),
3729    config->secondaryIndent,    config->secondaryIndent,
3730    initrdVal);    initrdVal);
3731   free(initrdVal);   free(initrdVal);
# Line 3386  static void traceback(int signum) Line 3757  static void traceback(int signum)
3757      memset(array, '\0', sizeof (array));      memset(array, '\0', sizeof (array));
3758      size = backtrace(array, 40);      size = backtrace(array, 40);
3759    
3760      fprintf(stderr, "grubby recieved SIGSEGV!  Backtrace (%ld):\n",      fprintf(stderr, "grubby received SIGSEGV!  Backtrace (%ld):\n",
3761              (unsigned long)size);              (unsigned long)size);
3762      backtrace_symbols_fd(array, size, STDERR_FILENO);      backtrace_symbols_fd(array, size, STDERR_FILENO);
3763      exit(1);      exit(1);
# Line 3429  int main(int argc, const char ** argv) { Line 3800  int main(int argc, const char ** argv) {
3800      int displayDefault = 0;      int displayDefault = 0;
3801      int displayDefaultIndex = 0;      int displayDefaultIndex = 0;
3802      int displayDefaultTitle = 0;      int displayDefaultTitle = 0;
3803        int defaultIndex = -1;
3804      struct poptOption options[] = {      struct poptOption options[] = {
3805   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
3806      _("add an entry for the specified kernel"), _("kernel-path") },      _("add an entry for the specified kernel"), _("kernel-path") },
# Line 3446  int main(int argc, const char ** argv) { Line 3818  int main(int argc, const char ** argv) {
3818   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,
3819      _("filestystem which contains /boot directory (for testing only)"),      _("filestystem which contains /boot directory (for testing only)"),
3820      _("bootfs") },      _("bootfs") },
3821  #if defined(__i386__) || defined(__x86_64__)  #if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__) || defined (__ia64__)
3822   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,
3823      _("check if lilo is installed on lilo.conf boot sector") },      _("check which bootloader is installed on boot sector") },
3824  #endif  #endif
3825   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,
3826      _("path to grub config file to update (\"-\" for stdin)"),      _("path to grub config file to update (\"-\" for stdin)"),
# Line 3469  int main(int argc, const char ** argv) { Line 3841  int main(int argc, const char ** argv) {
3841      _("display the title of the default kernel") },      _("display the title of the default kernel") },
3842   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
3843      _("configure elilo bootloader") },      _("configure elilo bootloader") },
3844     { "efi", 0, POPT_ARG_NONE, &isEfi, 0,
3845        _("force grub2 stanzas to use efi") },
3846   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,
3847      _("configure extlinux bootloader (from syslinux)") },      _("configure extlinux bootloader (from syslinux)") },
3848   { "grub", 0, POPT_ARG_NONE, &configureGrub, 0,   { "grub", 0, POPT_ARG_NONE, &configureGrub, 0,
# Line 3481  int main(int argc, const char ** argv) { Line 3855  int main(int argc, const char ** argv) {
3855   { "initrd", 0, POPT_ARG_STRING, &newKernelInitrd, 0,   { "initrd", 0, POPT_ARG_STRING, &newKernelInitrd, 0,
3856      _("initrd image for the new kernel"), _("initrd-path") },      _("initrd image for the new kernel"), _("initrd-path") },
3857   { "extra-initrd", 'i', POPT_ARG_STRING, NULL, 'i',   { "extra-initrd", 'i', POPT_ARG_STRING, NULL, 'i',
3858      _("auxilliary initrd image for things other than the new kernel"), _("initrd-path") },      _("auxiliary initrd image for things other than the new kernel"), _("initrd-path") },
3859   { "lilo", 0, POPT_ARG_NONE, &configureLilo, 0,   { "lilo", 0, POPT_ARG_NONE, &configureLilo, 0,
3860      _("configure lilo bootloader") },      _("configure lilo bootloader") },
3861   { "make-default", 0, 0, &makeDefault, 0,   { "make-default", 0, 0, &makeDefault, 0,
# Line 3501  int main(int argc, const char ** argv) { Line 3875  int main(int argc, const char ** argv) {
3875   { "set-default", 0, POPT_ARG_STRING, &defaultKernel, 0,   { "set-default", 0, POPT_ARG_STRING, &defaultKernel, 0,
3876      _("make the first entry referencing the specified kernel "      _("make the first entry referencing the specified kernel "
3877        "the default"), _("kernel-path") },        "the default"), _("kernel-path") },
3878     { "set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0,
3879        _("make the given entry index the default entry"),
3880        _("entry-index") },
3881   { "silo", 0, POPT_ARG_NONE, &configureSilo, 0,   { "silo", 0, POPT_ARG_NONE, &configureSilo, 0,
3882      _("configure silo bootloader") },      _("configure silo bootloader") },
3883   { "title", 0, POPT_ARG_STRING, &newKernelTitle, 0,   { "title", 0, POPT_ARG_STRING, &newKernelTitle, 0,
# Line 3609  int main(int argc, const char ** argv) { Line 3986  int main(int argc, const char ** argv) {
3986      }      }
3987    
3988      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
3989    newKernelPath || removeKernelPath || makeDefault ||      newKernelPath || removeKernelPath || makeDefault ||
3990    defaultKernel || displayDefaultIndex || displayDefaultTitle)) {      defaultKernel || displayDefaultIndex || displayDefaultTitle ||
3991        (defaultIndex >= 0))) {
3992   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
3993    "specified option"));    "specified option"));
3994   return 1;   return 1;
# Line 3652  int main(int argc, const char ** argv) { Line 4030  int main(int argc, const char ** argv) {
4030   makeDefault = 1;   makeDefault = 1;
4031   defaultKernel = NULL;   defaultKernel = NULL;
4032      }      }
4033        else if (defaultKernel && (defaultIndex >= 0)) {
4034     fprintf(stderr, _("grubby: --set-default and --set-default-index "
4035      "may not be used together\n"));
4036     return 1;
4037        }
4038    
4039      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {
4040   fprintf(stderr, _("grubby: output file must be specified if stdin "   fprintf(stderr, _("grubby: output file must be specified if stdin "
# Line 3660  int main(int argc, const char ** argv) { Line 4043  int main(int argc, const char ** argv) {
4043      }      }
4044    
4045      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
4046   && !kernelInfo && !bootloaderProbe && !updateKernelPath   && !kernelInfo && !bootloaderProbe && !updateKernelPath
4047          && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) {   && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle
4048     && (defaultIndex == -1)) {
4049   fprintf(stderr, _("grubby: no action specified\n"));   fprintf(stderr, _("grubby: no action specified\n"));
4050   return 1;   return 1;
4051      }      }
# Line 3688  int main(int argc, const char ** argv) { Line 4072  int main(int argc, const char ** argv) {
4072      }      }
4073    
4074      if (bootloaderProbe) {      if (bootloaderProbe) {
4075   int lrc = 0, grc = 0, gr2c = 0, erc = 0;   int lrc = 0, grc = 0, gr2c = 0, extrc = 0, yrc = 0, erc = 0;
4076   struct grubConfig * lconfig, * gconfig;   struct grubConfig * lconfig, * gconfig, * yconfig, * econfig;
4077    
4078   const char *grub2config = grub2FindConfig(&grub2ConfigType);   const char *grub2config = grub2FindConfig(&grub2ConfigType);
4079   if (grub2config) {   if (grub2config) {
# Line 3717  int main(int argc, const char ** argv) { Line 4101  int main(int argc, const char ** argv) {
4101   lrc = checkForLilo(lconfig);   lrc = checkForLilo(lconfig);
4102   }   }
4103    
4104     if (!access(eliloConfigType.defaultConfig, F_OK)) {
4105        econfig = readConfig(eliloConfigType.defaultConfig,
4106     &eliloConfigType);
4107        if (!econfig)
4108     erc = 1;
4109        else
4110     erc = checkForElilo(econfig);
4111     }
4112    
4113   if (!access(extlinuxConfigType.defaultConfig, F_OK)) {   if (!access(extlinuxConfigType.defaultConfig, F_OK)) {
4114      lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType);      lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType);
4115      if (!lconfig)      if (!lconfig)
4116   erc = 1;   extrc = 1;
4117      else      else
4118   erc = checkForExtLinux(lconfig);   extrc = checkForExtLinux(lconfig);
4119   }   }
4120    
4121   if (lrc == 1 || grc == 1 || gr2c == 1) return 1;  
4122     if (!access(yabootConfigType.defaultConfig, F_OK)) {
4123        yconfig = readConfig(yabootConfigType.defaultConfig,
4124     &yabootConfigType);
4125        if (!yconfig)
4126     yrc = 1;
4127        else
4128     yrc = checkForYaboot(yconfig);
4129     }
4130    
4131     if (lrc == 1 || grc == 1 || gr2c == 1 || extrc == 1 || yrc == 1 ||
4132     erc == 1)
4133        return 1;
4134    
4135   if (lrc == 2) printf("lilo\n");   if (lrc == 2) printf("lilo\n");
4136   if (gr2c == 2) printf("grub2\n");   if (gr2c == 2) printf("grub2\n");
4137   if (grc == 2) printf("grub\n");   if (grc == 2) printf("grub\n");
4138   if (erc == 2) printf("extlinux\n");   if (extrc == 2) printf("extlinux\n");
4139     if (yrc == 2) printf("yaboot\n");
4140     if (erc == 2) printf("elilo\n");
4141    
4142   return 0;   return 0;
4143      }      }
# Line 3748  int main(int argc, const char ** argv) { Line 4155  int main(int argc, const char ** argv) {
4155   if (!entry) return 0;   if (!entry) return 0;
4156   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;
4157    
4158   line = getLineByType(LT_KERNEL|LT_HYPER, entry->lines);   line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines);
4159   if (!line) return 0;   if (!line) return 0;
4160    
4161          rootspec = getRootSpecifier(line->elements[1].item);          rootspec = getRootSpecifier(line->elements[1].item);
# Line 3797  int main(int argc, const char ** argv) { Line 4204  int main(int argc, const char ** argv) {
4204      markRemovedImage(config, removeKernelPath, bootPrefix);      markRemovedImage(config, removeKernelPath, bootPrefix);
4205      markRemovedImage(config, removeMBKernel, bootPrefix);      markRemovedImage(config, removeMBKernel, bootPrefix);
4206      setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault,      setDefaultImage(config, newKernelPath != NULL, defaultKernel, makeDefault,
4207      bootPrefix, flags);      bootPrefix, flags, defaultIndex);
4208      setFallbackImage(config, newKernelPath != NULL);      setFallbackImage(config, newKernelPath != NULL);
4209      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,
4210                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;

Legend:
Removed from v.1849  
changed lines
  Added in v.2058