From c391359ac39756f6fc5ba16105ada030976de5f2 Mon Sep 17 00:00:00 2001 From: jdoubleu Date: Fri, 1 Aug 2025 23:03:16 +0200 Subject: [PATCH] implement support for persistent mount --- src/args.rs | 3 +++ src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/args.rs b/src/args.rs index e0aad83..72c234c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -36,6 +36,9 @@ pub struct Args { /// This effectively skips the 5 second startup delay. #[clap(long, short = 'd')] pub boot: bool, + /// Mount a persistent store which may be used by OVMF to store non-volatile variables + #[clap(long, short = 'p')] + pub persistent: bool, } impl Args { diff --git a/src/main.rs b/src/main.rs index 5dbaa5e..c30b3e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,29 @@ fn main() { .additional_args .extend(args.qemu_args.iter().cloned()); + // Prepare persistent mount + if args.persistent { + let persistent_image_path = { + let mut base = std::env::home_dir().unwrap_or(PathBuf::from("/")); + base.push(".uefi-run.persistent.fat"); + base + }; + + if !persistent_image_path.exists() { + EfiImage::new(&persistent_image_path, 0x40_0000) + .expect("Failed to create persistent image"); + } + + qemu_config.drives.insert( + 0, + QemuDriveConfig { + file: persistent_image_path.to_str().unwrap().to_string(), + media: "disk".to_string(), + format: "raw".to_string(), + }, + ) + } + // Run qemu let mut qemu_process = qemu_config.run().expect("Failed to start qemu");