|
90 | 90 | use std::fs::File; |
91 | 91 | use std::io::{BufWriter, Seek, Write}; |
92 | 92 | use std::os::unix::process::CommandExt; |
93 | | -use std::process::Command; |
| 93 | +use std::process::{Command, Stdio}; |
94 | 94 |
|
95 | 95 | use bootc_utils::CommandRunExt; |
96 | 96 | use camino::{Utf8Path, Utf8PathBuf}; |
@@ -708,6 +708,21 @@ pub(crate) async fn run_impl(opts: RunEphemeralOpts) -> Result<()> { |
708 | 708 | }; |
709 | 709 | debug!("Container image systemd version: {systemd_version:?}"); |
710 | 710 |
|
| 711 | + // Check if we need to handle cloud-init |
| 712 | + let cloudinit = { |
| 713 | + Command::new("systemctl") |
| 714 | + .args([ |
| 715 | + "--root=/run/source-image", |
| 716 | + "is-enabled", |
| 717 | + "cloud-init.target", |
| 718 | + ]) |
| 719 | + .stdout(Stdio::null()) |
| 720 | + .stderr(Stdio::null()) |
| 721 | + .status()? |
| 722 | + .success() |
| 723 | + }; |
| 724 | + tracing::debug!("Target image has cloud-init: {cloudinit}"); |
| 725 | + |
711 | 726 | // Find kernel and initramfs from the container image (not the host) |
712 | 727 | let modules_dir = Utf8Path::new("/run/source-image/usr/lib/modules"); |
713 | 728 | let mut vmlinuz_path = None; |
@@ -974,6 +989,12 @@ StandardOutput=file:/dev/virtio-ports/executestatus |
974 | 989 | if opts.common.console { |
975 | 990 | kernel_cmdline.push("console=ttyS0".to_string()); |
976 | 991 | } |
| 992 | + if cloudinit { |
| 993 | + // We don't provide any cloud-init datasource right now, |
| 994 | + // though in the future it would make sense to do so, |
| 995 | + // and switch over our SSH key injection. |
| 996 | + kernel_cmdline.push("ds=iid-datasource-none".to_string()); |
| 997 | + } |
977 | 998 |
|
978 | 999 | kernel_cmdline.extend(opts.common.kernel_args.clone()); |
979 | 1000 |
|
|
0 commit comments