0

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.

phodina
  • 1,341
  • 1
  • 12
  • 25
  • Then add `\0` after efi? – hellow Apr 26 '19 at 09:43
  • @hellow I tried adding \0, but without success. – phodina Apr 26 '19 at 09:45
  • 3
    Seems I've been looking into this the wrong way as I had similar issue https://stackoverflow.com/questions/55865024/generating-iso-with-xorriso. Turns out all I have to do is split the argument. That means pass it as `cmd!("sgdisk", "--new=0:0:+256MiB", "--typecode=0:ef00", "-c", "0:efi", &self.system)` and it works like charm. – phodina Apr 26 '19 at 11:18
  • 1
    @phodina Yup, you need to separate the arguments. Otherwise the whole argument is wrapped in a single string. – Tim Diekmann Apr 26 '19 at 12:17

0 Answers0