finish up partitioning

axtloss/rework-partitioning
amy 3 years ago
parent 6665868da7
commit a94f6a7136

@ -132,4 +132,150 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
}
}
}
if device.contains("nvme") {
part_nvme(device, efi);
} else {
part_disk(device, efi);
}
}
fn part_nvme(device: &str, efi: bool) {
if efi {
let devicep1 = format!("{}p1", device).as_str();
let devicep2 = format!("{}p2", device).as_str();
returncode_eval(exec("mkfs.vfat", vec![
String::from(devicep1),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(devicep2),
]));
mount(devicep2, "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
umount("/mnt");
mount(devicep2, "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
files::create_directory("/mnt/boot/efi");
files::create_directory("/mnt/home");
mount(devicep2, "/mnt/home", "subvol=@home");
mount(devicep1, "/mnt/boot/efi", "");
} else {
let devicep1 = format!("{}p1", device).as_str();
let devicep2 = format!("{}p2", device).as_str();
returncode_eval(exec("mkfs.ext4", vec![
String::from(devicep1),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(devicep2),
]));
mount(devicep2, "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
umount("/mnt");
mount(devicep2, "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
files::create_directory("/mnt/home");
mount(devicep2, "/mnt/home", "subvol=@home");
mount(devicep1, "/mnt/boot", "");
}
}
fn part_disk(device: &str, efi: bool) {
if efi {
let device1 = format!("{}1", device).as_str();
let device2 = format!("{}2", device).as_str();
returncode_eval(exec("mkfs.vfat", vec![
String::from(device1),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(device2),
]));
mount(device2, "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
umount("/mnt");
mount(device2, "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
files::create_directory("/mnt/boot/efi");
files::create_directory("/mnt/home");
mount(device2, "/mnt/home", "subvol=@home");
mount(device1, "/mnt/boot/efi", "");
} else {
let device1 = format!("{}1", device).as_str();
let device2 = format!("{}2", device).as_str();
returncode_eval(exec("mkfs.ext4", vec![
String::from(device1),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(device2),
]));
mount(device2, "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
umount("/mnt");
mount(device2, "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
files::create_directory("/mnt/home");
mount(device2, "/mnt/home", "subvol=@home");
mount(device1, "/mnt/boot", "");
}
}
fn mount(partition: &str, mountpoint: &str, options: &str) {
let options = if options.is_empty() { "\"\"" } else { options };
returncode_eval(exec("mount", vec![
String::from(partition),
String::from(mountpoint),
String::from("-o"),
String::from(options),
]));
}
fn umount(mountpoint: &str) {
returncode_eval(exec("umount", vec![
String::from(mountpoint),
]));
}
fn returncode_eval(return_code: std::result::Result<std::process::Output, std::io::Error>) {
match return_code {
Ok(_) => {
log("Success".to_string());
}
Err(e) => {
crash(format!("Failed with error: {}", e), 1);
}
}
}

@ -4,3 +4,8 @@ pub fn exec(command: &str, args: Vec<String>) -> Result<std::process::Output, st
let returncode = Command::new(command).args(args).output();
returncode
}
pub fn exec_workdir(command: &str, workdir: &str, args: Vec<String>,) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new(command).args(args).current_dir(workdir).output();
returncode
}
Loading…
Cancel
Save