allow manual partitioning

axtloss/rework-partitioning
axtlos 3 years ago
parent 9541bfb0ea
commit 6d894dcebf
No known key found for this signature in database
GPG Key ID: A468AFD71DD51D4A

@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = {version = "3.1.10", features = ["derive"] }
serde_json = "1.0.59"

@ -80,14 +80,44 @@ pub struct PartitionArgs {
pub mode: PartitionMode,
/// The device to partition
#[clap(required_if_eq("mode", "PartitionMode::Manual"))]
#[clap(required_if_eq("mode", "PartitionMode::Auto"))]
pub device: PathBuf,
/// If the install destination should be partitioned with EFI
#[clap(long)]
pub efi: bool,
/// The partitions to use for manual partitioning
#[clap(required_if_eq("mode", "Partition::Manual"), parse(try_from_str = parse_partitions))]
pub partitions: Vec<Partition>,
}
#[derive(Debug)]
pub struct Partition {
pub mountpoint: String,
pub blockdevice: String,
pub filesystem: String,
}
impl Partition {
pub fn new(mountpoint: String, blockdevice: String, filesystem: String) -> Self {
Self {
mountpoint,
blockdevice,
filesystem,
}
}
}
pub fn parse_partitions(s: &str) -> Result<Partition, &'static str> {
Ok(Partition::new(
s.split(' ').collect::<Vec<&str>>()[0].to_string(),
s.split(' ').collect::<Vec<&str>>()[1].to_string(),
s.split(' ').collect::<Vec<&str>>()[2].to_string(),
))
}
#[derive(Debug, ArgEnum, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)]
pub enum PartitionMode {
#[clap(name = "auto")]

@ -1,9 +1,163 @@
use crate::args::PartitionMode;
use crate::args;
use crate::internal::exec::*;
use crate::internal::*;
use std::path::{Path, PathBuf};
pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool) {
/*mkfs.bfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs
mkfs.btrfs mkfs.ext2 mkfs.extd mkfs.minix mkfs.vfat */
pub fn fmt_mount(mountpoint: &String, filesystem: &String, blockdevice: &String) {
match filesystem.as_str() {
"vfat" => {
exec_eval(
exec(
"mkfs.vfat",
vec![
String::from("-F"),
String::from("32"),
String::from(blockdevice),
],
),
"Formatting {blockdevice} as vfat",
)
}
"bfs" => {
exec_eval(
exec(
"mkfs.bfs",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as bfs",
)
}
"cramfs" => {
exec_eval(
exec(
"mkfs.cramfs",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as cramfs",
)
}
"ext3" => {
exec_eval(
exec(
"mkfs.ext3",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as ext3",
)
}
"fat" => {
exec_eval(
exec(
"mkfs.fat",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as fat",
)
}
"msdos" => {
exec_eval(
exec(
"mkfs.msdos",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as msdos",
)
}
"xfs" => {
exec_eval(
exec(
"mkfs.xfs",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as xfs",
)
}
"btrfs" => {
exec_eval(
exec(
"mkfs.btrfs",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as btrfs",
)
}
"ext2" => {
exec_eval(
exec(
"mkfs.ext2",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as ext2",
)
}
"extd" => {
exec_eval(
exec(
"mkfs.extd",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as extd",
)
}
"minix" => {
exec_eval(
exec(
"mkfs.minix",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as minix",
)
}
"vfat" => {
exec_eval(
exec(
"mkfs.vfat",
vec![
String::from(blockdevice),
],
),
"Formatting {blockdevice} as vfat",
)
}
_ => {
crash(
"Unknown filesystem {filesystem}, used in partition {blockdevice}",
1,
);
}
}
files_eval(
files::create_directory(&mountpoint),
"Creating mountpoint {mountpoint} for {blockdevice}",
);
mount(&blockdevice, &mountpoint, "");
}
pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: Vec<args::Partition>) {
if !device.exists() {
crash(format!("The device {device:?} doesn't exist"), 1);
}
@ -18,6 +172,13 @@ pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool) {
}
PartitionMode::Manual => {
log::debug!("Manual partitioning");
for i in 0..partitions.len() {
fmt_mount(
&partitions[i].mountpoint,
&partitions[i].filesystem,
&partitions[i].blockdevice,
);
}
}
}
if device.to_string_lossy().contains("nvme") {

@ -1,4 +1,5 @@
use crate::args::{DesktopSetup, PartitionMode};
use crate::args;
use crate::functions::*;
use crate::internal::*;
use serde::{Deserialize, Serialize};
@ -22,6 +23,7 @@ struct Partition {
device: String,
mode: PartitionMode,
efi: bool,
partitions: Vec<String>,
}
#[derive(Serialize, Deserialize)]
@ -77,10 +79,19 @@ pub fn read_config(configpath: PathBuf) {
log::info!("Block device to use : /dev/{}", config.partition.device);
log::info!("Partitioning mode : {:?}", config.partition.mode);
log::info!("Partitioning for EFI : {}", config.partition.efi);
let mut partitions: Vec<args::Partition> = Vec::new();
for partition in config.partition.partitions {
partitions.push(args::Partition::new(
partition.split(':').collect::<Vec<&str>>()[0].to_string(),
partition.split(':').collect::<Vec<&str>>()[1].to_string(),
partition.split(':').collect::<Vec<&str>>()[2].to_string(),
));
}
partition::partition(
PathBuf::from("/dev/").join(config.partition.device),
config.partition.mode,
config.partition.efi,
partitions,
);
base::install_base_packages();
base::genfstab();

@ -12,7 +12,7 @@ fn main() {
logging::init(opt.verbose);
match opt.command {
Command::Partition(args) => {
partition::partition(args.device, args.mode, args.efi);
partition::partition(args.device, args.mode, args.efi, args.partitions);
}
Command::InstallBase => {
base::install_base_packages();

Loading…
Cancel
Save