139 |
}; |
}; |
140 |
|
|
141 |
struct configFileInfo grubConfigType = { |
struct configFileInfo grubConfigType = { |
142 |
"/etc/grub.conf", /* defaultConfig */ |
"/boot/grub/grub.conf", /* defaultConfig */ |
143 |
grubKeywords, /* keywords */ |
grubKeywords, /* keywords */ |
144 |
1, /* defaultIsIndex */ |
1, /* defaultIsIndex */ |
145 |
1, /* defaultSupportSaved */ |
1, /* defaultSupportSaved */ |
356 |
struct configFileInfo * cfi; |
struct configFileInfo * cfi; |
357 |
}; |
}; |
358 |
|
|
359 |
|
blkid_cache blkid; |
360 |
|
|
361 |
struct singleEntry * findEntryByIndex(struct grubConfig * cfg, int index); |
struct singleEntry * findEntryByIndex(struct grubConfig * cfg, int index); |
362 |
struct singleEntry * findEntryByPath(struct grubConfig * cfg, |
struct singleEntry * findEntryByPath(struct grubConfig * cfg, |
363 |
const char * path, const char * prefix, |
const char * path, const char * prefix, |
436 |
} |
} |
437 |
|
|
438 |
static char * getpathbyspec(char *device) { |
static char * getpathbyspec(char *device) { |
|
static blkid_cache blkid; |
|
|
|
|
439 |
if (!blkid) |
if (!blkid) |
440 |
blkid_get_cache(&blkid, NULL); |
blkid_get_cache(&blkid, NULL); |
441 |
|
|
442 |
return blkid_get_devname(blkid, device, NULL); |
return blkid_get_devname(blkid, device, NULL); |
443 |
} |
} |
444 |
|
|
445 |
|
static char * getuuidbydev(char *device) { |
446 |
|
if (!blkid) |
447 |
|
blkid_get_cache(&blkid, NULL); |
448 |
|
|
449 |
|
return blkid_get_tag_value(blkid, "UUID", device); |
450 |
|
} |
451 |
|
|
452 |
static enum lineType_e getTypeByKeyword(char * keyword, |
static enum lineType_e getTypeByKeyword(char * keyword, |
453 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
454 |
struct keywordTypes * kw; |
struct keywordTypes * kw; |
1162 |
return i; |
return i; |
1163 |
} |
} |
1164 |
|
|
1165 |
|
static char *findDiskForRoot() |
1166 |
|
{ |
1167 |
|
int fd; |
1168 |
|
char buf[65536]; |
1169 |
|
char *devname; |
1170 |
|
char *chptr; |
1171 |
|
int rc; |
1172 |
|
|
1173 |
|
if ((fd = open(_PATH_MOUNTED, O_RDONLY)) < 0) { |
1174 |
|
fprintf(stderr, "grubby: failed to open %s: %s\n", |
1175 |
|
_PATH_MOUNTED, strerror(errno)); |
1176 |
|
return NULL; |
1177 |
|
} |
1178 |
|
|
1179 |
|
rc = read(fd, buf, sizeof(buf) - 1); |
1180 |
|
if (rc <= 0) { |
1181 |
|
fprintf(stderr, "grubby: failed to read %s: %s\n", |
1182 |
|
_PATH_MOUNTED, strerror(errno)); |
1183 |
|
close(fd); |
1184 |
|
return NULL; |
1185 |
|
} |
1186 |
|
close(fd); |
1187 |
|
buf[rc] = '\0'; |
1188 |
|
chptr = buf; |
1189 |
|
|
1190 |
|
while (chptr && chptr != buf+rc) { |
1191 |
|
devname = chptr; |
1192 |
|
|
1193 |
|
/* |
1194 |
|
* The first column of a mtab entry is the device, but if the entry is a |
1195 |
|
* special device it won't start with /, so move on to the next line. |
1196 |
|
*/ |
1197 |
|
if (*devname != '/') { |
1198 |
|
chptr = strchr(chptr, '\n'); |
1199 |
|
if (chptr) |
1200 |
|
chptr++; |
1201 |
|
continue; |
1202 |
|
} |
1203 |
|
|
1204 |
|
/* Seek to the next space */ |
1205 |
|
chptr = strchr(chptr, ' '); |
1206 |
|
if (!chptr) { |
1207 |
|
fprintf(stderr, "grubby: error parsing %s: %s\n", |
1208 |
|
_PATH_MOUNTED, strerror(errno)); |
1209 |
|
return NULL; |
1210 |
|
} |
1211 |
|
|
1212 |
|
/* |
1213 |
|
* The second column of a mtab entry is the mount point, we are looking |
1214 |
|
* for '/' obviously. |
1215 |
|
*/ |
1216 |
|
if (*(++chptr) == '/' && *(++chptr) == ' ') { |
1217 |
|
/* |
1218 |
|
* Move back 2, which is the first space after the device name, set |
1219 |
|
* it to \0 so strdup will just get the devicename. |
1220 |
|
*/ |
1221 |
|
chptr -= 2; |
1222 |
|
*chptr = '\0'; |
1223 |
|
return strdup(devname); |
1224 |
|
} |
1225 |
|
|
1226 |
|
/* Next line */ |
1227 |
|
chptr = strchr(chptr, '\n'); |
1228 |
|
if (chptr) |
1229 |
|
chptr++; |
1230 |
|
} |
1231 |
|
|
1232 |
|
return NULL; |
1233 |
|
} |
1234 |
|
|
1235 |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
1236 |
int skipRemoved, int flags) { |
int skipRemoved, int flags) { |
1237 |
struct singleLine * line; |
struct singleLine * line; |
1238 |
char * fullName; |
char * fullName; |
1239 |
int i; |
int i; |
|
struct stat sb, sb2; |
|
1240 |
char * dev; |
char * dev; |
1241 |
char * rootspec; |
char * rootspec; |
1242 |
|
char * rootdev; |
1243 |
|
|
1244 |
if (skipRemoved && entry->skip) return 0; |
if (skipRemoved && entry->skip) return 0; |
1245 |
|
|
1289 |
if (!dev) |
if (!dev) |
1290 |
return 0; |
return 0; |
1291 |
|
|
1292 |
i = stat(dev, &sb); |
rootdev = findDiskForRoot(); |
1293 |
if (i) |
if (!rootdev) |
1294 |
return 0; |
return 0; |
1295 |
|
|
1296 |
stat("/", &sb2); |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
1297 |
|
free(rootdev); |
1298 |
|
return 0; |
1299 |
|
} |
1300 |
|
|
1301 |
if (sb.st_rdev != sb2.st_dev) |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
1302 |
|
free(rootdev); |
1303 |
return 0; |
return 0; |
1304 |
|
} |
1305 |
|
|
1306 |
|
free(rootdev); |
1307 |
|
|
1308 |
return 1; |
return 1; |
1309 |
} |
} |
1666 |
char * start; |
char * start; |
1667 |
char * param; |
char * param; |
1668 |
|
|
1669 |
in = fopen("/etc/sysconfig/grub", "r"); |
in = fopen("/etc/conf.d/grub", "r"); |
1670 |
if (!in) return 1; |
if (!in) return 1; |
1671 |
|
|
1672 |
if (lbaPtr) *lbaPtr = 0; |
if (lbaPtr) *lbaPtr = 0; |
1728 |
return 1; |
return 1; |
1729 |
} |
} |
1730 |
|
|
1731 |
/* this is a horrible hack to support /etc/sysconfig/grub; there must |
/* this is a horrible hack to support /etc/conf.d/grub; there must |
1732 |
be a better way */ |
be a better way */ |
1733 |
if (config->cfi == &grubConfigType) { |
if (config->cfi == &grubConfigType) { |
1734 |
dumpSysconfigGrub(); |
dumpSysconfigGrub(); |
1979 |
const char ** arg; |
const char ** arg; |
1980 |
int useKernelArgs, useRoot; |
int useKernelArgs, useRoot; |
1981 |
int firstElement; |
int firstElement; |
1982 |
int *usedElements, *usedArgs; |
int *usedElements; |
1983 |
int doreplace; |
int doreplace; |
1984 |
|
|
1985 |
if (!image) return 0; |
if (!image) return 0; |
2014 |
useRoot = (getKeywordByType(LT_ROOT, cfg->cfi) |
useRoot = (getKeywordByType(LT_ROOT, cfg->cfi) |
2015 |
&& !multibootArgs); |
&& !multibootArgs); |
2016 |
|
|
|
for (k = 0, arg = newArgs; *arg; arg++, k++) ; |
|
|
usedArgs = calloc(k, sizeof(*usedArgs)); |
|
|
|
|
2017 |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
2018 |
|
|
2019 |
if (multibootArgs && !entry->multiboot) |
if (multibootArgs && !entry->multiboot) |
2089 |
usedElements = calloc(line->numElements, sizeof(*usedElements)); |
usedElements = calloc(line->numElements, sizeof(*usedElements)); |
2090 |
|
|
2091 |
for (k = 0, arg = newArgs; *arg; arg++, k++) { |
for (k = 0, arg = newArgs; *arg; arg++, k++) { |
|
if (usedArgs[k]) continue; |
|
2092 |
|
|
2093 |
doreplace = 1; |
doreplace = 1; |
2094 |
for (i = firstElement; i < line->numElements; i++) { |
for (i = firstElement; i < line->numElements; i++) { |
2103 |
continue; |
continue; |
2104 |
if (!argMatch(line->elements[i].item, *arg)) { |
if (!argMatch(line->elements[i].item, *arg)) { |
2105 |
usedElements[i]=1; |
usedElements[i]=1; |
|
usedArgs[k]=1; |
|
2106 |
break; |
break; |
2107 |
} |
} |
2108 |
} |
} |
2172 |
} |
} |
2173 |
} |
} |
2174 |
|
|
|
free(usedArgs); |
|
2175 |
free(newArgs); |
free(newArgs); |
2176 |
free(oldArgs); |
free(oldArgs); |
2177 |
|
|
2197 |
return rc; |
return rc; |
2198 |
} |
} |
2199 |
|
|
2200 |
|
int updateInitrd(struct grubConfig * cfg, const char * image, |
2201 |
|
const char * prefix, const char * initrd) { |
2202 |
|
struct singleEntry * entry; |
2203 |
|
struct singleLine * line, * kernelLine; |
2204 |
|
int index = 0; |
2205 |
|
|
2206 |
|
if (!image) return 0; |
2207 |
|
|
2208 |
|
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
2209 |
|
kernelLine = getLineByType(LT_KERNEL, entry->lines); |
2210 |
|
if (!kernelLine) continue; |
2211 |
|
|
2212 |
|
line = getLineByType(LT_INITRD, entry->lines); |
2213 |
|
if (line) |
2214 |
|
removeLine(entry, line); |
2215 |
|
if (prefix) { |
2216 |
|
int prefixLen = strlen(prefix); |
2217 |
|
if (!strncmp(initrd, prefix, prefixLen)) |
2218 |
|
initrd += prefixLen; |
2219 |
|
} |
2220 |
|
line = addLine(entry, cfg->cfi, LT_INITRD, kernelLine->indent, initrd); |
2221 |
|
if (!line) return 1; |
2222 |
|
break; |
2223 |
|
} |
2224 |
|
|
2225 |
|
return 0; |
2226 |
|
} |
2227 |
|
|
2228 |
int checkDeviceBootloader(const char * device, const unsigned char * boot) { |
int checkDeviceBootloader(const char * device, const unsigned char * boot) { |
2229 |
int fd; |
int fd; |
2230 |
unsigned char bootSect[512]; |
unsigned char bootSect[512]; |
3054 |
if (newKernelPath && !newKernelTitle) { |
if (newKernelPath && !newKernelTitle) { |
3055 |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
3056 |
return 1; |
return 1; |
3057 |
} else if (!newKernelPath && (newKernelTitle || newKernelInitrd || |
} else if (!newKernelPath && (newKernelTitle || copyDefault || |
3058 |
newKernelInitrd || copyDefault || |
(newKernelInitrd && !updateKernelPath)|| |
3059 |
makeDefault || extraInitrdCount > 0)) { |
makeDefault || extraInitrdCount > 0)) { |
3060 |
fprintf(stderr, _("grubby: kernel path expected\n")); |
fprintf(stderr, _("grubby: kernel path expected\n")); |
3061 |
return 1; |
return 1; |
3188 |
setFallbackImage(config, newKernelPath != NULL); |
setFallbackImage(config, newKernelPath != NULL); |
3189 |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
3190 |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
3191 |
|
if (updateKernelPath && newKernelInitrd) { |
3192 |
|
if (updateInitrd(config, updateKernelPath, bootPrefix, |
3193 |
|
newKernelInitrd)) return 1; |
3194 |
|
} |
3195 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
3196 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
3197 |
extraInitrds, extraInitrdCount, |
extraInitrds, extraInitrdCount, |