installer: Install GRUB2 instead of GRUB legacy.

This commit is contained in:
Michael Tremer
2014-07-24 14:22:22 +02:00
parent 268090a891
commit f5007e9c99
4 changed files with 48 additions and 21 deletions

View File

@@ -79,7 +79,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
--prefix=/usr \
--sysconfdir=/etc \
--with-platform=pc \
--with-grubdir=grub2 \
--with-grubdir=grub \
--program-transform-name=s,grub,grub, \
--disable-grub-mount \
--disable-werror

View File

@@ -47,6 +47,14 @@ const char* other_filesystems[] = {
NULL
};
static int system_chroot(const char* path, const char* cmd) {
char chroot_cmd[STRING_SIZE];
snprintf(chroot_cmd, sizeof(chroot_cmd), "/usr/sbin/chroot %s %s", path, cmd);
return mysystem(chroot_cmd);
}
struct hw* hw_init() {
struct hw* hw = malloc(sizeof(*hw));
assert(hw);
@@ -460,7 +468,7 @@ int hw_create_partitions(struct hw_destination* dest) {
else if (dest->part_table == HW_PART_TABLE_GPT)
asprintf(&cmd, "%s mklabel gpt", cmd);
unsigned long long part_start = 0 * 1024 * 1024; // 1MB
unsigned long long part_start = 1 * 1024 * 1024; // 1MB
if (*dest->part_boot) {
asprintf(&cmd, "%s mkpart %s ext2 %lluMB %lluMB", cmd,
@@ -707,7 +715,7 @@ int hw_setup_raid(struct hw_destination* dest) {
assert(dest->is_raid);
asprintf(&cmd, "echo \"y\" | /sbin/mdadm --create --verbose --metadata=0.9 %s", dest->path);
asprintf(&cmd, "echo \"y\" | /sbin/mdadm --create --verbose --metadata=1.2 %s", dest->path);
switch (dest->raid_level) {
case 1:
@@ -752,3 +760,32 @@ int hw_setup_raid(struct hw_destination* dest) {
int hw_stop_all_raid_arrays() {
return mysystem("/sbin/mdadm --stop --scan");
}
int hw_install_bootloader(struct hw_destination* dest) {
char cmd[STRING_SIZE];
int r;
// Generate configuration file
snprintf(cmd, sizeof(cmd), "/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg");
r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
if (r)
return r;
char cmd_grub[STRING_SIZE];
snprintf(cmd_grub, sizeof(cmd_grub), "/usr/sbin/grub-install --no-floppy --recheck");
if (dest->is_raid) {
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk1->path);
r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
if (r)
return r;
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk2->path);
r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
} else {
snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->path);
r = system_chroot(DESTINATION_MOUNT_PATH, cmd);
}
return r;
}

View File

@@ -116,4 +116,6 @@ int hw_umount_filesystems(struct hw_destination* dest, const char* prefix);
int hw_setup_raid(struct hw_destination* dest);
int hw_stop_all_raid_arrays();
int hw_install_bootloader(struct hw_destination* dest);
#endif /* HEADER_HW_H */

View File

@@ -528,31 +528,19 @@ int main(int argc, char *argv[]) {
snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE4#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_data);
system(commandstring);
replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION);
snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#root=ROOT#root=UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/boot/grub/grub.conf", destination->part_root);
system(commandstring);
mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab");
/*
* Generate device.map to help grub finding the device to install itself on.
*/
FILE *f = NULL;
if (f = fopen("/harddisk/boot/grub/device.map", "w")) {
fprintf(f, "(hd0) %s\n", destination->path);
fclose(f);
}
// Installing bootloader...
statuswindow(60, 4, title, ctr[TR_INSTALLING_GRUB]);
snprintf(commandstring, STRING_SIZE,
"/usr/sbin/chroot /harddisk /usr/sbin/grub-install --no-floppy %s", destination->path);
if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
rc = hw_install_bootloader(destination);
if (rc) {
errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
goto EXIT;
}
newtPopWindow();
/* Serial console ? */
if (serialconsole) {
/* grub */