Skip to content

Commit

Permalink
s390x: add support for IBM Z DASD disks
Browse files Browse the repository at this point in the history
Support formatting, creating partitions, and installing onto s390x
DASD disks.

Co-authored-by: Benjamin Gilbert <bgilbert@redhat.com>
  • Loading branch information
nikita-dubrovskii and bgilbert committed Jul 10, 2020
1 parent b3f24ed commit 85cc684
Show file tree
Hide file tree
Showing 11 changed files with 628 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ rust:
- beta
- nightly

arch:
- amd64
- s390x

matrix:
allow_failures:
- rust: nightly
# VM apparently has broken network access
- rust: 1.41.0
arch: s390x

env:
global:
Expand Down
104 changes: 104 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ path = "src/main.rs"
[profile.release]
lto = true

[target.'cfg(target_arch = "s390x")'.dependencies]
gptman = { version = "^0.6", default-features = false }

[dependencies]
bincode = "^1.3"
byte-unit = "^4.0"
Expand Down
19 changes: 13 additions & 6 deletions scripts/coreos-installer-service
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ PERSIST_KERNEL_NET_PARAMS=("ipv6.disable" "net.ifnames" "net.naming-scheme")
# List from https://www.mankier.com/7/dracut.cmdline#Description-Network
PERSIST_DRACUT_NET_PARAMS=("ip" "ifname" "rd.route" "bootdev" "BOOTIF" "rd.bootif" "nameserver" "rd.peerdns" "biosdevname" "vlan" "bond" "team" "bridge" "rd.net.timeout.carrier" "coreos.no_persist_ip")

# IBM S390X params to persist
PERSIST_S390X_PARAMS=("rd.dasd" "rd.zfcp" "rd.znet" "zfcp.allow_lun_scan" "cio_ignore")

args=("install")

cmdline=( $(</proc/cmdline) )
Expand Down Expand Up @@ -61,19 +64,24 @@ if [ -n "${ignition_url}" -a "${ignition_url}" != "skip" ]; then
args+=("--ignition-url" "${ignition_url}" "--insecure-ignition")
fi

# First-boot kernel arguments. Filter out any args that aren't in our
# list of networking arguments to forward and store them in $firstboot_args
# Forward whitelisted kernel arguments to the installed system. We have
# separate sets of whitelists for first-boot kargs and persistent kargs.
# Only pass --firstboot-kargs if additional networking options have been
# specified, since the default in coreos-assembler specifies
# `rd.neednet=1 ip=dhcp` when no options are persisted.
firstboot_args=""
for item in "${cmdline[@]}"; do
for param in "${PERSIST_KERNEL_NET_PARAMS[@]}" "${PERSIST_DRACUT_NET_PARAMS[@]}"; do
if [[ $item =~ ^$param(=.*)?$ ]]; then
firstboot_args+="${item} "
fi
done
for param in "${PERSIST_S390X_PARAMS[@]}"; do
if [[ $item =~ ^$param(=.*)?$ ]]; then
args+=("--append-karg" "${item}")
fi
done
done
# Only pass firstboot-kargs if additional networking options have been
# specified, since the default in ignition-dracut specifies
# `rd.neednet=1 ip=dhcp` when no options are persisted
if [ -n "${firstboot_args}" ]; then
args+=("--firstboot-args" "rd.neednet=1 ${firstboot_args}")
fi
Expand All @@ -94,4 +102,3 @@ udevadm settle
# Install
echo "coreos-installer ${args[@]}"
coreos-installer "${args[@]}"

2 changes: 1 addition & 1 deletion src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ mod ioctl {
ioctl_read!(blkgetsize64, 0x12, 114, libc::size_t);
}

fn udev_settle() -> Result<()> {
pub fn udev_settle() -> Result<()> {
// "udevadm settle" silently no-ops if the udev socket is missing, and
// then lsblk can't find partition labels. Catch this early.
if !Path::new("/run/udev/control").exists() {
Expand Down
25 changes: 24 additions & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use crate::cmdline::*;
use crate::download::*;
use crate::errors::*;
use crate::io::*;
#[cfg(target_arch = "s390x")]
use crate::s390x;
use crate::source::*;

/// Integrity verification hash for an Ignition config.
Expand Down Expand Up @@ -99,6 +101,13 @@ pub fn install(config: &InstallConfig) -> Result<()> {
}
}

#[cfg(target_arch = "s390x")]
{
if is_dasd(config)? {
s390x::prepare_dasd(&config)?;
}
}

// open output; ensure it's a block device and we have exclusive access
let mut dest = OpenOptions::new()
.write(true)
Expand Down Expand Up @@ -179,11 +188,17 @@ fn write_disk(
let sector_size = get_sector_size(dest)?;

// copy the image
#[allow(clippy::match_bool, clippy::match_single_binding)]
let image_copy = match is_dasd(config)? {
#[cfg(target_arch = "s390x")]
true => s390x::image_copy_s390x,
_ => image_copy_default,
};
write_image(
source,
dest,
Path::new(&config.device),
image_copy_default,
image_copy,
true,
Some(sector_size),
)?;
Expand All @@ -196,6 +211,7 @@ fn write_disk(
|| config.delete_kargs.is_some()
|| config.platform.is_some()
|| config.network_config.is_some()
|| cfg!(target_arch = "s390x")
{
let mount =
Disk::new(&config.device).mount_partition_by_label("boot", mount::MsFlags::empty())?;
Expand Down Expand Up @@ -225,6 +241,8 @@ fn write_disk(
if let Some(network_config) = config.network_config.as_ref() {
copy_network_config(mount.mountpoint(), network_config)?;
}
#[cfg(target_arch = "s390x")]
s390x::install_bootloader(mount.mountpoint(), &config.device)?;
}

Ok(())
Expand Down Expand Up @@ -463,6 +481,11 @@ fn clear_partition_table(dest: &mut File, table: &mut dyn PartTable) -> Result<(
Ok(())
}

fn is_dasd(config: &InstallConfig) -> Result<bool> {
let (target, _) = resolve_link(&config.device)?;
Ok(target.to_string_lossy().starts_with("/dev/dasd"))
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ mod install;
mod io;
mod iso;
mod osmet;
#[cfg(target_arch = "s390x")]
mod s390x;
mod source;
mod verify;

Expand Down
11 changes: 11 additions & 0 deletions src/s390x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# CoreOS installation on IBM Z

IBM s390x machines usually have DASD (Direct Access Storage Device) disks.

To use DASD as a Linux hard disk we have to perform several steps:

1. Low-level format it using `dasdfmt` tool
2. Create partitions on it using `fdasd` tool
3. Copy each partition from CoreOS image to corresponding partition on DASD
4. Install boot loader using `zipl` tool
5. Mark DASD as next boot device using `chreipl` tool
Loading

0 comments on commit 85cc684

Please sign in to comment.