From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 73DFB20EC91 for ; Tue, 30 Apr 2024 12:46:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 78F1F31E22; Tue, 30 Apr 2024 12:46:43 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Tue, 30 Apr 2024 12:46:08 +0200 Message-Id: <20240430104609.149766-2-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430104609.149766-1-a.lauterer@proxmox.com> References: <20240430104609.149766-1-a.lauterer@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.044 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Subject: [pve-devel] [PATCH installer v3 1/2] assistant: keep prepared iso bootable on uefi with flash drives X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" By mapping files into the ISO, the UUID for the partitions change as they depend on the timestamp. The result is, that grub cannot find its partition anymore and the user ends up on the grub shell. This only happens when booting from a blockdev in UEFI mode. E.g. a USB flash drive. Alternatively one can `dd` the ISO to a small (2GiB) VM disk and mark it as the first boot device. When booting in legacy mode or via CDROM (e.g. pass through via IPMI), it worked. Xorriso can report the commands needed to recreate the source ISO. The '-volume_date uuid' is the one needed to override the same UUIDs. We therefore read it first from the source iso and pass it as parameter whenever we inject a file into the iso. Signed-off-by: Aaron Lauterer Reviewed-by: Stoiko Ivanov Tested-by: Stoiko Ivanov --- changes since: v2: * add missing import of format_err to patch v1: * improve error handling should xorriso return empty output proxmox-auto-install-assistant/src/main.rs | 46 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs index 0debd29..f8e5ed0 100644 --- a/proxmox-auto-install-assistant/src/main.rs +++ b/proxmox-auto-install-assistant/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{bail, format_err, Result}; use clap::{Args, Parser, Subcommand, ValueEnum}; use glob::Pattern; use regex::Regex; @@ -276,6 +276,7 @@ fn show_system_info(_args: &CommandSystemInfo) -> Result<()> { fn prepare_iso(args: &CommandPrepareISO) -> Result<()> { check_prepare_requirements(args)?; + let uuid = get_iso_uuid(&args.input)?; if args.fetch_from == FetchAnswerFrom::Iso && args.answer_file.is_none() { bail!("Missing path to the answer file required for the fetch-from 'iso' mode."); @@ -331,10 +332,15 @@ fn prepare_iso(args: &CommandPrepareISO) -> Result<()> { instmode_file_tmp.push("auto-installer-mode.toml"); fs::write(&instmode_file_tmp, toml::to_string_pretty(&config)?)?; - inject_file_to_iso(&tmp_iso, &instmode_file_tmp, "/auto-installer-mode.toml")?; + inject_file_to_iso( + &tmp_iso, + &instmode_file_tmp, + "/auto-installer-mode.toml", + &uuid, + )?; if let Some(answer_file) = &args.answer_file { - inject_file_to_iso(&tmp_iso, answer_file, "/answer.toml")?; + inject_file_to_iso(&tmp_iso, answer_file, "/answer.toml", &uuid)?; } println!("Moving prepared ISO to target location..."); @@ -371,11 +377,14 @@ fn final_iso_location(args: &CommandPrepareISO) -> PathBuf { target.to_path_buf() } -fn inject_file_to_iso(iso: &PathBuf, file: &PathBuf, location: &str) -> Result<()> { +fn inject_file_to_iso(iso: &PathBuf, file: &PathBuf, location: &str, uuid: &String) -> Result<()> { let result = Command::new("xorriso") .arg("--boot_image") .arg("any") .arg("keep") + .arg("-volume_date") + .arg("uuid") + .arg(uuid) .arg("-dev") .arg(iso) .arg("-map") @@ -391,6 +400,35 @@ fn inject_file_to_iso(iso: &PathBuf, file: &PathBuf, location: &str) -> Result<( Ok(()) } +fn get_iso_uuid(iso: &PathBuf) -> Result { + let result = Command::new("xorriso") + .arg("-dev") + .arg(iso) + .arg("-report_system_area") + .arg("cmd") + .output()?; + if !result.status.success() { + bail!( + "Error determining the UUID of the source ISO: {}", + String::from_utf8_lossy(&result.stderr) + ); + } + let mut uuid = String::new(); + for line in String::from_utf8(result.stdout)?.lines() { + if line.starts_with("-volume_date uuid") { + uuid = line + .split(' ') + .last() + .ok_or_else(|| format_err!("xorriso did behave unexpextedly"))? + .replace('\'', "") + .trim() + .into(); + break; + } + } + Ok(uuid) +} + fn get_disks() -> Result>> { let unwantend_block_devs = vec![ "ram[0-9]*", -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel