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);
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,
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:
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;
+}
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 */