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