src/tools/disks.rs: new helper to reread partition table

This commit is contained in:
Dietmar Maurer 2020-06-08 07:22:06 +02:00
parent 2b388026f8
commit 044055062c

View File

@ -837,6 +837,29 @@ pub fn get_disks(
Ok(result)
}
/// Try to reload the partition table
pub fn reread_partition_table(disk: &Disk) -> Result<(), Error> {
const BLOCKDEV_BIN_PATH: &str = "/sbin/blockdev";
let disk_path = match disk.device_path() {
Some(path) => path,
None => bail!("disk {:?} has no node in /dev", disk.syspath()),
};
let mut command = std::process::Command::new(BLOCKDEV_BIN_PATH);
command.arg("--rereadpt");
command.arg(disk_path);
let output = command.output()
.map_err(|err| format_err!("failed to execute '{}' - {}", BLOCKDEV_BIN_PATH, err))?;
crate::tools::command_output(output, None)
.map_err(|err| format_err!("re-read partition table failed: {}", err))?;
Ok(())
}
/// Initialize disk by writing a GPT partition table
pub fn inititialize_gpt_disk(disk: &Disk, uuid: Option<&str>) -> Result<(), Error> {