diff --git a/src/main.rs b/src/main.rs index 74bee4d..5a51ceb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,46 +47,21 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { Ok(()) } -fn format_drive_encrypt(drive_name: &str) -> rsfdisk::Result<()> { - let mut disk = Fdisk::builder() - .assign_device(drive_name) - .enable_read_write() - .wipe_device_metadata() - .build()?; - - disk.partition_table_create(PartitionTableKind::GPT)?; - - let partition_type = PartitionKind::builder().guid(Guid::EfiSystem).build()?; - - let boot = Partition::builder() - .partition_type(partition_type) - .name("EFI") - //Assuming 512 bytes per sector, 2_097_152 sectors <=> 1 GiB. - .size_in_sectors(2_097_152) - .build()?; - - let _ = disk.partition_add(boot)?; - - let partition_type = PartitionKind::builder() - .guid(Guid::LinuxRootx86_64) - .build()?; - - let root = Partition::builder() - .partition_type(partition_type) - .name("Root") - .build()?; - - let _ = disk.partition_add(root)?; - - disk.partition_table_write_to_disk()?; - - Ok(()) -} - -fn format_partitions(drive_name: &str) { +fn encrypt(drive_name: &str) { let efi_path = format!("{}p1", drive_name); let root_path = format!("{}p2", drive_name); + //sudo cryptsetup luksFormat -v -s 512 -h sha512 $rootName + let _luks_format = Command::new("cryptsetup") + .args(["luksFormat", "-v", "-s", "512", "-h", "sha512"]) + .arg(&root_path) + .output() + .expect("Failed to run luksFomat"); +} + +fn format_boot(drive_name: &str) { + let efi_path = format!("{}p1", drive_name); + let _efi_partition = Command::new("mkfs.fat") .arg("-F32") .arg("-n") @@ -94,6 +69,10 @@ fn format_partitions(drive_name: &str) { .arg(&efi_path) .output() .expect("Failed to format boot partition as FAT32"); +} + +fn format_root(drive_name: &str) { + let root_path = format!("{}p2", drive_name); let _root_partition = Command::new("mkfs.ext4") .arg(&root_path) @@ -266,10 +245,13 @@ fn main() { // Partitioning the selected drive //let _ = format_drive(drive_name); - let _ = format_drive_encrypt(drive_name); + let _ = format_drive(drive_name); // Formatting the partitions - format_partitions(drive_name); + format_boot(drive_name); + //format_root(drive_name); + + encrypt(drive_name); // Mounting the partitions mount_partitions(drive_name);