mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-25 10:22:59 +02:00
installer: Write fstab
This commit is contained in:
@@ -843,3 +843,72 @@ int hw_install_bootloader(struct hw_destination* dest) {
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static char* hw_get_uuid(const char* dev) {
|
||||
blkid_probe p = blkid_new_probe_from_filename(dev);
|
||||
const char* buffer = NULL;
|
||||
char* uuid = NULL;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
blkid_do_probe(p);
|
||||
blkid_probe_lookup_value(p, "UUID", &buffer, NULL);
|
||||
|
||||
if (buffer)
|
||||
uuid = strdup(buffer);
|
||||
|
||||
blkid_free_probe(p);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
int hw_write_fstab(struct hw_destination* dest) {
|
||||
FILE* f = fopen(DESTINATION_MOUNT_PATH "/etc/fstab", "w");
|
||||
if (!f)
|
||||
return -1;
|
||||
|
||||
const char* fmt = "UUID=%s %-8s %-4s %-10s %d %d\n";
|
||||
char* uuid = NULL;
|
||||
|
||||
// boot
|
||||
if (*dest->part_boot) {
|
||||
uuid = hw_get_uuid(dest->part_boot);
|
||||
|
||||
if (uuid) {
|
||||
fprintf(f, fmt, uuid, "/boot", "auto", "defaults", 1, 2);
|
||||
free(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
// swap
|
||||
if (*dest->part_swap) {
|
||||
uuid = hw_get_uuid(dest->part_swap);
|
||||
|
||||
if (uuid) {
|
||||
fprintf(f, fmt, uuid, "swap", "swap", "defaults,pri=1", 0, 0);
|
||||
free(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
// root
|
||||
uuid = hw_get_uuid(dest->part_root);
|
||||
if (uuid) {
|
||||
fprintf(f, fmt, uuid, "/", "auto", "defaults", 1, 1);
|
||||
free(uuid);
|
||||
}
|
||||
|
||||
// data
|
||||
if (*dest->part_data) {
|
||||
uuid = hw_get_uuid(dest->part_data);
|
||||
|
||||
if (uuid) {
|
||||
fprintf(f, fmt, uuid, "/var", "auto", "defaults", 1, 1);
|
||||
free(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -120,5 +120,6 @@ int hw_setup_raid(struct hw_destination* dest);
|
||||
int hw_stop_all_raid_arrays();
|
||||
|
||||
int hw_install_bootloader(struct hw_destination* dest);
|
||||
int hw_write_fstab(struct hw_destination* dest);
|
||||
|
||||
#endif /* HEADER_HW_H */
|
||||
|
||||
@@ -508,7 +508,14 @@ int main(int argc, char *argv[]) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
|
||||
// Write fstab
|
||||
rc = hw_write_fstab(destination);
|
||||
if (rc) {
|
||||
fprintf(flog, "Could not write /etc/fstab\n");
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
/* Save language und local settings */
|
||||
write_lang_configs(shortlangname);
|
||||
|
||||
@@ -520,18 +527,6 @@ int main(int argc, char *argv[]) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
/* Update /etc/fstab */
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE1#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_boot);
|
||||
system(commandstring);
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE2#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_swap);
|
||||
system(commandstring);
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/sed -i -e \"s#DEVICE3#UUID=$(/sbin/blkid %s -sUUID | /usr/bin/cut -d'\"' -f2)#g\" /harddisk/etc/fstab", destination->part_root);
|
||||
system(commandstring);
|
||||
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);
|
||||
|
||||
system("/bin/sed -e 's#/harddisk#/#g' -e 's#//#/#g' < /proc/mounts > /harddisk/etc/mtab");
|
||||
|
||||
// Installing bootloader...
|
||||
statuswindow(60, 4, title, ctr[TR_INSTALLING_GRUB]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user