mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-10 02:55:55 +02:00
installer: Rewrite partitioning.
The installer now uses parted for partitioning and support for EXT2 and EXT3 has been dropped.
This commit is contained in:
@@ -349,6 +349,16 @@ char *de_tr[] = {
|
||||
"Das Installationsprogramm wird nun eine RAID-Konfiguration auf den ausgewählten Festplatten anlegen:\n\n %s\n %s\n\nMöchten Sie fortfahren?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Alle Daten löschen",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"Ihre gewünschte Auswahl wird derzeit nicht unterstützt.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Erstelle Dateisysteme...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Die Dateisysteme konnten nicht erstellt werden.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Hänge Dateisysteme ein...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Die Dateisysteme konnten nicht eingehangen werden.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"Auf dem Webserver wurde kein ipcop-Tarball gefunden.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -591,14 +601,12 @@ char *de_tr[] = {
|
||||
"Ich akzeptiere diese Lizenz.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Die Lizenz wurde nicht akzeptiert. Abbruch!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Dateisystem ohne Journal (empfohlen für Flash)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Dateisystem mit Journal",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Dateisystem mit Journal",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Dateisystem mit Journal",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Dateisystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Dateisystem ohne Journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Dateisystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Kein lokales Quellmedium gefunden. Starte Download.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -347,6 +347,14 @@ char *en_tr[] = {
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"No ipcop tarball found on Web Server.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -589,14 +597,12 @@ char *en_tr[] = {
|
||||
"I accept this license.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"License not accepted. Exit!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Filesystem without journal (suggested for flashdrives)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Filesystem with journal",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Filesystem with journal",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Filesystem with journal",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"No local source media found. Starting download.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -341,6 +341,16 @@ char *es_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"No se encontró ningun archivo tarball de ipcop en el servidor web",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -583,14 +593,12 @@ char *es_tr[] = {
|
||||
"I accept this license.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"License not accepted. Exit!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Filesystem without journal (suggested for flashdrives)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Filesystem with journal",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Filesystem with journal",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Filesystem with journal",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"No local source media found. Starting download.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -341,6 +341,16 @@ char *fr_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"Aucun tarball ipcop trouvé sur le serveur Web.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -583,14 +593,12 @@ char *fr_tr[] = {
|
||||
"J'accepte les termes de cette licence.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Je n'accepte pas les termes de cette licence, quitter le programme d'installation.",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Système de fichiers sans journal (suggéré pour les cartes flash)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Système de fichiers avec journal",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Système de fichiers avec journal",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Système de fichiers avec journal",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Pas de source locale trouvée. Démarrage du téléchargement.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -345,6 +345,16 @@ char *nl_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"Er is geen ipcop tarball gevonden op de webserver.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -587,14 +597,12 @@ char *nl_tr[] = {
|
||||
"Ik accepteer deze licentie.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Licentie niet geaccepteerd. Stopt!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Bestandssysteem zonder journal (geschikt voor flashdrives)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Bestandssysteem met journal",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Bestandssysteem met journal",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Bestandssysteem met journal",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Geen lokale bronmedia gevonden. Start download.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -341,6 +341,16 @@ char *pl_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"Nie znaleziono archiwum tar ipcop na serwerze Web.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -583,14 +593,12 @@ char *pl_tr[] = {
|
||||
"Akceptuję licencję.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Nie zaakceptowano licencji.Wyjście!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - System plików bez dziennika (zalecany dla napędów flash)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - System plików z dziennikiem",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - System plików z dziennikiem",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - System plików z dziennikiem",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Brak lokalnego źródła. Rozpoczynanie pobierania.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -339,6 +339,16 @@ char *ru_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"На сервере не найден архив ipcop.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -581,14 +591,12 @@ char *ru_tr[] = {
|
||||
"Я принимаю эту лицензию.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Лицензия не принята. Выход!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Файловая система без журналирования (Рекомендуется для флеш-носителей)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Файловая система с журналированием",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Файловая система с журналированием",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Файловая система с журналированием",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Локальный источник не найден. Начинаю загрузку.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -345,6 +345,16 @@ char *tr_tr[] = {
|
||||
"The installation program will now set up a RAID configuration on the selected harddisks:\n\n %s\n %s\n\nDo you agree to continue?",
|
||||
/* TR_DELETE_ALL_DATA */
|
||||
"Delete all data",
|
||||
/* TR_DISK_CONFIGURATION_NOT_SUPPORTED */
|
||||
"You disk configuration is currently not supported.",
|
||||
/* TR_CREATING_FILESYSTEMS */
|
||||
"Creating filesystems...",
|
||||
/* TR_UNABLE_TO_CREATE_FILESYSTEMS */
|
||||
"Unable to create filesystems.",
|
||||
/* TR_MOUNTING_FILESYSTEMS */
|
||||
"Mounting filesystems...",
|
||||
/* TR_UNABLE_TO_MOUNT_FILESYSTEMS */
|
||||
"Unable to mount filesystems.",
|
||||
/* TR_NO_IPCOP_TARBALL_FOUND */
|
||||
"Web sunucuda hiçbir ipfire arşivi bulunamadı.",
|
||||
/* TR_NO_ORANGE_INTERFACE */
|
||||
@@ -587,14 +597,12 @@ char *tr_tr[] = {
|
||||
"Bu lisansı kabul ediyorum.",
|
||||
/* TR_LICENSE_NOT_ACCEPTED */
|
||||
"Lisans kabul edilmedi. Çık!",
|
||||
/* TR_EXT2FS_DESCR */
|
||||
"Ext2 - Günlük olmadan dosya sistemi (flash sürücüler için önerilen)",
|
||||
/* TR_EXT3FS_DESCR */
|
||||
"Ext3 - Günlük ile dosya sistemi",
|
||||
/* TR_EXT4FS_DESCR */
|
||||
"Ext4 - Günlük ile dosya sistemi",
|
||||
/* TR_REISERFS_DESCR */
|
||||
"ReiserFS - Günlük ile dosya sistemi",
|
||||
/* TR_EXT4FS */
|
||||
"EXT4 - Filesystem",
|
||||
/* TR_EXT4FS_WO_JOURNAL */
|
||||
"EXT4 - Filesystem without journal",
|
||||
/* TR_REISERFS */
|
||||
"ReiserFS - Filesystem",
|
||||
/* TR_NO_LOCAL_SOURCE */
|
||||
"Yerel kaynak medya bulunamadı. İndirme başlatılıyor.",
|
||||
/* TR_DOWNLOADING_ISO */
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
# #
|
||||
#############################################################################*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <blkid/blkid.h>
|
||||
#include <fcntl.h>
|
||||
@@ -28,11 +32,20 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/swap.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "hw.h"
|
||||
#include "../libsmooth/libsmooth.h"
|
||||
|
||||
const char* other_filesystems[] = {
|
||||
"/dev",
|
||||
"/proc",
|
||||
"/sys",
|
||||
NULL
|
||||
};
|
||||
|
||||
struct hw* hw_init() {
|
||||
struct hw* hw = malloc(sizeof(*hw));
|
||||
@@ -59,8 +72,8 @@ static int strstartswith(const char* a, const char* b) {
|
||||
return (strncmp(a, b, strlen(b)) == 0);
|
||||
}
|
||||
|
||||
int hw_mount(const char* source, const char* target, int flags) {
|
||||
return mount(source, target, "iso9660", flags, NULL);
|
||||
int hw_mount(const char* source, const char* target, const char* fs, int flags) {
|
||||
return mount(source, target, fs, flags, NULL);
|
||||
}
|
||||
|
||||
int hw_umount(const char* target) {
|
||||
@@ -68,7 +81,7 @@ int hw_umount(const char* target) {
|
||||
}
|
||||
|
||||
static int hw_test_source_medium(const char* path) {
|
||||
int ret = hw_mount(path, SOURCE_MOUNT_PATH, MS_RDONLY);
|
||||
int ret = hw_mount(path, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY);
|
||||
|
||||
// If the source could not be mounted we
|
||||
// cannot proceed.
|
||||
@@ -279,6 +292,112 @@ struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned long long hw_swap_size(struct hw_destination* dest) {
|
||||
unsigned long long memory = hw_memory();
|
||||
|
||||
unsigned long long swap_size = memory / 4;
|
||||
|
||||
// Min. swap size is 128MB
|
||||
if (swap_size < MB2BYTES(128))
|
||||
swap_size = MB2BYTES(128);
|
||||
|
||||
// Cap swap size to 1GB
|
||||
else if (swap_size > MB2BYTES(1024))
|
||||
swap_size = MB2BYTES(1024);
|
||||
|
||||
return swap_size;
|
||||
}
|
||||
|
||||
static unsigned long long hw_root_size(struct hw_destination* dest) {
|
||||
unsigned long long root_size;
|
||||
|
||||
if (dest->size < MB2BYTES(2048))
|
||||
root_size = MB2BYTES(1024);
|
||||
|
||||
else if (dest->size >= MB2BYTES(2048) && dest->size <= MB2BYTES(3072))
|
||||
root_size = MB2BYTES(1536);
|
||||
|
||||
else
|
||||
root_size = MB2BYTES(2048);
|
||||
|
||||
return root_size;
|
||||
}
|
||||
|
||||
static unsigned long long hw_boot_size(struct hw_destination* dest) {
|
||||
return MB2BYTES(64);
|
||||
}
|
||||
|
||||
static int hw_calculate_partition_table(struct hw_destination* dest) {
|
||||
// Determine the size of the target block device
|
||||
if (dest->is_raid) {
|
||||
dest->size = (dest->disk1->size >= dest->disk2->size) ?
|
||||
dest->disk1->size : dest->disk2->size;
|
||||
} else {
|
||||
dest->size = dest->disk1->size;
|
||||
}
|
||||
|
||||
dest->size_boot = hw_boot_size(dest);
|
||||
dest->size_swap = hw_swap_size(dest);
|
||||
dest->size_root = hw_root_size(dest);
|
||||
|
||||
// Determine the size of the data partition.
|
||||
unsigned long long used_space = dest->size_boot + dest->size_swap + dest->size_root;
|
||||
|
||||
// Disk is way too small
|
||||
if (used_space >= dest->size)
|
||||
return -1;
|
||||
|
||||
dest->size_data = dest->size - used_space;
|
||||
|
||||
// If it gets too small, we remove the swap space.
|
||||
if (dest->size_data <= MB2BYTES(256)) {
|
||||
dest->size_data += dest->size_swap;
|
||||
dest->size_swap = 0;
|
||||
}
|
||||
|
||||
// Set partition names
|
||||
char path[DEV_SIZE];
|
||||
int part_idx = 1;
|
||||
|
||||
snprintf(path, sizeof(path), "%s%s", dest->path, (dest->is_raid) ? "p" : "");
|
||||
|
||||
if (dest->size_boot > 0) {
|
||||
dest->part_boot_idx = part_idx;
|
||||
|
||||
snprintf(dest->part_boot, sizeof(dest->part_boot), "%s%d", path, part_idx++);
|
||||
} else
|
||||
*dest->part_boot = '\0';
|
||||
|
||||
if (dest->size_swap > 0)
|
||||
snprintf(dest->part_swap, sizeof(dest->part_swap), "%s%d", path, part_idx++);
|
||||
else
|
||||
*dest->part_swap = '\0';
|
||||
|
||||
// There is always a root partition
|
||||
if (!*dest->part_boot)
|
||||
dest->part_boot_idx = part_idx;
|
||||
|
||||
snprintf(dest->part_root, sizeof(dest->part_root), "%s%d", path, part_idx++);
|
||||
|
||||
if (dest->size_data > 0)
|
||||
snprintf(dest->part_data, sizeof(dest->part_data), "%s%d", path, part_idx++);
|
||||
else
|
||||
*dest->part_data = '\0';
|
||||
|
||||
// Determine partition table
|
||||
dest->part_table = HW_PART_TABLE_MSDOS;
|
||||
|
||||
// Disks over 2TB need to use GPT
|
||||
if (dest->size >= MB2BYTES(2047 * 1024))
|
||||
dest->part_table = HW_PART_TABLE_GPT;
|
||||
|
||||
// We also use GPT on raid disks by default
|
||||
else if (dest->is_raid)
|
||||
dest->part_table = HW_PART_TABLE_GPT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks) {
|
||||
struct hw_destination* dest = malloc(sizeof(*dest));
|
||||
|
||||
@@ -298,20 +417,12 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks
|
||||
// Is this a RAID device?
|
||||
dest->is_raid = (part_type > HW_PART_TYPE_NORMAL);
|
||||
|
||||
// Set partition names
|
||||
char path[DEV_SIZE];
|
||||
snprintf(path, sizeof(path), "%s%s", dest->path, (dest->is_raid) ? "p" : "");
|
||||
snprintf(dest->part_boot, sizeof(dest->part_boot), "%s1", path);
|
||||
snprintf(dest->part_swap, sizeof(dest->part_swap), "%s2", path);
|
||||
snprintf(dest->part_root, sizeof(dest->part_root), "%s3", path);
|
||||
snprintf(dest->part_data, sizeof(dest->part_data), "%s4", path);
|
||||
int r = hw_calculate_partition_table(dest);
|
||||
if (r)
|
||||
return NULL;
|
||||
|
||||
if (dest->is_raid) {
|
||||
dest->size = (dest->disk1->size >= dest->disk2->size) ?
|
||||
dest->disk1->size : dest->disk2->size;
|
||||
} else {
|
||||
dest->size = dest->disk1->size;
|
||||
}
|
||||
// Set default filesystem
|
||||
dest->filesystem = HW_FS_DEFAULT;
|
||||
|
||||
return dest;
|
||||
}
|
||||
@@ -325,7 +436,7 @@ unsigned long long hw_memory() {
|
||||
/* Calculate amount of memory in machine */
|
||||
if ((handle = fopen("/proc/meminfo", "r"))) {
|
||||
while (fgets(line, sizeof(line), handle)) {
|
||||
if (!sscanf (line, "MemTotal: %llu kB", memory)) {
|
||||
if (!sscanf (line, "MemTotal: %llu kB", &memory)) {
|
||||
memory = 0;
|
||||
}
|
||||
}
|
||||
@@ -335,3 +446,232 @@ unsigned long long hw_memory() {
|
||||
|
||||
return memory * 1024;
|
||||
}
|
||||
|
||||
int hw_create_partitions(struct hw_destination* dest) {
|
||||
char* cmd = NULL;
|
||||
|
||||
asprintf(&cmd, "/usr/sbin/parted -s %s -a optimal", dest->path);
|
||||
|
||||
// Set partition type
|
||||
if (dest->part_table == HW_PART_TABLE_MSDOS)
|
||||
asprintf(&cmd, "%s mklabel msdos", cmd);
|
||||
else if (dest->part_table == HW_PART_TABLE_GPT)
|
||||
asprintf(&cmd, "%s mklabel gpt", cmd);
|
||||
|
||||
unsigned long long part_start = 0 * 1024 * 1024; // 1MB
|
||||
|
||||
if (*dest->part_boot) {
|
||||
asprintf(&cmd, "%s mkpart %s ext2 %lluMB %lluMB", cmd,
|
||||
(dest->part_table == HW_PART_TABLE_GPT) ? "BOOT" : "primary",
|
||||
BYTES2MB(part_start), BYTES2MB(part_start + dest->size_boot));
|
||||
|
||||
part_start += dest->size_boot;
|
||||
}
|
||||
|
||||
if (*dest->part_swap) {
|
||||
asprintf(&cmd, "%s mkpart %s linux-swap %lluMB %lluMB", cmd,
|
||||
(dest->part_table == HW_PART_TABLE_GPT) ? "SWAP" : "primary",
|
||||
BYTES2MB(part_start), BYTES2MB(part_start + dest->size_swap));
|
||||
|
||||
part_start += dest->size_swap;
|
||||
}
|
||||
|
||||
if (*dest->part_root) {
|
||||
asprintf(&cmd, "%s mkpart %s ext2 %lluMB %lluMB", cmd,
|
||||
(dest->part_table == HW_PART_TABLE_GPT) ? "ROOT" : "primary",
|
||||
BYTES2MB(part_start), BYTES2MB(part_start + dest->size_root));
|
||||
|
||||
part_start += dest->size_root;
|
||||
}
|
||||
|
||||
if (*dest->part_data) {
|
||||
asprintf(&cmd, "%s mkpart %s ext2 %lluMB %lluMB", cmd,
|
||||
(dest->part_table == HW_PART_TABLE_GPT) ? "DATA" : "primary",
|
||||
BYTES2MB(part_start), BYTES2MB(part_start + dest->size_data));
|
||||
|
||||
part_start += dest->size_data;
|
||||
}
|
||||
|
||||
if (dest->part_table == HW_PART_TABLE_MSDOS && dest->part_boot_idx > 0) {
|
||||
asprintf(&cmd, "%s set %d boot on", cmd, dest->part_boot_idx);
|
||||
|
||||
} else if (dest->part_table == HW_PART_TABLE_GPT) {
|
||||
asprintf(&cmd, "%s disk_set pmbr_boot on", cmd);
|
||||
}
|
||||
|
||||
int r = mysystem(cmd);
|
||||
|
||||
if (cmd)
|
||||
free(cmd);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int hw_format_filesystem(const char* path, int fs) {
|
||||
char cmd[STRING_SIZE] = "\0";
|
||||
|
||||
// Swap
|
||||
if (fs == HW_FS_SWAP) {
|
||||
snprintf(cmd, sizeof(cmd), "/sbin/mkswap -v1 %s &>/dev/null", path);
|
||||
// ReiserFS
|
||||
} else if (fs == HW_FS_REISERFS) {
|
||||
snprintf(cmd, sizeof(cmd), "/sbin/mkreiserfs -f %s ", path);
|
||||
|
||||
// EXT4
|
||||
} else if (fs == HW_FS_EXT4) {
|
||||
snprintf(cmd, sizeof(cmd), "/sbin/mke2fs -T ext4 %s", path);
|
||||
|
||||
// EXT4 w/o journal
|
||||
} else if (fs == HW_FS_EXT4_WO_JOURNAL) {
|
||||
snprintf(cmd, sizeof(cmd), "/sbin/mke2fs -T ext4 -O ^has_journal %s", path);
|
||||
}
|
||||
|
||||
assert(*cmd);
|
||||
|
||||
int r = mysystem(cmd);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int hw_create_filesystems(struct hw_destination* dest) {
|
||||
int r;
|
||||
|
||||
// boot
|
||||
if (*dest->part_boot) {
|
||||
r = hw_format_filesystem(dest->part_boot, dest->filesystem);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
|
||||
// swap
|
||||
if (*dest->part_swap) {
|
||||
r = hw_format_filesystem(dest->part_swap, HW_FS_SWAP);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
|
||||
// root
|
||||
r = hw_format_filesystem(dest->part_root, dest->filesystem);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
// data
|
||||
if (*dest->part_data) {
|
||||
r = hw_format_filesystem(dest->part_data, dest->filesystem);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) {
|
||||
char target[STRING_SIZE];
|
||||
|
||||
assert(*prefix == '/');
|
||||
|
||||
const char* filesystem;
|
||||
switch (dest->filesystem) {
|
||||
case HW_FS_REISERFS:
|
||||
filesystem = "reiserfs";
|
||||
break;
|
||||
|
||||
case HW_FS_EXT4:
|
||||
case HW_FS_EXT4_WO_JOURNAL:
|
||||
filesystem = "ext4";
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// root
|
||||
int r = hw_mount(dest->part_root, prefix, filesystem, 0);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
// boot
|
||||
if (*dest->part_boot) {
|
||||
snprintf(target, sizeof(target), "%s%s", prefix, HW_PATH_BOOT);
|
||||
mkdir(target, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
|
||||
r = hw_mount(dest->part_boot, target, filesystem, 0);
|
||||
if (r) {
|
||||
hw_umount_filesystems(dest, prefix);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// data
|
||||
if (*dest->part_data) {
|
||||
snprintf(target, sizeof(target), "%s%s", prefix, HW_PATH_DATA);
|
||||
mkdir(target, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
|
||||
r = hw_mount(dest->part_data, target, filesystem, 0);
|
||||
if (r) {
|
||||
hw_umount_filesystems(dest, prefix);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// swap
|
||||
if (*dest->part_swap) {
|
||||
r = swapon(dest->part_swap, 0);
|
||||
if (r) {
|
||||
hw_umount_filesystems(dest, prefix);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// bind-mount misc filesystems
|
||||
char** otherfs = other_filesystems;
|
||||
while (*otherfs) {
|
||||
snprintf(target, sizeof(target), "%s%s", prefix, *otherfs);
|
||||
|
||||
mkdir(target, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
r = hw_mount(*otherfs, target, NULL, MS_BIND);
|
||||
if (r) {
|
||||
hw_umount_filesystems(dest, prefix);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
otherfs++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hw_umount_filesystems(struct hw_destination* dest, const char* prefix) {
|
||||
// boot
|
||||
if (*dest->part_boot) {
|
||||
hw_umount(dest->part_boot);
|
||||
}
|
||||
|
||||
// data
|
||||
if (*dest->part_data) {
|
||||
hw_umount(dest->part_data);
|
||||
}
|
||||
|
||||
// root
|
||||
hw_umount(dest->part_root);
|
||||
|
||||
// swap
|
||||
if (*dest->part_swap) {
|
||||
swapoff(dest->part_swap);
|
||||
}
|
||||
|
||||
// misc filesystems
|
||||
char target[STRING_SIZE];
|
||||
char** otherfs = other_filesystems;
|
||||
|
||||
while (*otherfs) {
|
||||
snprintf(target, sizeof(target), "%s%s", prefix, *otherfs++);
|
||||
hw_umount(target);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
#define DESTINATION_MOUNT_PATH "/harddisk"
|
||||
#define SOURCE_MOUNT_PATH "/cdrom"
|
||||
#define SOURCE_TEST_FILE SOURCE_MOUNT_PATH "/" VERSION ".media"
|
||||
|
||||
@@ -30,9 +31,25 @@
|
||||
#define STRING_SIZE 1024
|
||||
#define DEV_SIZE 128
|
||||
|
||||
#define HW_PATH_BOOT "/boot"
|
||||
#define HW_PATH_DATA "/var"
|
||||
|
||||
#define HW_PART_TYPE_NORMAL 0
|
||||
#define HW_PART_TYPE_RAID1 1
|
||||
|
||||
#define HW_PART_TABLE_MSDOS 0
|
||||
#define HW_PART_TABLE_GPT 1
|
||||
|
||||
#define HW_FS_SWAP 0
|
||||
#define HW_FS_REISERFS 1
|
||||
#define HW_FS_EXT4 2
|
||||
#define HW_FS_EXT4_WO_JOURNAL 3
|
||||
|
||||
#define HW_FS_DEFAULT HW_FS_EXT4
|
||||
|
||||
#define BYTES2MB(x) ((x) / 1024 / 1024)
|
||||
#define MB2BYTES(x) ((unsigned long long)(x) * 1024 * 1024)
|
||||
|
||||
struct hw {
|
||||
struct udev *udev;
|
||||
};
|
||||
@@ -51,23 +68,31 @@ struct hw_disk {
|
||||
|
||||
struct hw_destination {
|
||||
char path[DEV_SIZE];
|
||||
unsigned long long size;
|
||||
|
||||
int is_raid;
|
||||
|
||||
const struct hw_disk* disk1;
|
||||
const struct hw_disk* disk2;
|
||||
|
||||
int part_table;
|
||||
char part_boot[DEV_SIZE];
|
||||
char part_swap[DEV_SIZE];
|
||||
char part_root[DEV_SIZE];
|
||||
char part_data[DEV_SIZE];
|
||||
int part_boot_idx;
|
||||
|
||||
int filesystem;
|
||||
|
||||
unsigned long long size;
|
||||
unsigned long long size_boot;
|
||||
unsigned long long size_swap;
|
||||
unsigned long long size_root;
|
||||
unsigned long long size_data;
|
||||
};
|
||||
|
||||
struct hw* hw_init();
|
||||
void hw_free(struct hw* hw);
|
||||
|
||||
int hw_mount(const char* source, const char* target, int flags);
|
||||
int hw_mount(const char* source, const char* target, const char* fs, int flags);
|
||||
int hw_umount(const char* target);
|
||||
|
||||
char* hw_find_source_medium(struct hw* hw);
|
||||
@@ -77,6 +102,14 @@ void hw_free_disks(struct hw_disk** disks);
|
||||
unsigned int hw_count_disks(struct hw_disk** disks);
|
||||
struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection);
|
||||
|
||||
struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks);
|
||||
|
||||
unsigned long long hw_memory();
|
||||
|
||||
int hw_create_partitions(struct hw_destination* dest);
|
||||
int hw_create_filesystems(struct hw_destination* dest);
|
||||
|
||||
int hw_mount_filesystems(struct hw_destination* dest, const char* prefix);
|
||||
int hw_umount_filesystems(struct hw_destination* dest, const char* prefix);
|
||||
|
||||
#endif /* HEADER_HW_H */
|
||||
|
||||
@@ -24,11 +24,6 @@
|
||||
#define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
|
||||
#define LICENSE_FILE "/cdrom/COPYING"
|
||||
|
||||
#define EXT2 0
|
||||
#define EXT3 1
|
||||
#define EXT4 2
|
||||
#define REISERFS 3
|
||||
|
||||
FILE *flog = NULL;
|
||||
char *mylog;
|
||||
|
||||
@@ -160,21 +155,14 @@ int main(int argc, char *argv[]) {
|
||||
char* sourcedrive = NULL;
|
||||
int rc = 0;
|
||||
char commandstring[STRING_SIZE];
|
||||
char mkfscommand[STRING_SIZE];
|
||||
char *fstypes[] = { "ext2", "ext3", "ext4", "ReiserFS", NULL };
|
||||
int fstype = EXT4;
|
||||
int choice;
|
||||
char shortlangname[10];
|
||||
char message[STRING_SIZE];
|
||||
char title[STRING_SIZE];
|
||||
int allok = 0;
|
||||
int allok_fastexit=0;
|
||||
struct keyvalue *ethernetkv = initkeyvalues();
|
||||
FILE *handle, *cmdfile, *copying;
|
||||
char line[STRING_SIZE];
|
||||
char string[STRING_SIZE];
|
||||
long memory = 0, disk = 0;
|
||||
long system_partition, boot_partition, root_partition, swap_file;
|
||||
|
||||
int unattended = 0;
|
||||
int serialconsole = 0;
|
||||
@@ -266,7 +254,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
assert(sourcedrive);
|
||||
|
||||
int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, MS_RDONLY);
|
||||
int r = hw_mount(sourcedrive, SOURCE_MOUNT_PATH, "iso9660", MS_RDONLY);
|
||||
if (r) {
|
||||
fprintf(flog, "Could not mount %s to %s\n", sourcedrive, SOURCE_MOUNT_PATH);
|
||||
fprintf(flog, strerror(errno));
|
||||
@@ -384,191 +372,87 @@ int main(int argc, char *argv[]) {
|
||||
hw_free_disks(disks);
|
||||
|
||||
struct hw_destination* destination = hw_make_destination(part_type, selected_disks);
|
||||
assert(destination);
|
||||
|
||||
if (!destination) {
|
||||
errorbox(ctr[TR_DISK_TOO_SMALL]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
fprintf(flog, "Destination drive: %s\n", destination->path);
|
||||
fprintf(flog, " boot: %s\n", destination->part_boot);
|
||||
fprintf(flog, " swap: %s\n", destination->part_swap);
|
||||
fprintf(flog, " root: %s\n", destination->part_root);
|
||||
fprintf(flog, " data: %s\n", destination->part_data);
|
||||
fprintf(flog, " boot: %s (%lluMB)\n", destination->part_boot, BYTES2MB(destination->size_boot));
|
||||
fprintf(flog, " swap: %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap));
|
||||
fprintf(flog, " root: %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root));
|
||||
fprintf(flog, " data: %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data));
|
||||
|
||||
fstypes[0]=ctr[TR_EXT2FS_DESCR];
|
||||
fstypes[1]=ctr[TR_EXT3FS_DESCR];
|
||||
fstypes[2]=ctr[TR_EXT4FS_DESCR];
|
||||
fstypes[3]=ctr[TR_REISERFS_DESCR];
|
||||
fstypes[4]=NULL;
|
||||
// Warn the user if there is not enough space to create a swap partition
|
||||
if (!unattended && !*destination->part_swap) {
|
||||
rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
|
||||
|
||||
if (!unattended) {
|
||||
sprintf(message, ctr[TR_CHOOSE_FILESYSTEM]);
|
||||
rc = newtWinMenu( ctr[TR_CHOOSE_FILESYSTEM], message,
|
||||
50, 5, 5, 6, fstypes, &fstype, ctr[TR_OK],
|
||||
ctr[TR_CANCEL], NULL);
|
||||
} else {
|
||||
rc = 1;
|
||||
fstype = EXT4;
|
||||
}
|
||||
if (rc == 2)
|
||||
goto EXIT;
|
||||
|
||||
memory = hw_memory() / 1024 / 1024;
|
||||
|
||||
/* Partition, mkswp, mkfs.
|
||||
* before partitioning, first determine the sizes of each
|
||||
* partition. In order to do that we need to know the size of
|
||||
* the disk.
|
||||
*/
|
||||
disk = destination->size / 1024 / 1024;
|
||||
|
||||
fprintf(flog, "Disksize = %ld, memory = %ld", disk, memory);
|
||||
|
||||
/* Calculating Swap-Size dependend of Ram Size */
|
||||
if (memory <= 256)
|
||||
swap_file = 128;
|
||||
else if (memory <= 1024 && memory > 256)
|
||||
swap_file = 256;
|
||||
else
|
||||
swap_file = memory / 4;
|
||||
|
||||
/* Calculating Root-Size dependend of Max Disk Space */
|
||||
if ( disk < 2048 )
|
||||
root_partition = 1024;
|
||||
else if ( disk >= 2048 && disk <= 3072 )
|
||||
root_partition = 1536;
|
||||
else
|
||||
root_partition = 2048;
|
||||
|
||||
|
||||
/* Calculating the amount of free space */
|
||||
boot_partition = 64; /* in MB */
|
||||
system_partition = disk - ( root_partition + swap_file + boot_partition );
|
||||
|
||||
fprintf(flog, ", boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
|
||||
boot_partition, swap_file, system_partition, root_partition);
|
||||
rc = 0;
|
||||
|
||||
if ( (!unattended) && (((disk - (root_partition + swap_file + boot_partition)) < 256 ) && ((disk - (root_partition + boot_partition )) > 256)) ) {
|
||||
rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
|
||||
if (rc == 1){
|
||||
swap_file = 0;
|
||||
system_partition = disk - ( root_partition + swap_file + boot_partition );
|
||||
fprintf(flog, "Changing Swap Size to 0 MB.\n");
|
||||
}
|
||||
else if (rc == 2){
|
||||
fprintf(flog, "Disk is too small.\n");
|
||||
errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
|
||||
}
|
||||
}
|
||||
else if (disk - (root_partition + swap_file + boot_partition) >= 256) {
|
||||
|
||||
}
|
||||
else {
|
||||
fprintf(flog, "Disk is too small.\n");
|
||||
errorbox(ctr[TR_DISK_TOO_SMALL]);goto EXIT;
|
||||
}
|
||||
|
||||
handle = fopen("/tmp/partitiontable", "w");
|
||||
|
||||
/* Make swapfile */
|
||||
if (swap_file) {
|
||||
fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
|
||||
boot_partition, swap_file, root_partition);
|
||||
} else {
|
||||
fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
|
||||
boot_partition, root_partition);
|
||||
}
|
||||
|
||||
fclose(handle);
|
||||
|
||||
if (disk < 2097150) {
|
||||
// <2TB use sfdisk and normal mbr
|
||||
snprintf(commandstring, STRING_SIZE, "/sbin/sfdisk -L -uM %s < /tmp/partitiontable", destination->path);
|
||||
} else {
|
||||
// >2TB use parted with gpt
|
||||
snprintf(commandstring, STRING_SIZE, "/usr/sbin/parted -s %s mklabel gpt mkpart boot ext2 1M 64M mkpart swap linux-swap 64M 1000M mkpart root ext4 1000M 5000M mkpart var ext4 5000M 100%% disk_set pmbr_boot on", destination->path);
|
||||
if (rc != 1)
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
|
||||
{
|
||||
// Filesystem selection
|
||||
if (!unattended) {
|
||||
struct filesystems {
|
||||
int fstype;
|
||||
const char* description;
|
||||
} filesystems[] = {
|
||||
{ HW_FS_EXT4, ctr[TR_EXT4FS] },
|
||||
{ HW_FS_EXT4_WO_JOURNAL, ctr[TR_EXT4FS_WO_JOURNAL] },
|
||||
{ HW_FS_REISERFS, ctr[TR_REISERFS] },
|
||||
{ 0, NULL },
|
||||
};
|
||||
unsigned int num_filesystems = sizeof(filesystems) / sizeof(*filesystems);
|
||||
|
||||
char* fs_names[num_filesystems];
|
||||
int fs_choice = 0;
|
||||
for (unsigned int i = 0; i < num_filesystems; i++) {
|
||||
if (HW_FS_DEFAULT == filesystems[i].fstype)
|
||||
fs_choice = i;
|
||||
|
||||
fs_names[i] = filesystems[i].description;
|
||||
}
|
||||
|
||||
rc = newtWinMenu(ctr[TR_CHOOSE_FILESYSTEM], ctr[TR_CHOOSE_FILESYSTEM],
|
||||
50, 5, 5, 6, fs_names, &fs_choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 0)
|
||||
destination->filesystem = filesystems[fs_choice].fstype;
|
||||
|
||||
else
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
// Execute the partitioning...
|
||||
statuswindow(60, 4, title, ctr[TR_PARTITIONING_DISK]);
|
||||
|
||||
rc = hw_create_partitions(destination);
|
||||
if (rc) {
|
||||
errorbox(ctr[TR_UNABLE_TO_PARTITION]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (fstype == EXT2) {
|
||||
// mysystem("/sbin/modprobe ext2");
|
||||
sprintf(mkfscommand, "/sbin/mke2fs -T ext2");
|
||||
} else if (fstype == REISERFS) {
|
||||
mysystem("/sbin/modprobe reiserfs");
|
||||
sprintf(mkfscommand, "/sbin/mkreiserfs -f");
|
||||
} else if (fstype == EXT3) {
|
||||
// mysystem("/sbin/modprobe ext3");
|
||||
sprintf(mkfscommand, "/sbin/mke2fs -T ext3");
|
||||
} else if (fstype == EXT4) {
|
||||
// mysystem("/sbin/modprobe ext4");
|
||||
sprintf(mkfscommand, "/sbin/mke2fs -T ext4");
|
||||
}
|
||||
newtPopWindow();
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/sbin/mke2fs -T ext2 -I 128 %s", destination->part_boot);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
|
||||
// Execute the formatting...
|
||||
statuswindow(60, 4, title, ctr[TR_CREATING_FILESYSTEMS]);
|
||||
|
||||
rc = hw_create_filesystems(destination);
|
||||
if (rc) {
|
||||
errorbox(ctr[TR_UNABLE_TO_CREATE_FILESYSTEMS]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (swap_file) {
|
||||
snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s", destination->part_swap);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "%s %s", mkfscommand, destination->part_root);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
|
||||
rc = hw_mount_filesystems(destination, DESTINATION_MOUNT_PATH);
|
||||
if (rc) {
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_FILESYSTEMS]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "%s %s", mkfscommand, destination->part_data);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/mount %s /harddisk", destination->part_root);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/mount %s /harddisk/boot", destination->part_boot);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
|
||||
goto EXIT;
|
||||
}
|
||||
if (swap_file) {
|
||||
snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s", destination->part_swap);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/mount %s /harddisk/var", destination->part_data);
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
|
||||
goto EXIT;
|
||||
}
|
||||
newtPopWindow();
|
||||
|
||||
// Extract files...
|
||||
snprintf(commandstring, STRING_SIZE,
|
||||
"/bin/tar -C /harddisk -xvf /cdrom/" SNAME "-" VERSION ".tlz --lzma 2>/dev/null");
|
||||
|
||||
@@ -582,12 +466,6 @@ int main(int argc, char *argv[]) {
|
||||
/* Save language und local settings */
|
||||
write_lang_configs(shortlangname);
|
||||
|
||||
/* mount proc filesystem */
|
||||
mysystem("mkdir /harddisk/proc");
|
||||
mysystem("/bin/mount --bind /proc /harddisk/proc");
|
||||
mysystem("/bin/mount --bind /dev /harddisk/dev");
|
||||
mysystem("/bin/mount --bind /sys /harddisk/sys");
|
||||
|
||||
/* Build cache lang file */
|
||||
snprintf(commandstring, STRING_SIZE, "/usr/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
|
||||
@@ -606,18 +484,20 @@ 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);
|
||||
|
||||
if (fstype == EXT2) {
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "ext2");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
} else if (fstype == REISERFS) {
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
} else if (fstype == EXT3) {
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "ext3");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
} else if (fstype == EXT4) {
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "ext4");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
switch (destination->filesystem) {
|
||||
case HW_FS_REISERFS:
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "reiserfs");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
break;
|
||||
|
||||
case HW_FS_EXT4:
|
||||
case HW_FS_EXT4_WO_JOURNAL:
|
||||
replace("/harddisk/etc/fstab", "FSTYPE", "ext4");
|
||||
replace("/harddisk/boot/grub/grub.conf", "MOUNT", "ro");
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
replace("/harddisk/boot/grub/grub.conf", "KVER", KERNEL_VERSION);
|
||||
@@ -694,58 +574,30 @@ EXIT:
|
||||
|
||||
freekeyvalues(ethernetkv);
|
||||
|
||||
if (allok && !allok_fastexit)
|
||||
{
|
||||
if (unattended) {
|
||||
fprintf(flog, "Entering unattended setup\n");
|
||||
if (unattended_setup(unattendedkv)) {
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
|
||||
runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
|
||||
} else {
|
||||
errorbox("Unattended setup failed.");
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
if (allok) {
|
||||
fflush(flog);
|
||||
fclose(flog);
|
||||
newtFinished();
|
||||
|
||||
if (system("/bin/umount /harddisk/proc"))
|
||||
printf("Unable to umount /harddisk/proc.\n");
|
||||
} else {
|
||||
fflush(flog);
|
||||
fclose(flog);
|
||||
newtFinished();
|
||||
}
|
||||
|
||||
fcloseall();
|
||||
|
||||
if (swap_file) {
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s", destination->part_swap);
|
||||
}
|
||||
|
||||
newtFinished();
|
||||
|
||||
system("/bin/umount /harddisk/proc >/dev/null 2>&1");
|
||||
system("/bin/umount /harddisk/dev >/dev/null 2>&1");
|
||||
system("/bin/umount /harddisk/sys >/dev/null 2>&1");
|
||||
|
||||
system("/bin/umount /harddisk/var >/dev/null 2>&1");
|
||||
system("/bin/umount /harddisk/boot >/dev/null 2>&1");
|
||||
system("/bin/umount /harddisk >/dev/null 2>&1");
|
||||
|
||||
if (!(allok))
|
||||
system("/etc/halt");
|
||||
|
||||
// Free resources
|
||||
free(sourcedrive);
|
||||
free(destination);
|
||||
|
||||
if (destination) {
|
||||
hw_umount_filesystems(destination, DESTINATION_MOUNT_PATH);
|
||||
free(destination);
|
||||
}
|
||||
|
||||
if (selected_disks)
|
||||
hw_free_disks(selected_disks);
|
||||
|
||||
hw_free(hw);
|
||||
|
||||
fcloseall();
|
||||
|
||||
if (!(allok))
|
||||
system("/etc/halt");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user