[pve-devel] [PATCH v1 installer 14/18] auto-installer: add fetch answer binary

Aaron Lauterer a.lauterer at proxmox.com
Thu Feb 8 17:46:36 CET 2024



On 2/8/24 15:18, Christoph Heiss wrote:
> Sorry for not including this in the first email.
> 
> On Tue, Jan 23, 2024 at 06:00:49PM +0100, Aaron Lauterer wrote:
> [..]
>> diff --git a/proxmox-auto-installer/src/fetch_plugins/partition.rs b/proxmox-auto-installer/src/fetch_plugins/partition.rs
>> new file mode 100644
>> index 0000000..0552ddd
>> --- /dev/null
>> +++ b/proxmox-auto-installer/src/fetch_plugins/partition.rs
>> @@ -0,0 +1,102 @@
>> +use anyhow::{bail, Result};
>> +use log::{info, warn};
>> +use std::fs::read_to_string;
>> +use std::path::{Path, PathBuf};
>> +use std::process::Command;
>> +
>> +static ANSWER_FILE: &str = "answer.toml";
>> +static ANSWER_MP: &str = "/mnt/answer";
>> +static PARTLABEL: &str = "proxmoxinst";
>> +static SEARCH_PATH: &str = "/dev/disk/by-label";
>> +
>> +pub struct FetchFromPartition;
>> +
>> +impl FetchFromPartition {
>> +    /// Returns the contents of the answer file
>> +    pub fn get_answer() -> Result<String> {
>> +        let part_path = Self::scan_partlabels()?;
>> +        Self::mount_part(part_path)?;
>> +        Self::get_answer_file()
> 
> Before returning, the partition should be unmounted, as it is not needed
> anymore after this point.
> 
> This also prevents some funny error that occurs if the installation
> fails due to some error. The next time `proxmox-fetch-answer` is run, it
> cannot mount the answer partition anymore, due to being already mounted.

For now sure. If we add additional plugins to fetch the answer file via a URL, we might want to place the ssl fingerprint on the same partition. Then we would have to either mount it again, or wait with the unmount until we have reached the end of going through the plugins, as a cleanup measure.

> 
>> +
> [..]
>> +
>> +    /// Will mount source path to ANSWER_MP
>> +    ///
>> +    /// # Arguments
>> +    ///
>> +    /// * `source` - `PathBuf` of the source location
>> +    fn mount_part(source: PathBuf) -> Result<()> {
>> +        info!("Mounting partition at {ANSWER_MP}");
>> +        // create dir for mountpoint
>> +        match Command::new("/usr/bin/mkdir")
>> +            .arg(ANSWER_MP)
>> +            .arg("-p")
>> +            .output()
>> +        {
>> +            Ok(output) => {
>> +                if !output.status.success() {
>> +                    warn!(
>> +                        "Error creating mount path: {}",
>> +                        String::from_utf8(output.stderr)?
>> +                    )
>> +                }
>> +            }
>> +            Err(err) => bail!("Error creating mount path: {}", err),
>> +        }
>> +        match Command::new("/usr/bin/mount")
>> +            .arg(source)
>> +            .arg(ANSWER_MP)
> 
> I'd argue the partition should be mounted with `-o ro` and thus
> readonly, just for the sake of it. We never write to it anyway and this
> would prevent any (accidental) attempt to do so in the future.

Good point!

> 
>> +            .output()
>> +        {
>> +            Ok(output) => {
>> +                if output.status.success() {
>> +                    Ok(())
>> +                } else {
>> +                    warn!("Error mounting: {}", String::from_utf8(output.stderr)?);
>> +                    Ok(())
>> +                }
>> +            }
>> +            Err(err) => bail!("Error mounting: {}", err),
>> +        }
>> +    }
>> +
> [..]




More information about the pve-devel mailing list