|
|
|
@ -7,69 +7,87 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
} else {
|
|
|
|
|
log(format!("automatically partitioning {}", device));
|
|
|
|
|
if efi {
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("gpt"),
|
|
|
|
|
],
|
|
|
|
|
), format!("create gpt label on {}", device).as_str());
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("fat32"),
|
|
|
|
|
String::from("0"),
|
|
|
|
|
String::from("300"),
|
|
|
|
|
],
|
|
|
|
|
), "create EFI partition");
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("btrfs"),
|
|
|
|
|
String::from("300"),
|
|
|
|
|
String::from("100%"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs root partition");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("gpt"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
format!("create gpt label on {}", device).as_str(),
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("fat32"),
|
|
|
|
|
String::from("0"),
|
|
|
|
|
String::from("300"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"create EFI partition",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("btrfs"),
|
|
|
|
|
String::from("300"),
|
|
|
|
|
String::from("100%"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs root partition",
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("msdos"),
|
|
|
|
|
],
|
|
|
|
|
), format!("Create msdos label on {}", device).as_str());
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("btrfs"),
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
String::from("100&"),
|
|
|
|
|
],
|
|
|
|
|
), "create btrfs root partition");
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("ext4"),
|
|
|
|
|
String::from("1MIB"),
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
],
|
|
|
|
|
), "create bios boot partition");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mklabel"),
|
|
|
|
|
String::from("msdos"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
format!("Create msdos label on {}", device).as_str(),
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("btrfs"),
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
String::from("100&"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"create btrfs root partition",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"parted",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from(device),
|
|
|
|
|
String::from("mkpart"),
|
|
|
|
|
String::from("ext4"),
|
|
|
|
|
String::from("1MIB"),
|
|
|
|
|
String::from("512MIB"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"create bios boot partition",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if device.contains("nvme") {
|
|
|
|
@ -81,121 +99,189 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
|
|
|
|
|
|
|
|
|
|
fn part_nvme(device: &str, efi: bool) {
|
|
|
|
|
if efi {
|
|
|
|
|
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());
|
|
|
|
|
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![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @home",
|
|
|
|
|
);
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
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/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!("{}p2", device).as_str(),
|
|
|
|
|
"/mnt/home",
|
|
|
|
|
"subvol=@home",
|
|
|
|
|
);
|
|
|
|
|
mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", "");
|
|
|
|
|
} else {
|
|
|
|
|
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());
|
|
|
|
|
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![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @home",
|
|
|
|
|
);
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
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!("{}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 {
|
|
|
|
|
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());
|
|
|
|
|
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![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @home");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @home",
|
|
|
|
|
);
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
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/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 {
|
|
|
|
|
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());
|
|
|
|
|
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![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
), "Create btrfs subvolume @");
|
|
|
|
|
exec_eval(exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
), "create btrfs subvolume @home");
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"Create btrfs subvolume @",
|
|
|
|
|
);
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_workdir(
|
|
|
|
|
"btrfs",
|
|
|
|
|
"/mnt",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("subvolume"),
|
|
|
|
|
String::from("create"),
|
|
|
|
|
String::from("@home"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"create btrfs subvolume @home",
|
|
|
|
|
);
|
|
|
|
|
umount("/mnt");
|
|
|
|
|
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");
|
|
|
|
|
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", "");
|
|
|
|
|
}
|
|
|
|
@ -203,17 +289,27 @@ fn part_disk(device: &str, efi: bool) {
|
|
|
|
|
|
|
|
|
|
fn mount(partition: &str, mountpoint: &str, options: &str) {
|
|
|
|
|
let options = if options.is_empty() { "\"\"" } else { options };
|
|
|
|
|
exec_eval(exec(
|
|
|
|
|
"mount",
|
|
|
|
|
vec![
|
|
|
|
|
String::from(partition),
|
|
|
|
|
String::from(mountpoint),
|
|
|
|
|
String::from("-o"),
|
|
|
|
|
String::from(options),
|
|
|
|
|
],
|
|
|
|
|
), format!("mount {} with options {} at {}", partition, options, mountpoint).as_str());
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec(
|
|
|
|
|
"mount",
|
|
|
|
|
vec![
|
|
|
|
|
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) {
|
|
|
|
|
exec_eval(exec("umount", vec![String::from(mountpoint)]), format!("unmount {}", mountpoint).as_str());
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec("umount", vec![String::from(mountpoint)]),
|
|
|
|
|
format!("unmount {}", mountpoint).as_str(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|