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

Configure the console by default only on particular platforms #2400

Merged
merged 4 commits into from
Jun 3, 2022
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
2 changes: 1 addition & 1 deletion mantle/cmd/kola/switchkernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var (

if [[ $FROM_KERNEL == "default" && $TO_KERNEL == "rt-kernel" ]]; then
# Switch from default to RT Kernel
# https://github.com/openshift/machine-config-operator/blob/master/pkg/daemon/update.go#L711
# https://github.com/openshift/machine-config-operator/blob/e246be62e7839a086bc4494203472349c406dcae/pkg/daemon/update.go#L711
RT_KERNEL_REPO=$3
if [[ -z $(ls ${RT_KERNEL_REPO}) ]]; then
echo "No kernel-rt package available in the repo: ${RT_KERNEL_REPO}"
Expand Down
17 changes: 8 additions & 9 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,7 @@ fi

set -x
kargs="$(python3 -c 'import sys, json; args = json.load(sys.stdin)["extra-kargs"]; print(" ".join(args))' < "${image_json}")"
tty="console=tty0 console=${DEFAULT_TERMINAL},115200n8"
# On each s390x hypervisor, a tty would be automatically detected by the kernel
# and systemd, there is no need to specify one. However, we keep DEFAULT_TERMINAL
# as ttysclp0, which is helpful for building/testing with KVM+virtio (cmd-run).
# For aarch64, ttyAMA0 is used as the default console
case "$basearch" in
"aarch64"|"s390x") tty= ;;
esac
kargs="$kargs $tty ignition.platform.id=$ignition_platform_id"
kargs="$kargs ignition.platform.id=$ignition_platform_id"

qemu-img create -f ${image_format} "${path}.tmp" "${image_size}"

Expand All @@ -217,10 +209,17 @@ cat >image-dynamic.json << EOF
}
EOF
cat "${image_json}" image-dynamic.json | jq -s add > image-for-disk.json
platforms_json=
if [ -e "${configdir}/platforms.yaml" ]; then
platforms_json="${workdir}/tmp/platforms.json"
yaml2json "${configdir}/platforms.yaml" "${platforms_json}"
fi
Comment on lines +213 to +216
Copy link
Member

Choose a reason for hiding this comment

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

One thing to be aware of is the existing effort to shove image.json into the OSTree:

I'm sure the reasoning behind that move would also want to do the same for platforms.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, noted. Let's not block on that, though.

runvm "${target_drive[@]}" -- \
/usr/lib/coreos-assembler/create_disk.sh \
--config "$(pwd)"/image-for-disk.json \
--kargs "\"${kargs}\"" \
--platform "${ignition_platform_id}" \
${platforms_json:+--platforms-json "${platforms_json}"} \
bgilbert marked this conversation as resolved.
Show resolved Hide resolved
"${disk_args[@]}"
/usr/lib/coreos-assembler/finalize-artifact "${path}.tmp" "${path}"

Expand Down
2 changes: 1 addition & 1 deletion src/cosalib/qemuvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def image_meta(self):
return None

def set_platform(self):
run_verbose(['/usr/lib/coreos-assembler/gf-platformid',
run_verbose(['/usr/lib/coreos-assembler/gf-set-platform',
self.image_qemu, self.tmp_image, self.platform])

def mutate_image(self):
Expand Down
40 changes: 38 additions & 2 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Options:
--disk: disk device to use
--help: show this help
--kargs: kernel CLI args
--platform: Ignition platform ID
bgilbert marked this conversation as resolved.
Show resolved Hide resolved
--platforms-json: platforms.yaml in JSON format
--no-x86-bios-bootloader: don't install BIOS bootloader on x86_64

You probably don't want to run this script by hand. This script is
Expand All @@ -38,6 +40,8 @@ EOC

config=
disk=
platform=metal
platforms_json=
x86_bios_bootloader=1
extrakargs=""

Expand All @@ -50,6 +54,8 @@ do
--help) usage; exit;;
--kargs) extrakargs="${extrakargs} ${1}"; shift;;
--no-x86-bios-bootloader) x86_bios_bootloader=0;;
--platform) platform="${1}"; shift;;
--platforms-json) platforms_json="${1}"; shift;;
*) echo "${flag} is not understood."; usage; exit 10;;
esac;
done
Expand All @@ -62,6 +68,27 @@ udevtrig() {
export PATH=$PATH:/sbin:/usr/sbin
arch="$(uname -m)"

if [ -n "$platforms_json" ]; then
platform_grub_cmds=$(jq -r ".${arch}.${platform}.grub_commands // [] | join(\"\\\\n\")" < "${platforms_json}")
platform_kargs=$(jq -r ".${arch}.${platform}.kernel_arguments // [] | join(\" \")" < "${platforms_json}")
else
# Add legacy kargs and console settings
platform_grub_cmds='serial --speed=115200\nterminal_input serial console\nterminal_output serial console'
DEFAULT_TERMINAL=$(. $(dirname "$0")/cmdlib.sh; echo $DEFAULT_TERMINAL)
# On each s390x hypervisor, a tty would be automatically detected by the
# kernel and systemd, there is no need to specify one. However, we keep
# DEFAULT_TERMINAL as ttysclp0, which is helpful for building/testing
# with KVM+virtio (cmd-run). For aarch64, ttyAMA0 is used as the
# default console
case "$arch" in
"aarch64"|"s390x") platform_kargs= ;;
*) platform_kargs="console=tty0 console=${DEFAULT_TERMINAL},115200n8" ;;
esac
fi
if [ -n "${platform_kargs}" ]; then
extrakargs="${extrakargs} ${platform_kargs}"
fi

disk=$(realpath /dev/disk/by-id/virtio-target)

config="${config:?--config must be defined}"
Expand Down Expand Up @@ -364,7 +391,16 @@ install_grub_cfg() {
# 0700 to match the RPM permissions which I think are mainly in case someone has
# manually set a grub password
mkdir -p -m 0700 $rootfs/boot/grub2
printf "%s" "$grub_script" > $rootfs/boot/grub2/grub.cfg
printf "%s\n" "$grub_script" | \
sed -E 's@(^# CONSOLE-SETTINGS-START$)@\1'"${platform_grub_cmds:+\\n${platform_grub_cmds}}"'@' \
> $rootfs/boot/grub2/grub.cfg
if [ -n "$platforms_json" ]; then
# Copy platforms table if it's non-empty for this arch
if jq -e ".$arch" < "$platforms_json" > /dev/null; then
mkdir -p "$rootfs/boot/coreos"
jq ".$arch" < "$platforms_json" > "$rootfs/boot/coreos/platforms.json"
bgilbert marked this conversation as resolved.
Show resolved Hide resolved
fi
fi
}

# Other arch-specific bootloader changes
Expand Down Expand Up @@ -406,7 +442,7 @@ s390x)
# this is only a temporary solution until we are able to do firstboot check at bootloader
# stage on s390x, either through zipl->grub2-emu or zipl standalone.
# See https://github.com/coreos/ignition-dracut/issues/84
# A similar hack is present in https://github.com/coreos/coreos-assembler/blob/main/src/gf-platformid#L55
# There's a similar hack in gf-set-platform
echo "$(grep options $blsfile | cut -d' ' -f2-) ignition.firstboot" > $tmpfile

# ideally we want to invoke zipl with bls and zipl.conf but we might need
Expand Down
37 changes: 33 additions & 4 deletions src/gf-platformid → src/gf-set-platform
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ dn=$(dirname "$0")
# shellcheck source=src/libguestfish.sh
. "${dn}"/libguestfish.sh

# Usage: gf-platformid <input image> <output image> PLATFORMID
# Example: gf-platformid fedora-coreos.qcow2 fedora-coreos-aws.qcow2 aws
# Usage: gf-set-platform <input image> <output image> PLATFORMID
# Example: gf-set-platform fedora-coreos.qcow2 fedora-coreos-aws.qcow2 aws
#
# This will add ignition.platform.id=aws to the bootloader arguments. Intended to
# be used for Ignition. It's much faster to do this than generate a fresh image
Expand All @@ -30,7 +30,7 @@ set -x
# See also:
# https://github.com/coreos/coreos-assembler/issues/292
# https://github.com/coreos/coreos-assembler/pull/394
tmpd=$(mktemp -tdp "$(dirname "${dest}")" gf-platformid.XXXXXX)
tmpd=$(mktemp -tdp "$(dirname "${dest}")" gf-set-platform.XXXXXX)
tmp_dest=${tmpd}/box.img

/usr/lib/coreos-assembler/cp-reflink "${src}" "${tmp_dest}"
Expand All @@ -41,17 +41,46 @@ coreos_gf_run_mount ro "${tmp_dest}"
# We just mount the boot partition writable
coreos_gf remount /boot rw:true

# Look up platform-specific configuration
rewrite_grub_cmds=
extra_grub_cmds=
extra_kargs=
remove_kargs=
if [ "$(coreos_gf exists /boot/coreos/platforms.json)" = "true" ]; then
coreos_gf download /boot/coreos/platforms.json "${tmpd}"/platforms.json
rewrite_grub_cmds=1
extra_grub_cmds=$(jq -r ".${platformid}.grub_commands // [] | join(\"\\\\n\")" < "${tmpd}/platforms.json")
extra_kargs=$(jq -r ".${platformid}.kernel_arguments // [] | join(\" \")" < "${tmpd}/platforms.json")
remove_kargs=$(jq -r ".qemu.kernel_arguments // [] | join(\" \")" < "${tmpd}/platforms.json")
fi

# Inject PLATFORM label in BLS config (for subsequent config regeneration)
blscfg_path=$(coreos_gf glob-expand /boot/loader/entries/ostree-*.conf)
coreos_gf download "${blscfg_path}" "${tmpd}"/bls.conf
# Remove any platformid currently there
sed -i -e 's, ignition.platform.id=[a-zA-Z0-9]*,,g' "${tmpd}"/bls.conf
sed -i -e '/^options / s,$, ignition.platform.id='"${platformid}"',' "${tmpd}"/bls.conf
if [ -n "$remove_kargs" ]; then
# Remove existing qemu-specific kargs
sed -i -e '/^options / s@ '"${remove_kargs}"'@@' "${tmpd}"/bls.conf
fi
dustymabe marked this conversation as resolved.
Show resolved Hide resolved
if [ -n "$extra_kargs" ]; then
sed -i -e '/^options / s@$@ '"${extra_kargs}"'@' "${tmpd}"/bls.conf
fi
coreos_gf upload "${tmpd}"/bls.conf "${blscfg_path}"

if [ -n "$rewrite_grub_cmds" ]; then
# Remove qemu-specific grub.cfg commands and inject any new ones
coreos_gf download /boot/grub2/grub.cfg "${tmpd}"/grub-orig.cfg
awk '/^# CONSOLE-SETTINGS-START$/ {suspend=1; print} {if (!suspend) print} /^# CONSOLE-SETTINGS-END$/ {suspend=0; print}' "${tmpd}"/grub-orig.cfg | \
sed -E 's@(^# CONSOLE-SETTINGS-START$)@\1'"${extra_grub_cmds:+\\n${extra_grub_cmds}}"'@' \
> "${tmpd}"/grub.cfg
coreos_gf upload "${tmpd}"/grub.cfg /boot/grub2/grub.cfg
fi

if [ "$basearch" = "s390x" ] ; then
# Before we re-run zipl make sure we have the firstboot options
# A hack similar to https://github.com/coreos/coreos-assembler/blob/main/src/create_disk.sh#L381
# There's a similar hack in create_disk.sh
sed -i -e 's|^\(options .*\)|\1 ignition.firstboot|' "${tmpd}"/bls.conf
coreos_gf rename "${blscfg_path}" "${blscfg_path}.orig"
coreos_gf upload "${tmpd}"/bls.conf "${blscfg_path}"
Expand Down
7 changes: 4 additions & 3 deletions src/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ function load_video {
fi
}

serial --speed=115200
terminal_input serial console
terminal_output serial console
# Any non-default console settings will be inserted here.
# CONSOLE-SETTINGS-START
# CONSOLE-SETTINGS-END

if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=1
Expand Down