From e95ed0ed7d0d6fce1dd9bbd0ad445a9197043dcc Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Tue, 24 Sep 2019 13:12:16 +0200 Subject: [PATCH 1/9] coreos-installer: add failure check for lsblk There are cases where lsblk cannot get the output right away. Thus output= and UUID= would be empty making the loop to be useless. Put lsblk inside the loop too. --- coreos-installer | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/coreos-installer b/coreos-installer index 05be5fc3a..3434a7299 100755 --- a/coreos-installer +++ b/coreos-installer @@ -313,16 +313,14 @@ mount_boot_partition() { # The first command will find the partition with the boot label # and the eval command will set the $UUID variable that we use later. set -o pipefail - output=$(lsblk "${DEST_DEV}" --output NAME,LABEL,UUID --pairs | grep 'LABEL="boot"') - eval $(echo $output | tr ' ' '\n' | tail -n 1) - set +o pipefail - let retry=0 while true do + output=$(lsblk "${DEST_DEV}" --output NAME,LABEL,UUID --pairs | grep 'LABEL="boot"') + eval $(echo $output | tr ' ' '\n' | tail -n 1) mount "/dev/disk/by-uuid/${UUID}" /mnt/boot_partition RETCODE=$? - if [[ $RETCODE -ne 0 ]]; then + if [[ -z "$output" ]] || [[ $RETCODE -ne 0 ]]; then if [[ $retry -lt 30 ]]; then # retry and sleep to allow udevd to populate /dev/disk/by-uuid sleep 1 @@ -334,6 +332,7 @@ mount_boot_partition() { fi break; done + set +o pipefail } ############################################################ From ae92aa1d8a3b16ccb52369e064f004e94e78eb49 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Thu, 10 Oct 2019 15:12:06 +0200 Subject: [PATCH 2/9] coreos-installer: use variables instead of hardcoding Also small change in sed-ing the sha256 signature --- coreos-installer | 66 ++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/coreos-installer b/coreos-installer index 3434a7299..aeac4ab67 100755 --- a/coreos-installer +++ b/coreos-installer @@ -294,6 +294,11 @@ ZskQ/mDUv6F4w6N8Vk9R/nJTfpI36vWTcH7xxLNoNRlL2b/7ra6dB8YPsOdLy158 -----END PGP PUBLIC KEY BLOCK----- " +boot_partition="/mnt/boot_partition" +tmpfs_mountpoint="/mnt/dl" +imagefile="$tmpfs_mountpoint/imagefile" +imagefile_compressed="$tmpfs_mountpoint/imagefile.compressed" +imagefile_compressed_sig="$tmpfs_mountpoint/imagefile.compressed.sig" ############################################################ # Helper to mount the boot partition from the device @@ -318,7 +323,7 @@ mount_boot_partition() { do output=$(lsblk "${DEST_DEV}" --output NAME,LABEL,UUID --pairs | grep 'LABEL="boot"') eval $(echo $output | tr ' ' '\n' | tail -n 1) - mount "/dev/disk/by-uuid/${UUID}" /mnt/boot_partition + mount "/dev/disk/by-uuid/${UUID}" "$boot_partition" RETCODE=$? if [[ -z "$output" ]] || [[ $RETCODE -ne 0 ]]; then if [[ $retry -lt 30 ]]; then @@ -346,12 +351,12 @@ write_ignition_file() { log "Embedding provided Ignition config" # mount the boot partition - mkdir -p /mnt/boot_partition - mount_boot_partition /mnt/boot_partition - trap 'umount /mnt/boot_partition; trap - RETURN' RETURN + mkdir -p "$boot_partition" + mount_boot_partition "$boot_partition" + trap 'umount $boot_partition; trap - RETURN' RETURN - mkdir -p /mnt/boot_partition/ignition - cp /tmp/ignition.ign /mnt/boot_partition/ignition/config.ign + mkdir -p "${boot_partition}/ignition" + cp /tmp/ignition.ign "${boot_partition}/ignition/config.ign" RETCODE=$? if [[ $RETCODE -ne 0 ]]; then log "failed writing ignition config" @@ -370,11 +375,11 @@ write_networking_opts() { log "Embedding provided networking options" # check for the boot partition - mkdir -p /mnt/boot_partition - mount_boot_partition /mnt/boot_partition - trap 'umount /mnt/boot_partition; trap - RETURN' RETURN + mkdir -p "$boot_partition" + mount_boot_partition "$boot_partition" + trap 'umount $boot_partition; trap - RETURN' RETURN - echo "set ignition_network_kcmdline=\"$(cat /tmp/networking_opts)\"" >> /mnt/boot_partition/ignition.firstboot + echo "set ignition_network_kcmdline=\"$(cat /tmp/networking_opts)\"" >> "${boot_partition}/ignition.firstboot" } ######################################################### @@ -393,10 +398,10 @@ write_platform_id() { log "Overwriting ignition platform id" # check for the boot partition - mkdir -p /mnt/boot_partition - mount_boot_partition /mnt/boot_partition - trap 'umount /mnt/boot_partition; trap - RETURN' RETURN - local conf_files=$(ls /mnt/boot_partition/loader/entries/*conf) + mkdir -p "$boot_partition" + mount_boot_partition "$boot_partition" + trap 'umount $boot_partition; trap - RETURN' RETURN + local conf_files=$(ls ${boot_partition}/loader/entries/*conf) for f in $conf_files do @@ -424,11 +429,11 @@ write_additional_opts() { log "Embedding provided additional options" # check for the boot partition - mkdir -p /mnt/boot_partition - mount_boot_partition /mnt/boot_partition - trap 'umount /mnt/boot_partition; trap - RETURN' RETURN + mkdir -p "$boot_partition" + mount_boot_partition "$boot_partition" + trap 'umount $boot_partition; trap - RETURN' RETURN - echo "set ignition_extra_kcmdline=\"$(cat /tmp/additional_opts)\"" >> /mnt/boot_partition/ignition.firstboot + echo "set ignition_extra_kcmdline=\"$(cat /tmp/additional_opts)\"" >> "${boot_partition}/ignition.firstboot" } ############################################################ @@ -571,8 +576,8 @@ get_ignition_url() { ######################################################### mount_tmpfs() { log "Mounting tmpfs" - mkdir -p /mnt/dl - mount -t tmpfs -o size=${TMPFS_MBSIZE}m tmpfs /mnt/dl + mkdir -p "$tmpfs_mountpoint" + mount -t tmpfs -o size=${TMPFS_MBSIZE}m tmpfs "$tmpfs_mountpoint" } ######################################################### @@ -580,15 +585,15 @@ mount_tmpfs() { ######################################################### download_image() { log "Downloading install image" - (curl -L -s -o /mnt/dl/imagefile.compressed $IMAGE_URL; echo $? > /tmp/curl-rc) & + (curl -L -s -o ${imagefile_compressed} $IMAGE_URL; echo $? > /tmp/curl-rc) & while [ ! -f /tmp/curl-rc ]; do # If the image hasn't show up yet then wait a sec and loop - if [ ! -f /mnt/dl/imagefile.compressed ]; then + if [ ! -f ${imagefile_compressed} ]; then sleep 1 continue fi - PART_FILE_SIZE=$(ls -l /mnt/dl/imagefile.compressed | awk '{print $5}') 2>/dev/null + PART_FILE_SIZE=$(ls -l ${imagefile_compressed} | awk '{print $5}') 2>/dev/null PCT=$(dc -e"2 k $PART_FILE_SIZE $IMAGE_SIZE / 100 * p" | sed -e"s/\..*$//" 2>/dev/null) echo "${PCT}%" >&2 sleep 1 @@ -607,7 +612,7 @@ download_image() { ######################################################### download_sig() { log "Getting signature" - curl -L -s -o /mnt/dl/imagefile.compressed.sig $SIG_URL + curl -L -s -o ${imagefile_compressed_sig} $SIG_URL if [ $? -ne 0 ] then log "Unable to download sig file." @@ -624,7 +629,7 @@ validate_image() { then if [ "$SIG_TYPE" == "gpg" ] then - gpg2 --trusted-key "${GPG_LONG_ID}" --verify /mnt/dl/imagefile.compressed.sig >/dev/null 2>&1 + gpg2 --trusted-key "${GPG_LONG_ID}" --verify ${imagefile_compressed_sig} >/dev/null 2>&1 if [ $? -ne 0 ] then log "Install Image is corrupted." @@ -632,8 +637,9 @@ validate_image() { fi elif [ "$SIG_TYPE" == "sha" ] then - sed -i -e"s/$/\ \/mnt\/dl\/imagefile\.gz/" /mnt/dl/imagefile.compressed.sig - sha256sum -c /mnt/dl/imagefile.compressed.sig + # sed original file path with current path in signature file + sed -i -e "s@/.*/@$tmpfs_mountpoint/@g" ${imagefile_compressed_sig} + sha256sum -c ${imagefile_compressed_sig} if [ $? -ne 0 ] then log "Install Image is corrupted." @@ -669,10 +675,10 @@ write_image_to_disk() { set -o pipefail # Check for gzip and xz correspondingly - if [ "$(dd count=2 bs=1 if=/mnt/dl/imagefile.compressed status=none)" = "$(printf '\x1f\x8b')" ] + if [ "$(dd count=2 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\x1f\x8b')" ] then DECOMPRESSION_TOOL='zcat' - elif [ "$(dd count=5 bs=1 if=/mnt/dl/imagefile.compressed status=none)" = "$(printf '\xfd\x37\x7a\x58\x5a')" ] + elif [ "$(dd count=5 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\xfd\x37\x7a\x58\x5a')" ] then DECOMPRESSION_TOOL='xzcat' else @@ -680,7 +686,7 @@ write_image_to_disk() { exit 1 fi - $DECOMPRESSION_TOOL /mnt/dl/imagefile.compressed |\ + $DECOMPRESSION_TOOL ${imagefile_compressed} |\ dd bs=1M iflag=fullblock oflag=direct of="${DEST_DEV}" status=none RETCODE=$? if [[ $RETCODE -ne 0 ]]; then From b54b89cec504c659c8b2d777481ab113cfa1297b Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Thu, 10 Oct 2019 15:32:35 +0200 Subject: [PATCH 3/9] add support for zFCP SCSI devices on zVM and LPAR Significant changes include : - zFCP SCSI devices cannot be dd directly from qemu raw image, but dd each partition. Thus we have to extract the image, read and apply partition table accordingly, then dd partitions. Also remount tmpfs according to the size of decompressed image. Another good approach is using `sgdisk -R` which copies the whole GPT disk. - dracut-cmdline-ask.service is required on s390x, adding it at boot time (via generator) rather than hardcode in .target file affecting other arches. - write_zipl_bootloader(): chreipl to target disk at the end of the installation so in the next reboot, that disk will be in first priority. --- coreos-installer | 113 +++++++++++++++--- .../coreos-installer-generator | 5 + dracut/30coreos-installer/module-setup.sh | 9 ++ dracut/30coreos-installer/parse-coreos.sh | 18 +++ 4 files changed, 130 insertions(+), 15 deletions(-) diff --git a/coreos-installer b/coreos-installer index aeac4ab67..89b974269 100755 --- a/coreos-installer +++ b/coreos-installer @@ -294,6 +294,7 @@ ZskQ/mDUv6F4w6N8Vk9R/nJTfpI36vWTcH7xxLNoNRlL2b/7ra6dB8YPsOdLy158 -----END PGP PUBLIC KEY BLOCK----- " +arch=$(uname -m) boot_partition="/mnt/boot_partition" tmpfs_mountpoint="/mnt/dl" imagefile="$tmpfs_mountpoint/imagefile" @@ -576,8 +577,13 @@ get_ignition_url() { ######################################################### mount_tmpfs() { log "Mounting tmpfs" + if [ -n "$1" ]; then + options="remount,size=${1}m" + else + options="size=${TMPFS_MBSIZE}m" + fi mkdir -p "$tmpfs_mountpoint" - mount -t tmpfs -o size=${TMPFS_MBSIZE}m tmpfs "$tmpfs_mountpoint" + mount -t tmpfs -o "$options" tmpfs "$tmpfs_mountpoint" } ######################################################### @@ -605,6 +611,18 @@ download_image() { log "Image download failed" exit 1 fi + + # Check for gzip and xz correspondingly + if [ "$(dd count=2 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\x1f\x8b')" ] + then + DECOMPRESSION_TOOL='zcat' + elif [ "$(dd count=5 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\xfd\x37\x7a\x58\x5a')" ] + then + DECOMPRESSION_TOOL='xzcat' + else + log "Compressed file format is not supported. Supported formats: '.xz', '.gz'" + exit 1 + fi } ######################################################### @@ -667,6 +685,66 @@ log() { echo "$1" >&2 } +######################################################### +#Update bootloader if needed +######################################################### +write_zipl_bootloader() { + if [[ "$arch" == "s390x" ]]; then + log "Updating zipl" + mkdir -p /mnt/boot_partition + mount_boot_partition /mnt/boot_partition + trap 'umount /mnt/boot_partition; trap - RETURN' RETURN + + blsfile=$(ls /mnt/boot_partition/loader/entries/*.conf) + echo "$(grep options $blsfile | cut -d' ' -f2-) $(cat /tmp/s390x_opts) ignition.firstboot rd.neednet=1 ip=dhcp" > /tmp/zipl_prm + zipl --verbose -p /tmp/zipl_prm -i $(ls /mnt/boot_partition/ostree/*/*vmlinuz*) -r $(ls /mnt/boot_partition/ostree/*/*initramfs*) --target /mnt/boot_partition + if [[ $? -ne 0 ]]; then + log "failed updating bootloder" + exit 1 + fi + # this allows a reboot into new installed disk + chreipl "${DEST_DEV}" + fi +} + +######################################################### +#Handle s390x zFCP SCSI devices +######################################################### +write_image_to_zfcp_disk() { + log "Extracting disk image" + mount_tmpfs $(( $($DECOMPRESSION_TOOL ${imagefile_compressed} | wc --bytes) / 1024 / 1024 + ${TMPFS_MBSIZE} + 100 )) + $DECOMPRESSION_TOOL ${imagefile_compressed} > ${imagefile} + + # we have to store the strings to a file because any change in this + # while-do block would not take effect outside + (while IFS='' read -r line || [ -n "$line" ] + do + if [[ $line =~ "start=" ]] + then + # we save the start= and size= here, then dd the partitions later + printf "%s:%s\n" \ + "$(echo $line | cut -d: -f 2 | cut -d, -f 1 | tr -d ' ')" \ + "$(echo $line | cut -d: -f 2 | cut -d, -f 2 | tr -d ' ')" \ + >> /tmp/sfdisk_info + elif ! [[ $line =~ "label:" || $line =~ "label-id:" || $line =~ "unit:" ]] + then + continue + fi + echo $line + done <<< $(sfdisk -d ${imagefile}) + ) | sfdisk "${DEST_DEV}" + + while IFS='' read -r line || [ -n "$line" ] + do + eval ${line%%:*} ${line##*:} + dd if=${imagefile} bs=512 iflag=fullblock \ + of="${DEST_DEV}" status=progress skip=$start seek=$start count=$size + if [[ $? -ne 0 ]]; then + log "failed to write image to zFCP SCSI disk" + exit 1 + fi + done < /tmp/sfdisk_info +} ######################################################### #And Write the image to disk ######################################################### @@ -674,23 +752,25 @@ write_image_to_disk() { log "Writing disk image" set -o pipefail - # Check for gzip and xz correspondingly - if [ "$(dd count=2 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\x1f\x8b')" ] + if [[ "${arch}" =~ (aarch64|ppc64le|x86_64) ]] then - DECOMPRESSION_TOOL='zcat' - elif [ "$(dd count=5 bs=1 if=${imagefile_compressed} status=none)" = "$(printf '\xfd\x37\x7a\x58\x5a')" ] + $DECOMPRESSION_TOOL ${imagefile_compressed} |\ + dd bs=1M iflag=fullblock oflag=direct of="${DEST_DEV}" status=none + RETCODE=$? + if [[ $RETCODE -ne 0 ]]; then + log "failed to write image to disk" + exit 1 + fi + elif [[ "$arch" == "s390x" ]] then - DECOMPRESSION_TOOL='xzcat' + case $(systemd-detect-virt) in + none|zvm) # 'none' means LPAR + write_image_to_zfcp_disk + ;; + qemu) log "Use qcow images for KVM s390x installation instead"; exit 1 ;; + esac else - log "Compressed file format is not supported. Supported formats: '.xz', '.gz'" - exit 1 - fi - - $DECOMPRESSION_TOOL ${imagefile_compressed} |\ - dd bs=1M iflag=fullblock oflag=direct of="${DEST_DEV}" status=none - RETCODE=$? - if [[ $RETCODE -ne 0 ]]; then - log "failed to write image to disk" + log "Unsupported architecture" exit 1 fi set +o pipefail @@ -793,6 +873,9 @@ main() { # If ignition platform id is provided, overwrite ignition.platform.id in BLS write_platform_id + # If platform is s390x, update bootloader records + write_zipl_bootloader + log "Install complete" } diff --git a/dracut/30coreos-installer/coreos-installer-generator b/dracut/30coreos-installer/coreos-installer-generator index bce01e029..5d990e3eb 100755 --- a/dracut/30coreos-installer/coreos-installer-generator +++ b/dracut/30coreos-installer/coreos-installer-generator @@ -17,6 +17,11 @@ cmdline_arg() { echo "${value}" } +# allow adding boot parameters at boot time +if [[ $(uname -m) == "s390x" ]]; then + echo -e '\nRequires=dracut-cmdline-ask.service\nAfter=dracut-cmdline-ask.service' >> /usr/lib/systemd/system/coreos-installer.target +fi + if [[ $(cmdline_arg coreos.inst) == "yes" ]]; then ln -sf "/usr/lib/systemd/system/coreos-installer.target" \ "${UNIT_DIR}/default.target" diff --git a/dracut/30coreos-installer/module-setup.sh b/dracut/30coreos-installer/module-setup.sh index 1e5195713..e89b15910 100755 --- a/dracut/30coreos-installer/module-setup.sh +++ b/dracut/30coreos-installer/module-setup.sh @@ -35,6 +35,15 @@ install() { inst_multiple /usr/sbin/blockdev inst_multiple /usr/sbin/wipefs + if [ "$arch" = "s390x" ]; then + inst_multiple -o /usr/bin/wc + inst_multiple -o /usr/sbin/zipl + inst_multiple -o /usr/sbin/chreipl + inst_multiple -o /usr/sbin/chzdev + inst_multiple -o /usr/sbin/sfdisk + inst_multiple -o /lib/s390-tools/stage3.bin + fi + inst_simple /usr/libexec/coreos-installer inst_simple "$moddir/coreos-installer-generator" \ diff --git a/dracut/30coreos-installer/parse-coreos.sh b/dracut/30coreos-installer/parse-coreos.sh index fe126643b..7b201c75b 100755 --- a/dracut/30coreos-installer/parse-coreos.sh +++ b/dracut/30coreos-installer/parse-coreos.sh @@ -58,6 +58,24 @@ then echo "${NETWORKING_ARGS}" >> /tmp/networking_opts fi +# Preserve s390x-specific user-provided parameters for zipl +local S390X_ALL_ARGS= +declare -a DRACUT_S390X_ARGS=("rd.dasd=" "rd.zfcp=" "rd.znet=" "zfcp.allow_lun_scan=" "cio_ignore=") +for S390X_ARG in "${DRACUT_S390X_ARGS[@]}" +do + S390X_OPT=$(getarg $S390X_ARG) + if [ ! -z "$S390X_OPT" ] + then + echo "persist $S390X_ARG to $S390X_OPT" >> /tmp/debug + S390X_ALL_ARGS+=" ${S390X_ARG}${S390X_OPT}" + fi +done +if [ -n "${S390X_ALL_ARGS}" ] +then + echo "persisting s390x options: ${S390X_ALL_ARGS}" >> /tmp/debug + echo "${S390X_ALL_ARGS}" >> /tmp/s390x_opts +fi + if getargbool 0 coreos.inst.skip_media_check then echo "Asserting skip of media check" >> /tmp/debug From 6e1126526bd5469ffa9c0f2ee3e093c54d42d416 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Thu, 10 Oct 2019 17:54:17 +0200 Subject: [PATCH 4/9] add support for ECKD DASD devices on zVM and LPAR --- coreos-installer | 54 ++++++++++++++++++++++- dracut/30coreos-installer/module-setup.sh | 4 ++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/coreos-installer b/coreos-installer index 89b974269..941f97b7b 100755 --- a/coreos-installer +++ b/coreos-installer @@ -707,6 +707,51 @@ write_zipl_bootloader() { fi } +######################################################### +#Handle s390x ECKD DASD devices +######################################################### +write_image_to_dasd() { + log "Extracting disk image" + mount_tmpfs $(( $($DECOMPRESSION_TOOL ${imagefile_compressed} | wc --bytes) / 1024 / 1024 + ${TMPFS_MBSIZE} + 100 )) + $DECOMPRESSION_TOOL ${imagefile_compressed} > ${imagefile} + + # low-level format the ECKD DASD using dasdfmt, if needed + DEST_DEV_BUS=$(lszdev --by-node ${DEST_DEV} | tail -n 1 | awk '{print $2}') + if [ "$(< /sys/bus/ccw/devices/${DEST_DEV_BUS}/status)" = "unformatted" ]; then + dasdfmt --blocksize 4096 --disk_layout cdl --mode full -ypv "${DEST_DEV}" + fi + block_per_tracks=$(fdasd -p ${DEST_DEV} | grep blocks\ per\ track | awk '{print $5}') + + # the first 2 tracks of the ECKD DASD are reserved + first_track=2 + boot_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}1" | awk '{print $2,$3}')) + root_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}4" | awk '{print $2,$3}')) + boot_partition+=( $first_track $(dc -e "${boot_partition[1]} $block_per_tracks 1 - + $block_per_tracks / p") ) + root_partition+=($(( ${boot_partition[2]} + ${boot_partition[3]} )) "last") + cat > "/tmp/fdasd_conf" <<- EOF +[$first_track,$(( ${root_partition[2]} - 1 )),native] +[${root_partition[2]},${root_partition[3]},native] +EOF + + # format the ECKD DASD using fdasd program + fdasd --silent --config /tmp/fdasd_conf "${DEST_DEV}" + + # copy the content of each partition + set -- ${boot_partition[@]} ${root_partition[@]} + while [ $# -gt 0 ]; do + dd bs=4096 if="${imagefile}" iflag=fullblock of="${DEST_DEV}" \ + status=progress \ + skip="$1" \ + count="$2" \ + seek="$(( $3 * $block_per_tracks ))" + if [[ $? -ne 0 ]]; then + log "failed to write image to ECKD DASD device" + exit 1 + fi + shift 4 + done +} + ######################################################### #Handle s390x zFCP SCSI devices ######################################################### @@ -765,9 +810,14 @@ write_image_to_disk() { then case $(systemd-detect-virt) in none|zvm) # 'none' means LPAR - write_image_to_zfcp_disk + if [[ "${DEST_DEV}" =~ "dasd" ]]; then + write_image_to_dasd + else + write_image_to_zfcp_disk + fi ;; - qemu) log "Use qcow images for KVM s390x installation instead"; exit 1 ;; + kvm|qemu) log "Use qcow images for KVM s390x installation instead"; exit 1 ;; + *) log "Unsupported hypervisor"; exit 1 ;; esac else log "Unsupported architecture" diff --git a/dracut/30coreos-installer/module-setup.sh b/dracut/30coreos-installer/module-setup.sh index e89b15910..f42186dda 100755 --- a/dracut/30coreos-installer/module-setup.sh +++ b/dracut/30coreos-installer/module-setup.sh @@ -40,6 +40,10 @@ install() { inst_multiple -o /usr/sbin/zipl inst_multiple -o /usr/sbin/chreipl inst_multiple -o /usr/sbin/chzdev + inst_multiple -o /usr/sbin/lszdev + inst_multiple -o /usr/sbin/dasdfmt + inst_multiple -o /usr/sbin/fdasd + inst_multiple -o /usr/sbin/fdisk inst_multiple -o /usr/sbin/sfdisk inst_multiple -o /lib/s390-tools/stage3.bin fi From 669c8e64ce528304dbd2a4cdba9b2c7264f7ea53 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Tue, 29 Oct 2019 14:17:18 +0100 Subject: [PATCH 5/9] s390x: adapt the partition layout for both fcos and rhcos-4.2 In FCOS, root partition is always at index 4. Even with coreos-assembler commit d5299ad6d5caf3479aeeac10ce0879a48815f0a4, it's still at index 4 even though there are only 2 partitions. In RHCOS4.2, anaconda only creates 2 partitions, boot and root. Also change the rest of hard-coded mountpoints to variables, which was missed earlier in a3052c5474df4c2c6ab1a7b2327ca46ed23ba61f. --- coreos-installer | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/coreos-installer b/coreos-installer index 941f97b7b..9eb548537 100755 --- a/coreos-installer +++ b/coreos-installer @@ -691,13 +691,14 @@ log() { write_zipl_bootloader() { if [[ "$arch" == "s390x" ]]; then log "Updating zipl" - mkdir -p /mnt/boot_partition - mount_boot_partition /mnt/boot_partition - trap 'umount /mnt/boot_partition; trap - RETURN' RETURN + mkdir -p "$boot_partition" + mount_boot_partition "$boot_partition" + trap 'umount $boot_partition; trap - RETURN' RETURN - blsfile=$(ls /mnt/boot_partition/loader/entries/*.conf) + + blsfile=$(ls ${boot_partition}/loader/entries/*.conf) echo "$(grep options $blsfile | cut -d' ' -f2-) $(cat /tmp/s390x_opts) ignition.firstboot rd.neednet=1 ip=dhcp" > /tmp/zipl_prm - zipl --verbose -p /tmp/zipl_prm -i $(ls /mnt/boot_partition/ostree/*/*vmlinuz*) -r $(ls /mnt/boot_partition/ostree/*/*initramfs*) --target /mnt/boot_partition + zipl --verbose -p /tmp/zipl_prm -i $(ls ${boot_partition}/ostree/*/*vmlinuz*) -r $(ls ${boot_partition}/ostree/*/*initramfs*) --target "$boot_partition" if [[ $? -ne 0 ]]; then log "failed updating bootloder" exit 1 @@ -724,8 +725,14 @@ write_image_to_dasd() { # the first 2 tracks of the ECKD DASD are reserved first_track=2 - boot_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}1" | awk '{print $2,$3}')) - root_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}4" | awk '{print $2,$3}')) + # in RHCOS4.2 using anaconda, we have root partition at index 2 while in FCOS it's 4 + BOOTPN=1 + ROOTPN=2 + if [[ -n $(grep -i fedora /usr/lib/initrd-release) ]]; then + ROOTPN=4 + fi + boot_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}${BOOTPN}" | awk '{print $2,$3}')) + root_partition=($(fdisk -b 4096 -o DEVICE,START,SECTORS -l ${imagefile} | grep "${imagefile}${ROOTPN}" | awk '{print $2,$3}')) boot_partition+=( $first_track $(dc -e "${boot_partition[1]} $block_per_tracks 1 - + $block_per_tracks / p") ) root_partition+=($(( ${boot_partition[2]} + ${boot_partition[3]} )) "last") cat > "/tmp/fdasd_conf" <<- EOF From f8d142c53400cebbd6aa81088b390b6120e71cb2 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Tue, 29 Oct 2019 14:56:16 +0100 Subject: [PATCH 6/9] s390x: write s390x opts to BLS file, respect networking opts In https://github.com/coreos/fedora-coreos-tracker/issues/305 we decided that, we want to write s390x opts to BLS files to persist after second boot. Respect all networking opts that are provided. This aligns with what write_networking_opts() function does. --- coreos-installer | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/coreos-installer b/coreos-installer index 9eb548537..4bb2ccb52 100755 --- a/coreos-installer +++ b/coreos-installer @@ -697,7 +697,12 @@ write_zipl_bootloader() { blsfile=$(ls ${boot_partition}/loader/entries/*.conf) - echo "$(grep options $blsfile | cut -d' ' -f2-) $(cat /tmp/s390x_opts) ignition.firstboot rd.neednet=1 ip=dhcp" > /tmp/zipl_prm + # We need to propagate s390x parameter to later boots via BLS files + # More details : https://github.com/coreos/fedora-coreos-tracker/issues/305 + options="$(grep options $blsfile | cut -d' ' -f2-) $(cat /tmp/s390x_opts)" + sed -i -e "s@^options.*@options $options@g" $blsfile + # And also keep networking parameters for first boot + echo "$options $(cat /tmp/networking_opts) ignition.firstboot" > /tmp/zipl_prm zipl --verbose -p /tmp/zipl_prm -i $(ls ${boot_partition}/ostree/*/*vmlinuz*) -r $(ls ${boot_partition}/ostree/*/*initramfs*) --target "$boot_partition" if [[ $? -ne 0 ]]; then log "failed updating bootloder" From bb9bc4be959168d93df6f073e03da1d65a4ef887 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Thu, 31 Oct 2019 18:50:55 +0100 Subject: [PATCH 7/9] s390x: parse multiple instances of the same cmdline parameters Only the last instance of multiple instances of, for example, rd.znet= was parsed. Now we catch 'em all. --- dracut/30coreos-installer/parse-coreos.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dracut/30coreos-installer/parse-coreos.sh b/dracut/30coreos-installer/parse-coreos.sh index 7b201c75b..f7397b372 100755 --- a/dracut/30coreos-installer/parse-coreos.sh +++ b/dracut/30coreos-installer/parse-coreos.sh @@ -63,12 +63,13 @@ local S390X_ALL_ARGS= declare -a DRACUT_S390X_ARGS=("rd.dasd=" "rd.zfcp=" "rd.znet=" "zfcp.allow_lun_scan=" "cio_ignore=") for S390X_ARG in "${DRACUT_S390X_ARGS[@]}" do - S390X_OPT=$(getarg $S390X_ARG) - if [ ! -z "$S390X_OPT" ] - then - echo "persist $S390X_ARG to $S390X_OPT" >> /tmp/debug - S390X_ALL_ARGS+=" ${S390X_ARG}${S390X_OPT}" - fi + for S390X_OPT in $(getargs $S390X_ARG); do + if [ ! -z "$S390X_OPT" ] + then + echo "persist $S390X_ARG to $S390X_OPT" >> /tmp/debug + S390X_ALL_ARGS+=" ${S390X_ARG}${S390X_OPT}" + fi + done done if [ -n "${S390X_ALL_ARGS}" ] then From 85269b837ffd395e3ad95d636e67b5833ad916f0 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Fri, 15 Nov 2019 17:21:22 +0100 Subject: [PATCH 8/9] coreos-installer: allow install bare metal raw image on KVM At first the assumption was, using bare metal raw image to install on zFCP SCSI disks on z/VM and LPAR. For KVM, users would be expected to use qemu/openstack images to boot instead of using coreos-installer to install on disk. Basically the bare metal raw image that works on zFCP SCSI disk would be working just fine for qemu's raw disk, we just didn't let this happen due to above assumption. Now we remove this restriction. --- coreos-installer | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/coreos-installer b/coreos-installer index 4bb2ccb52..84c32272b 100755 --- a/coreos-installer +++ b/coreos-installer @@ -820,17 +820,11 @@ write_image_to_disk() { fi elif [[ "$arch" == "s390x" ]] then - case $(systemd-detect-virt) in - none|zvm) # 'none' means LPAR - if [[ "${DEST_DEV}" =~ "dasd" ]]; then - write_image_to_dasd - else - write_image_to_zfcp_disk - fi - ;; - kvm|qemu) log "Use qcow images for KVM s390x installation instead"; exit 1 ;; - *) log "Unsupported hypervisor"; exit 1 ;; - esac + if [[ "${DEST_DEV}" =~ "dasd" ]]; then + write_image_to_dasd + else + write_image_to_zfcp_disk + fi else log "Unsupported architecture" exit 1 From 868e38dae0a22dd215bbb336edbad2e870d2ac51 Mon Sep 17 00:00:00 2001 From: Tuan Hoang Date: Sat, 16 Nov 2019 15:28:30 +0100 Subject: [PATCH 9/9] coreos-installer: dd status=none --- coreos-installer | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coreos-installer b/coreos-installer index 84c32272b..bf44e77d1 100755 --- a/coreos-installer +++ b/coreos-installer @@ -752,7 +752,7 @@ EOF set -- ${boot_partition[@]} ${root_partition[@]} while [ $# -gt 0 ]; do dd bs=4096 if="${imagefile}" iflag=fullblock of="${DEST_DEV}" \ - status=progress \ + status=none \ skip="$1" \ count="$2" \ seek="$(( $3 * $block_per_tracks ))" @@ -795,7 +795,7 @@ write_image_to_zfcp_disk() { do eval ${line%%:*} ${line##*:} dd if=${imagefile} bs=512 iflag=fullblock \ - of="${DEST_DEV}" status=progress skip=$start seek=$start count=$size + of="${DEST_DEV}" status=none skip=$start seek=$start count=$size if [[ $? -ne 0 ]]; then log "failed to write image to zFCP SCSI disk" exit 1