rsdisk working

This commit is contained in:
Aaron Honeycutt 2025-03-23 19:36:41 -06:00
parent 888bba4c34
commit 725967fe25
3 changed files with 579 additions and 2 deletions

View file

@ -1,5 +1,47 @@
use std::io;
use sys_metrics::disks;
use rsfdisk::fdisk::Fdisk;
use rsfdisk::core::partition_table::PartitionTableKind;
use rsfdisk::core::partition::{Guid, Partition, PartitionKind, PartitionList};
fn format_drive(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::LinuxRootx86_64)
.build()?;
let boot = Partition::builder()
.partition_type(partition_type.clone())
.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 root = Partition::builder()
.partition_type(partition_type)
.name("Root")
.size_in_sectors(499_033_071_616)
.build()?;
let _ = disk.partition_add(root)?;
disk.partition_table_write_to_disk()?;
Ok(())
}
fn mount_parts() {
}
fn main() {
println!("Availble disks for installation:");
@ -23,8 +65,11 @@ fn main() {
.read_line(&mut drive_name)
.expect("Failed to read line");
let _drive_name = drive_name.trim();
let drive_name = drive_name.trim();
// let deposit_number: f64 = deposit_amount.parse().expect("Input not an integer");
// Partitioning the selected drive
format_drive(drive_name);
}