mirror of
https://gitlab.com/ahoneybun/nyxi-installer.git
synced 2025-05-12 11:04:02 -06:00
76 lines
1.9 KiB
Rust
76 lines
1.9 KiB
Rust
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:");
|
|
println!("");
|
|
|
|
match disks::get_physical_ioblocks() {
|
|
Ok(disk_list) => {
|
|
for disk in disk_list {
|
|
println!("Disk: {}", disk.device_name);
|
|
}
|
|
}
|
|
Err(_e) => println!("{}",_e),
|
|
}
|
|
|
|
let mut drive_name = String::new();
|
|
|
|
println!("");
|
|
println!("Use the full drive path such as /dev/nvme0n1 or /dev/sda");
|
|
println!("Which drive do we want to use for this installation?: {}", drive_name);
|
|
|
|
io::stdin()
|
|
.read_line(&mut drive_name)
|
|
.expect("Failed to read line");
|
|
|
|
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);
|
|
|
|
}
|