Adds a new parameter `--on-first-boot` to the `prepare-iso` command, to specify a file to bake into the ISO.
To later use it with the auto-installer, the following must be set in the answer file: [first-boot] source = "from-iso" Signed-off-by: Christoph Heiss <c.he...@proxmox.com> --- Changes v1 -> v2: * add filesize check; only allow up to 1 MiB scripts proxmox-auto-install-assistant/Cargo.toml | 1 + proxmox-auto-install-assistant/src/main.rs | 30 +++++++++++++++++++++- proxmox-installer-common/src/lib.rs | 6 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/proxmox-auto-install-assistant/Cargo.toml b/proxmox-auto-install-assistant/Cargo.toml index c4486f8..07e6ffb 100644 --- a/proxmox-auto-install-assistant/Cargo.toml +++ b/proxmox-auto-install-assistant/Cargo.toml @@ -13,6 +13,7 @@ homepage = "https://www.proxmox.com" [dependencies] anyhow.workspace = true log.workspace = true +proxmox-installer-common.workspace = true proxmox-auto-installer.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs index bdcf067..d7aa134 100644 --- a/proxmox-auto-install-assistant/src/main.rs +++ b/proxmox-auto-install-assistant/src/main.rs @@ -19,6 +19,7 @@ use proxmox_auto_installer::{ FetchAnswerFrom, HttpOptions, }, }; +use proxmox_installer_common::{FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME}; static PROXMOX_ISO_FLAG: &str = "/auto-installer-capable"; @@ -149,6 +150,13 @@ struct CommandPrepareISO { // so shorten "Automated Installer Source" to "AIS" to be safe. #[arg(long, default_value_t = { "proxmox-ais".to_owned() } )] partition_label: String, + + /// Executable file to include, which should be run on the first system boot after the + /// installation. Can be used for further bootstrapping the new system. + /// + /// Must be appropriately enabled in the answer file. + #[arg(long)] + on_first_boot: Option<PathBuf>, } /// Show the system information that can be used to identify a host. @@ -201,7 +209,7 @@ fn main() { Commands::SystemInfo(args) => show_system_info(args), }; if let Err(err) = res { - eprintln!("{err}"); + eprintln!("Error: {err:?}"); std::process::exit(1); } } @@ -305,6 +313,17 @@ fn prepare_iso(args: &CommandPrepareISO) -> Result<()> { bail!("You must set '--fetch-from' to 'iso' to place the answer file directly in the ISO."); } + if let Some(first_boot) = &args.on_first_boot { + let metadata = fs::metadata(first_boot)?; + + if metadata.len() > FIRST_BOOT_EXEC_MAX_SIZE.try_into()? { + bail!( + "Maximum file size for first-boot executable file is {} MiB", + FIRST_BOOT_EXEC_MAX_SIZE / 1024 / 1024 + ) + } + } + if let Some(file) = &args.answer_file { println!("Checking provided answer file..."); parse_answer(file)?; @@ -352,6 +371,15 @@ fn prepare_iso(args: &CommandPrepareISO) -> Result<()> { inject_file_to_iso(&tmp_iso, answer_file, "/answer.toml", &uuid)?; } + if let Some(first_boot) = &args.on_first_boot { + inject_file_to_iso( + &tmp_iso, + first_boot, + &format!("/{FIRST_BOOT_EXEC_NAME}"), + &uuid, + )?; + } + println!("Moving prepared ISO to target location..."); fs::rename(&tmp_iso, &iso_target)?; println!("Final ISO is available at {iso_target:?}."); diff --git a/proxmox-installer-common/src/lib.rs b/proxmox-installer-common/src/lib.rs index 10b5940..13acb89 100644 --- a/proxmox-installer-common/src/lib.rs +++ b/proxmox-installer-common/src/lib.rs @@ -11,3 +11,9 @@ pub const RUNTIME_DIR: &str = "/run/proxmox-installer"; /// Default placeholder value for the administrator email address. pub const EMAIL_DEFAULT_PLACEHOLDER: &str = "mail@example.invalid"; + +/// Name of the executable for the first-boot hook. +pub const FIRST_BOOT_EXEC_NAME: &str = "proxmox-first-boot"; + +/// Maximum file size for the first-boot hook executable. +pub const FIRST_BOOT_EXEC_MAX_SIZE: usize = 1024 * 1024; // 1 MiB -- 2.47.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel