start work on encrypt feature

This commit is contained in:
Aaron Honeycutt 2025-04-24 17:24:39 -06:00
parent 0d32bf0d6e
commit 27e5e98669

View file

@ -47,6 +47,42 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
Ok(()) 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 format_partitions(drive_name: &str) {
let efi_path = format!("{}p1", drive_name); let efi_path = format!("{}p1", drive_name);
let root_path = format!("{}p2", drive_name); let root_path = format!("{}p2", drive_name);
@ -228,7 +264,9 @@ fn main() {
grab_gnome(); grab_gnome();
// Partitioning the selected drive // Partitioning the selected drive
let _ = format_drive(drive_name); //let _ = format_drive(drive_name);
let _ = format_drive_encrypt(drive_name);
// Formatting the partitions // Formatting the partitions
format_partitions(drive_name); format_partitions(drive_name);