Skip to content

Commit d45d2fd

Browse files
committed
Added --virtiofsd command line option to the libvirt run command
fix: use overlayfs for ephemeral /var to handle large images with xattrs on virtiofs Signed-off-by: Nick Downs <nickryand@gmail.com>
1 parent e3907b1 commit d45d2fd

6 files changed

Lines changed: 23 additions & 8 deletions

File tree

crates/integration-tests/src/tests/run_ephemeral.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ integration_test!(test_run_ephemeral_virtiofs_mmap);
406406
/// Test that ephemeral VMs have the expected mount layout:
407407
/// - / is read-only virtiofs
408408
/// - /etc is overlayfs with tmpfs upper (writable)
409-
/// - /var is tmpfs (not overlayfs, so podman can use overlayfs inside)
409+
/// - /var is overlayfs with tmpfs upper (writable, instant setup for large /var trees)
410410
fn test_run_ephemeral_mount_layout() -> TestResult {
411411
let sh = shell()?;
412412
let bck = get_bck_command()?;
@@ -446,16 +446,17 @@ fn test_run_ephemeral_mount_layout() -> TestResult {
446446
etc_fstype
447447
);
448448

449-
// Check /var mount - should be tmpfs, NOT overlay
449+
// Check /var mount - should be overlay (using overlayfs for instant setup,
450+
// avoiding slow/failing cp -a of large /var trees on virtiofs)
450451
let var_fstype = cmd!(
451452
sh,
452453
"{bck} ephemeral run --rm --label {label} --execute 'findmnt -n -o FSTYPE /var' {image}"
453454
)
454455
.read()?;
455456
assert_eq!(
456457
var_fstype.trim(),
457-
"tmpfs",
458-
"/var should be tmpfs (not overlay), got: {}",
458+
"overlay",
459+
"/var should be overlay, got: {}",
459460
var_fstype
460461
);
461462

crates/kit/src/cpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn create_initramfs_units_cpio() -> io::Result<Vec<u8>> {
9494
),
9595
File(
9696
"usr/lib/systemd/system/initrd-fs.target.d/bcvk-var-ephemeral.conf",
97-
b"[Unit]\nWants=bcvk-var-ephemeral.service\n",
97+
b"[Unit]\nRequires=bcvk-var-ephemeral.service\n",
9898
),
9999
File(
100100
"usr/lib/systemd/system/initrd-fs.target.d/bcvk-copy-units.conf",

crates/kit/src/libvirt/base_disks.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn find_or_create_base_disk(
1818
image_digest: &str,
1919
install_options: &InstallOptions,
2020
connect_uri: Option<&str>,
21+
virtiofsd_binary: Option<String>,
2122
) -> Result<Utf8PathBuf> {
2223
let metadata = DiskImageMetadata::from(install_options, image_digest, source_image);
2324
let cache_hash = metadata.compute_cache_hash();
@@ -67,6 +68,7 @@ pub fn find_or_create_base_disk(
6768
image_digest,
6869
install_options,
6970
connect_uri,
71+
virtiofsd_binary,
7072
)?;
7173

7274
Ok(base_disk_path)
@@ -79,6 +81,7 @@ fn create_base_disk(
7981
image_digest: &str,
8082
install_options: &InstallOptions,
8183
connect_uri: Option<&str>,
84+
virtiofsd_binary: Option<String>,
8285
) -> Result<()> {
8386
use crate::run_ephemeral::CommonVmOpts;
8487
use crate::to_disk::{Format, ToDiskAdditionalOpts, ToDiskOpts};
@@ -116,6 +119,7 @@ fn create_base_disk(
116119
memory: crate::common_opts::MemoryOpts {
117120
memory: super::LIBVIRT_DEFAULT_MEMORY.to_string(),
118121
},
122+
virtiofsd_binary,
119123
..Default::default()
120124
},
121125
..Default::default()

crates/kit/src/libvirt/base_disks_cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub fn run_create(
7777
&image_digest,
7878
&opts.install_options,
7979
connect_uri,
80+
None,
8081
)?;
8182
println!("Created base disk: {path}");
8283

crates/kit/src/libvirt/run.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ pub struct LibvirtRunOpts {
309309
#[clap(long = "ignition")]
310310
pub ignition_config: Option<Utf8PathBuf>,
311311

312+
/// Path to virtiofsd binary (overrides auto-detection for disk creation)
313+
#[clap(long = "virtiofsd", env = "VIRTIOFSD_BIN")]
314+
pub virtiofsd_binary: Option<String>,
315+
312316
/// Log virtio console (OS/journald on hvc0) to this file (created if absent)
313317
#[clap(long = "console-log")]
314318
pub console_log: Option<Utf8PathBuf>,
@@ -498,6 +502,7 @@ pub fn run(global_opts: &crate::libvirt::LibvirtOptions, mut opts: LibvirtRunOpt
498502
&image_digest,
499503
&opts.install,
500504
connect_uri,
505+
opts.virtiofsd_binary.take(),
501506
)
502507
.with_context(|| "Failed to find or create base disk")?;
503508

crates/kit/src/units/bcvk-var-ephemeral.service

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Requires=sysroot.mount
1010
Type=oneshot
1111
RemainAfterExit=yes
1212
TimeoutStartSec=60
13-
ExecStart=/usr/bin/mkdir -p /run/var-ephemeral
14-
ExecStart=/usr/bin/cp -a /sysroot/var/. /run/var-ephemeral/
15-
ExecStart=/usr/bin/mount --bind /run/var-ephemeral /sysroot/var
13+
# Use overlayfs like /etc to avoid copying large files
14+
# from virtiofs to tmpfs. The cp -a approach fails on virtiofs due to xattr issues
15+
# and is prohibitively slow for large /var trees.
16+
# Bind-mount /sysroot/var to a separate location first (same technique as /etc overlay).
17+
ExecStart=/usr/bin/mkdir -p /run/var-lower /run/var-upper /run/var-work
18+
ExecStart=/usr/bin/mount --bind /sysroot/var /run/var-lower
19+
ExecStart=/usr/bin/mount -t overlay overlay -o lowerdir=/run/var-lower,upperdir=/run/var-upper,workdir=/run/var-work,index=off,metacopy=off /sysroot/var

0 commit comments

Comments
 (0)