(source: &Path, image_path: &Path)
| 462 | } |
| 463 | |
| 464 | fn format_ext4_image_from_dir(source: &Path, image_path: &Path) -> Result<(), String> { |
| 465 | let mut last_error = None; |
| 466 | for tool in ["mke2fs", "mkfs.ext4"] { |
| 467 | for candidate in e2fs_tool_candidates(tool) { |
| 468 | let label = candidate.display().to_string(); |
| 469 | let output = Command::new(&candidate) |
| 470 | .arg("-q") |
| 471 | .arg("-F") |
| 472 | .arg("-t") |
| 473 | .arg("ext4") |
| 474 | .arg("-E") |
| 475 | .arg("root_owner=0:0") |
| 476 | .arg("-d") |
| 477 | .arg(source) |
| 478 | .arg(image_path) |
| 479 | .output(); |
| 480 | match output { |
| 481 | Ok(output) if output.status.success() => return Ok(()), |
| 482 | Ok(output) => { |
| 483 | last_error = Some(format!( |
| 484 | "{label} failed with status {}\nstdout: {}\nstderr: {}", |
| 485 | output.status, |
| 486 | String::from_utf8_lossy(&output.stdout), |
| 487 | String::from_utf8_lossy(&output.stderr) |
| 488 | )); |
| 489 | } |
| 490 | Err(err) if err.kind() == std::io::ErrorKind::NotFound => { |
| 491 | last_error = Some(format!("{label} not found")); |
| 492 | } |
| 493 | Err(err) => { |
| 494 | last_error = Some(format!("run {label}: {err}")); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | Err(format!( |
| 500 | "failed to create ext4 rootfs image from {}: {}. Install e2fsprogs (mke2fs/mkfs.ext4) and retry", |
| 501 | source.display(), |
| 502 | last_error.unwrap_or_else(|| "no ext4 formatter found".to_string()) |
| 503 | )) |
| 504 | } |
| 505 | |
| 506 | fn ensure_rootfs_image_parent_dirs(image_path: &Path, guest_path: &str) { |
| 507 | let Some(parent) = Path::new(guest_path).parent() else { |
no test coverage detected