Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s390x: call zipl using exact kernel, ramdisk and cmdline #1422

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Minor changes:

Internal changes:

- zipl: Directly pass kernel, initrd and kargs instead of BLS entry

Packaging changes:

Expand Down
96 changes: 30 additions & 66 deletions src/s390x/zipl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// limitations under the License.

use crate::blockdev::Mount;
use crate::io::{visit_bls_entry, visit_bls_entry_options, Initrd, KargsEditor};
use crate::io::{visit_bls_entry, Initrd};
use crate::s390x::ZiplSecexMode;
use crate::util::cmd_output;
use crate::{runcmd, runcmd_output};
use anyhow::{anyhow, bail, Context, Result};
use lazy_static::lazy_static;
use nix::mount::MsFlags;
use regex::Regex;
use std::fs::{copy, create_dir_all, read_dir, DirEntry, File};
use std::fs::{read_dir, DirEntry, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -330,73 +330,37 @@ pub fn zipl<P: AsRef<Path>>(
)
} else {
// This branch could be also executed during installation, that's why
// we have to take care of ignition.firstboot karg and copy bls config
// files for further modification
let tempdir = Builder::new()
.prefix("coreos-installer-zipl-bls-")
.tempdir()
.context("creating temporary directory")?;
// we have to take care of ignition.firstboot karg
let firstboot_file = boot.join("ignition.firstboot");
let blsdir = if kargs.is_some() || firstboot_file.exists() {
let blsdir = tempdir.path().join("loader/entries");
create_dir_all(&blsdir).with_context(|| format!("creating {}", blsdir.display()))?;
read_dir(boot.join("loader/entries"))
.with_context(|| format!("reading {}", boot.display()))?
.filter_map(Result::ok)
.filter(|p| p.file_type().unwrap().is_file())
.for_each(|src| {
copy(src.path(), blsdir.join(src.file_name())).unwrap();
});

let mut extra = Vec::new();
if firstboot_file.exists() {
extra.push("ignition.firstboot".to_string());
let firstboot_contents = std::fs::read_to_string(&firstboot_file)
.with_context(|| format!("reading \"{}\"", firstboot_file.display()))?;
if let Some(firstboot_kargs) = extract_firstboot_kargs(&firstboot_contents)? {
extra.extend_from_slice(
&firstboot_kargs
.split_whitespace()
.map(|s| s.to_string())
.collect::<Vec<String>>(),
);
}
let (kernel, initrd, mut options) = get_info_from_bls(boot)?;
// we need a full path to kernel and initrd
jlebon marked this conversation as resolved.
Show resolved Hide resolved
let kernel = boot.join(&kernel[1..]);
let initrd = boot.join(&initrd[1..]);
Comment on lines +337 to +338
Copy link
Member

@dustymabe dustymabe Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and because we have the boot -> . symlink it doesn't matter if the ultimate path ends up being /boot/boot/ostree/foo/vmlinuz... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly, symlink does the trick


if firstboot_file.exists() {
options.push_str(" ignition.firstboot");
let firstboot_contents = std::fs::read_to_string(&firstboot_file)
.with_context(|| format!("reading \"{}\"", firstboot_file.display()))?;
if let Some(firstboot_kargs) = extract_firstboot_kargs(&firstboot_contents)? {
options = format!("{options} {firstboot_kargs}");
}
if let Some(kargs) = kargs {
extra.extend_from_slice(
&kargs
.split_whitespace()
.map(|s| s.to_string())
.collect::<Vec<String>>(),
);
}

visit_bls_entry_options(tempdir.path(), |orig_options: &str| {
KargsEditor::new()
.append_if_missing(extra.as_slice())
.maybe_apply_to(orig_options)
})
.with_context(|| format!("appending {extra:?}"))?;

blsdir
} else {
boot.join("loader/entries")
};

// create dummy config for zipl
let mut conffile = Builder::new()
.prefix("coreos-installer-zipl.")
.tempfile()
.context("creating zipl config")?;
let data = format!(
"[defaultboot]\ndefaultauto\nprompt=1\ntimeout=5\nsecure=auto\ntarget={}\n",
boot.to_str().unwrap()
);
conffile
.write_all(data.as_bytes())
.context("writing zipl config")?;
}
if let Some(kargs) = kargs {
options = format!("{options} {kargs}");
}

runcmd!("zipl", "--blsdir", blsdir, "--config", conffile.path())
runcmd!(
"zipl",
"-V",
"--target",
boot,
"--image",
kernel,
"--ramdisk",
initrd,
"--parameters",
options
)
}
}

Expand Down
Loading