164 |
|
|
165 |
const char *grubFindConfig(struct configFileInfo *cfi) { |
const char *grubFindConfig(struct configFileInfo *cfi) { |
166 |
static const char *configFiles[] = { |
static const char *configFiles[] = { |
|
"/etc/grub.conf", |
|
167 |
"/boot/grub/grub.conf", |
"/boot/grub/grub.conf", |
168 |
"/boot/grub/menu.lst", |
"/boot/grub/menu.lst", |
169 |
|
"/etc/grub.conf", |
170 |
NULL |
NULL |
171 |
}; |
}; |
172 |
static int i = -1; |
static int i = -1; |
2350 |
char * boot = NULL; |
char * boot = NULL; |
2351 |
int lba; |
int lba; |
2352 |
|
|
2353 |
if (!isSuseSystem()) { |
if (isSuseSystem()) { |
2354 |
if (parseSysconfigGrub(&lba, &boot)) { |
if (parseSuseGrubConf(&lba, &boot)) { |
2355 |
free(boot); |
free(boot); |
2356 |
return; |
return; |
2357 |
} |
} |
2358 |
} else { |
} else { |
2359 |
if (parseSuseGrubConf(&lba, &boot)) { |
if (parseSysconfigGrub(&lba, &boot)) { |
2360 |
free(boot); |
free(boot); |
2361 |
return; |
return; |
2362 |
} |
} |
3179 |
int fd; |
int fd; |
3180 |
unsigned char bootSect[512]; |
unsigned char bootSect[512]; |
3181 |
char * boot; |
char * boot; |
3182 |
int onSuse; |
int onSuse = isSuseSystem(); |
3183 |
|
|
3184 |
|
|
3185 |
onSuse = isSuseSystem(); |
if (onSuse) { |
3186 |
if (!onSuse) { |
if (parseSuseGrubConf(NULL, &boot)) |
3187 |
if (parseSysconfigGrub(NULL, &boot)) return 0; |
return 0; |
3188 |
} else { |
} else { |
3189 |
if (parseSuseGrubConf(NULL, &boot)) return 0; |
if (parseSysconfigGrub(NULL, &boot)) |
3190 |
|
return 0; |
3191 |
} |
} |
3192 |
|
|
3193 |
/* assume grub is not installed -- not an error condition */ |
/* assume grub is not installed -- not an error condition */ |
3207 |
} |
} |
3208 |
close(fd); |
close(fd); |
3209 |
|
|
3210 |
if (!onSuse) |
/* The more elaborate checks do not work on SuSE. The checks done |
3211 |
return checkDeviceBootloader(boot, bootSect); |
* seem to be reasonble (at least for now), so just return success |
3212 |
else |
*/ |
3213 |
/* |
if (onSuse) |
|
* The more elaborate checks do not work on SuSE. The checks done |
|
|
* seem to be reasonble (at least for now), so just return success |
|
|
*/ |
|
3214 |
return 2; |
return 2; |
3215 |
|
|
3216 |
|
return checkDeviceBootloader(boot, bootSect); |
3217 |
} |
} |
3218 |
|
|
3219 |
int checkForExtLinux(struct grubConfig * config) { |
int checkForExtLinux(struct grubConfig * config) { |
3246 |
return checkDeviceBootloader(boot, bootSect); |
return checkDeviceBootloader(boot, bootSect); |
3247 |
} |
} |
3248 |
|
|
3249 |
|
int checkForYaboot(struct grubConfig * config) { |
3250 |
|
/* |
3251 |
|
* This is a simplistic check that we consider good enough for own puporses |
3252 |
|
* |
3253 |
|
* If we were to properly check if yaboot is *installed* we'd need to: |
3254 |
|
* 1) get the system boot device (LT_BOOT) |
3255 |
|
* 2) considering it's a raw filesystem, check if the yaboot binary matches |
3256 |
|
* the content on the boot device |
3257 |
|
* 3) if not, copy the binary to a temporary file and run "addnote" on it |
3258 |
|
* 4) check again if binary and boot device contents match |
3259 |
|
*/ |
3260 |
|
if (!access("/etc/yaboot.conf", R_OK)) |
3261 |
|
return 2; |
3262 |
|
|
3263 |
|
return 1; |
3264 |
|
} |
3265 |
|
|
3266 |
|
int checkForElilo(struct grubConfig * config) { |
3267 |
|
if (!access("/etc/elilo.conf", R_OK)) |
3268 |
|
return 2; |
3269 |
|
|
3270 |
|
return 1; |
3271 |
|
} |
3272 |
|
|
3273 |
static char * getRootSpecifier(char * str) { |
static char * getRootSpecifier(char * str) { |
3274 |
char * idx, * rootspec = NULL; |
char * idx, * rootspec = NULL; |
3275 |
|
|
3757 |
{ "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0, |
{ "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0, |
3758 |
_("filestystem which contains /boot directory (for testing only)"), |
_("filestystem which contains /boot directory (for testing only)"), |
3759 |
_("bootfs") }, |
_("bootfs") }, |
3760 |
#if defined(__i386__) || defined(__x86_64__) |
#if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__) || defined (__ia64__) |
3761 |
{ "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0, |
{ "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0, |
3762 |
_("check if lilo is installed on lilo.conf boot sector") }, |
_("check which bootloader is installed on boot sector") }, |
3763 |
#endif |
#endif |
3764 |
{ "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0, |
{ "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0, |
3765 |
_("path to grub config file to update (\"-\" for stdin)"), |
_("path to grub config file to update (\"-\" for stdin)"), |
3999 |
} |
} |
4000 |
|
|
4001 |
if (bootloaderProbe) { |
if (bootloaderProbe) { |
4002 |
int lrc = 0, grc = 0, gr2c = 0, erc = 0; |
int lrc = 0, grc = 0, gr2c = 0, extrc = 0, yrc = 0, erc = 0; |
4003 |
struct grubConfig * lconfig, * gconfig; |
struct grubConfig * lconfig, * gconfig, * yconfig, * econfig; |
4004 |
|
|
4005 |
const char *grub2config = grub2FindConfig(&grub2ConfigType); |
const char *grub2config = grub2FindConfig(&grub2ConfigType); |
4006 |
if (grub2config) { |
if (grub2config) { |
4028 |
lrc = checkForLilo(lconfig); |
lrc = checkForLilo(lconfig); |
4029 |
} |
} |
4030 |
|
|
4031 |
|
if (!access(eliloConfigType.defaultConfig, F_OK)) { |
4032 |
|
econfig = readConfig(eliloConfigType.defaultConfig, |
4033 |
|
&eliloConfigType); |
4034 |
|
if (!econfig) |
4035 |
|
erc = 1; |
4036 |
|
else |
4037 |
|
erc = checkForElilo(econfig); |
4038 |
|
} |
4039 |
|
|
4040 |
if (!access(extlinuxConfigType.defaultConfig, F_OK)) { |
if (!access(extlinuxConfigType.defaultConfig, F_OK)) { |
4041 |
lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType); |
lconfig = readConfig(extlinuxConfigType.defaultConfig, &extlinuxConfigType); |
4042 |
if (!lconfig) |
if (!lconfig) |
4043 |
erc = 1; |
extrc = 1; |
4044 |
else |
else |
4045 |
erc = checkForExtLinux(lconfig); |
extrc = checkForExtLinux(lconfig); |
4046 |
} |
} |
4047 |
|
|
4048 |
if (lrc == 1 || grc == 1 || gr2c == 1) return 1; |
|
4049 |
|
if (!access(yabootConfigType.defaultConfig, F_OK)) { |
4050 |
|
yconfig = readConfig(yabootConfigType.defaultConfig, |
4051 |
|
&yabootConfigType); |
4052 |
|
if (!yconfig) |
4053 |
|
yrc = 1; |
4054 |
|
else |
4055 |
|
yrc = checkForYaboot(lconfig); |
4056 |
|
} |
4057 |
|
|
4058 |
|
if (lrc == 1 || grc == 1 || gr2c == 1 || extrc == 1 || yrc == 1 || |
4059 |
|
erc == 1) |
4060 |
|
return 1; |
4061 |
|
|
4062 |
if (lrc == 2) printf("lilo\n"); |
if (lrc == 2) printf("lilo\n"); |
4063 |
if (gr2c == 2) printf("grub2\n"); |
if (gr2c == 2) printf("grub2\n"); |
4064 |
if (grc == 2) printf("grub\n"); |
if (grc == 2) printf("grub\n"); |
4065 |
if (erc == 2) printf("extlinux\n"); |
if (extrc == 2) printf("extlinux\n"); |
4066 |
|
if (yrc == 2) printf("yaboot\n"); |
4067 |
|
if (erc == 2) printf("elilo\n"); |
4068 |
|
|
4069 |
return 0; |
return 0; |
4070 |
} |
} |