✨ disk format
This commit is contained in:
parent
047f8eccce
commit
31110447da
3 changed files with 21 additions and 10 deletions
|
@ -33,6 +33,7 @@ pub fn get_args() -> clap::ArgMatches {
|
||||||
command!()
|
command!()
|
||||||
.name("create-img")
|
.name("create-img")
|
||||||
.about("Create an install on a disk image for VMs or embedded devices")
|
.about("Create an install on a disk image for VMs or embedded devices")
|
||||||
|
.arg(arg!(--gpt "Use modern disk format"))
|
||||||
.arg(arg!([config] "Config file").required(true))
|
.arg(arg!([config] "Config file").required(true))
|
||||||
.arg(arg!([image] "Image file").required(true))
|
.arg(arg!([image] "Image file").required(true))
|
||||||
)
|
)
|
||||||
|
|
|
@ -151,19 +151,28 @@ pub fn setup_fstrim() {
|
||||||
systemd_service_enable("fstrim.service");
|
systemd_service_enable("fstrim.service");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_disk_image(img_file: &str) {
|
pub fn setup_disk_image(img_file: &str, modern: bool) {
|
||||||
print_status(&format!("Allocating disk image"));
|
print_status(&format!("Allocating disk image"));
|
||||||
run_command(&["fallocate", "-l", "8G", img_file], None, false);
|
run_command(&["fallocate", "-l", "8G", img_file], None, false);
|
||||||
|
|
||||||
print_status(&format!("Partitioning disk image"));
|
print_status(&format!("Partitioning disk image"));
|
||||||
run_command(
|
if modern {
|
||||||
&[
|
run_command(
|
||||||
"parted", img_file, "--script", "--", "mklabel", "gpt", "mkpart", "ESP", "fat32",
|
&[
|
||||||
"1MiB", "1GiB", "set", "1", "esp", "on", "mkpart", "primary", "ext4", "1GiB", "100%",
|
"parted", img_file, "--script", "--", "mklabel", "gpt", "mkpart", "ESP", "fat32",
|
||||||
],
|
"1MiB", "1GiB", "set", "1", "esp", "on", "mkpart", "primary", "ext4", "1GiB",
|
||||||
None,
|
"100%",
|
||||||
true,
|
],
|
||||||
);
|
None,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
run_command(
|
||||||
|
&["fdisk", img_file],
|
||||||
|
Some("o\nn\np\n1\n\n+1G\nt\nc\nn\np\n2\n\n\nw\n"),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
print_status(&format!("Setting up disk image"));
|
print_status(&format!("Setting up disk image"));
|
||||||
let (stdout, _) = run_command(
|
let (stdout, _) = run_command(
|
||||||
|
|
|
@ -74,8 +74,9 @@ fn main() {
|
||||||
let config_file: &String = install_args.get_one("config").unwrap();
|
let config_file: &String = install_args.get_one("config").unwrap();
|
||||||
let conf = read_conf(config_file);
|
let conf = read_conf(config_file);
|
||||||
let img_file: &String = install_args.get_one("image").unwrap();
|
let img_file: &String = install_args.get_one("image").unwrap();
|
||||||
|
let gpt = install_args.get_flag("gpt");
|
||||||
|
|
||||||
setup_disk_image(img_file.as_str());
|
setup_disk_image(img_file.as_str(), gpt);
|
||||||
install_mnt(conf, false);
|
install_mnt(conf, false);
|
||||||
}
|
}
|
||||||
Some(("install", install_args)) => {
|
Some(("install", install_args)) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue