|
|
|
@ -7,7 +7,7 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
} else {
|
|
|
|
|
log(format!("automatically partitioning {}", device));
|
|
|
|
|
if efi {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -15,8 +15,8 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("gpt"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
), format!("create gpt label on {}", device).as_str());
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -26,8 +26,8 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("0"),
|
|
|
|
|
String::from("300"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
), "create EFI partition");
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -37,9 +37,9 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("300"),
|
|
|
|
|
String::from("100%"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "Create btrfs root partition");
|
|
|
|
|
} else {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -47,8 +47,8 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("msdos"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
), format!("Create msdos label on {}", device).as_str());
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -58,8 +58,8 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
String::from("100&"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
), "create btrfs root partition");
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
@ -69,7 +69,7 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
String::from("1MIB"),
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "create bios boot partition");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if device.contains("nvme") {
|
|
|
|
@ -81,16 +81,10 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
|
|
|
|
|
fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
if efi {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.vfat",
|
|
|
|
|
vec![format!("{}p1", device)],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.btrfs",
|
|
|
|
|
vec![format!("{}p2", device)],
|
|
|
|
|
));
|
|
|
|
|
mount(format!("{}p2", device), "/mnt", "");
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
exec_eval(exec("mkfs.vfat", vec![format!("{}p1", device)]), format!("format {}p1 as fat32", device).as_str());
|
|
|
|
|
exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str());
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt", "");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -98,8 +92,8 @@ fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -107,25 +101,19 @@ fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
mount(format!("{}p2", device), "/mnt/", "subvol=@");
|
|
|
|
|
files::create_directory("/mnt/boot");
|
|
|
|
|
files::create_directory("/mnt/boot/efi");
|
|
|
|
|
files::create_directory("/mnt/home");
|
|
|
|
|
mount(format!("{}p2", device), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}p1", device), "/mnt/boot/efi", "");
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot/efi"), "create /mnt/boot/efi");
|
|
|
|
|
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
|
|
|
|
|
} else {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.ext4",
|
|
|
|
|
vec![format!("{}p1", device)],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.btrfs",
|
|
|
|
|
vec![format!("{}p2", device)],
|
|
|
|
|
));
|
|
|
|
|
mount(format!("{}p2", device), "/mnt/", "");
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
exec_eval(exec("mkfs.ext4", vec![format!("{}p1", device)]), format!("format {}p1 as ext4", device).as_str());
|
|
|
|
|
exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str());
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt/", "");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -133,8 +121,8 @@ fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -142,28 +130,22 @@ fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
mount(format!("{}p2", device), "/mnt/", "subvol=@");
|
|
|
|
|
files::create_directory("/mnt/boot");
|
|
|
|
|
files::create_directory("/mnt/home");
|
|
|
|
|
mount(format!("{}p2", device), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}p1", device), "/mnt/boot", "");
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
|
|
|
|
|
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
|
|
|
|
|
mount(format!("{}p2", device).as_str(), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}p1", device).as_str(), "/mnt/boot", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
if efi {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.vfat",
|
|
|
|
|
vec![format!("{}1", device)],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.btrfs",
|
|
|
|
|
vec![format!("{}2", device)],
|
|
|
|
|
));
|
|
|
|
|
mount(format!("{}2", device), "/mnt", "");
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
exec_eval(exec("mkfs.vfat", vec![format!("{}1", device)]), format!("format {}1 as fat32", device).as_str());
|
|
|
|
|
exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str());
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt", "");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -171,8 +153,8 @@ fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -180,25 +162,19 @@ fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
mount(format!("{}2", device), "/mnt/", "subvol=@");
|
|
|
|
|
files::create_directory("/mnt/boot");
|
|
|
|
|
files::create_directory("/mnt/boot/efi");
|
|
|
|
|
files::create_directory("/mnt/home");
|
|
|
|
|
mount(format!("{}2", device), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}1", device), "/mnt/boot/efi", "");
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot/efi"), "create /mnt/boot/efi");
|
|
|
|
|
files_eval(files::create_directory("/mnt/home"), "create /mnt/home");
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}1", device).as_str(), "/mnt/boot/efi", "");
|
|
|
|
|
} else {
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.ext4",
|
|
|
|
|
vec![format!("{}1", device)],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
"mkfs.btrfs",
|
|
|
|
|
vec![format!("{}2", device)],
|
|
|
|
|
));
|
|
|
|
|
mount(format!("{}2", device), "/mnt/", "");
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
exec_eval(exec("mkfs.ext4", vec![format!("{}1", device)]), format!("format {}1 as ext4", device).as_str());
|
|
|
|
|
exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str());
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt/", "");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -206,8 +182,8 @@ fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
returncode_eval(exec_workdir(
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
@ -215,40 +191,29 @@ fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), "create btrfs subvolume @home");
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
mount(format!("{}2", device), "/mnt/", "subvol=@");
|
|
|
|
|
files::create_directory("/mnt/boot");
|
|
|
|
|
files::create_directory("/mnt/home");
|
|
|
|
|
mount(format!("{}2", device), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}1", device), "/mnt/boot", "");
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@");
|
|
|
|
|
files_eval(files::create_directory("/mnt/boot"), "create directory /mnt/boot");
|
|
|
|
|
files_eval(files::create_directory("/mnt/home"), "create directory /mnt/home");
|
|
|
|
|
mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home");
|
|
|
|
|
mount(format!("{}1", device).as_str(), "/mnt/boot", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn mount(partition: String, mountpoint: &str, options: &str) {
|
|
|
|
|
fn mount(partition: &str, mountpoint: &str, options: &str) {
|
|
|
|
|
let options = if options.is_empty() { "\"\"" } else { options };
|
|
|
|
|
returncode_eval(exec(
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"mount",
|
|
|
|
|
vec![
|
|
|
|
|
partition,
|
|
|
|
|
String::from(partition),
|
|
|
|
|
String::from(mountpoint),
|
|
|
|
|
String::from("-o"),
|
|
|
|
|
String::from(options),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
), format!("mount {} with options {} at {}", partition, options, mountpoint).as_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exec_eval(exec("umount", vec![String::from(mountpoint)]), format!("unmount {}", mountpoint).as_str());
|
|
|
|
|
}
|
|
|
|
|