I'm trying to partition the disk on my Linux machine using Rust.
To format and create new partition I'm using sgdisk
utility.
#[derive(Deserialize, Debug)]
pub struct Drives {
system: PathBuf,
home: Option<PathBuf>,
}
impl Drives {
fn create_partitions(&self) -> Result<()> {
cmd!("sgdisk", "--new=0:0:+256MiB --typecode=0:ef00 -c 0:\"efi\"", &self.system).run().context("Failed to create EFI partition")?;
Ok(())
}
}
The command succeeds with creating a new partition, but unfortunately the label is missing.
sgdisk -p /dev/sda
...
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB 8300
The cmd!
macro comes from duct
crate which passes the content to std::process::Command
underneath. Even if I directly call the external process I don't get the partition labeled.
I suppose the issue is probably with passing the String to sgdisk
expecting zero terminated ASCII string. If I call the same command in shell script it works.