Skip to content

Commit 8e44292

Browse files
authored
[202205][Arista] Fix cmdline generation during warm-reboot from 201811/201911 (#12371)
* [202012][Arista] Fix cmdline generation during warm-reboot from 201811/201911 (#11161) Issue fixed: when performing a warm-reboot or fast-reboot from 201811 or 201911 to 202012 the kernel command line contains duplicate information. This issue is related to a change that was made to make 202012 boot0 file more futureproof. A cold reboot brings everything back into a clean slate though not always desirable. Changes done: Added some logic to properly detect the end of the Aboot cmdline when cmdline-aboot-end delimiter is not set (clean case) Added some logic to regenerate the Aboot cmdline when cmdline-aboot-end is set but duplicate parameters exists before (dirty case). Reorganized some code to handle duplicate parameter handling in the allowlist. * Fix cmdline generation due to sonic_fips
1 parent 55d4d3f commit 8e44292

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

files/Aboot/boot0.j2

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fi
6767

6868
mountpoint_for_file() {
6969
local file="$1"
70-
df "$file" | tail -1 | tr -s " " | cut -d ' ' -f6
70+
df "$file" 2> /dev/null | tail -1 | tr -s " " | cut -d ' ' -f6
7171
}
7272

7373
# extract mount point from the swi path, e.g., /mnt/flash/sonic.swi --> /mnt/flash
@@ -701,27 +701,40 @@ write_default_cmdline() {
701701
cmdline_clear
702702

703703
if $in_aboot; then
704-
# generate the default kernel parameters for the platform
704+
# Generate the default kernel parameters for the platform
705705
cat /etc/cmdline | sed "/^\(${bootconfigvars// /\|}\|crashkernel\|loglevel\|ignore_loglevel\)\(\$\|=\)/d;/^\$/d" | cmdline_append
706-
elif grep -q "$delimiter" /proc/cmdline; then
707-
# we are on a recent sonic image using delimiter. extracting the part of the
706+
elif grep -q "$delimiter" /proc/cmdline && ! grep -Eq "varlog_size=.* $delimiter" /proc/cmdline; then
707+
# We are on a recent sonic image using delimiter. extracting the part of the
708708
# cmdline coming from aboot is trivial.
709+
# The 2nd part of the condition ensures that the append bug is not present.
710+
# When it is it should go through the last case of this if/else block to
711+
# regenerate the aboot cmdline
709712
cat /proc/cmdline | sed -E "s/^(.*) $delimiter .*$/\1/" | tr ' ' '\n' | cmdline_append
710-
else
711-
# we are either on SONiC or EOS and the commandline doesn't have a delimiter
712-
# for the Aboot part. Take an educated guess at a right delimiter.
713-
# Subject to breakage if EOS or SONiC cmdline change.
713+
elif grep -q "SWI=" /proc/cmdline; then
714+
# We are in EOS and the cmdline doesn't have a delimiter for the aboot part
714715
cat /proc/cmdline | sed -E 's/^(.*) rw .*$/\1/' | tr ' ' '\n' | cmdline_append
716+
else
717+
# We are in SONiC and the cmdline doesn't have a delimiter for the aboot part.
718+
# sid= should most of the time be the last parameter provided by Aboot
719+
# Alternatively we are in SONiC and the cmdline-aboot-end delimiter was
720+
# added after image specific parameters due to a BUG which is solved by the
721+
# following statement.
722+
cat /proc/cmdline | sed -E 's/^(.* sid=[^ ]+).*$/\1/' | tr ' ' '\n' | cmdline_append
715723
fi
716724

717725
cmdline_add "$delimiter"
718726
}
719727

720728
write_cmdline() {
721729
# use extra parameters from kernel-params hook if the file exists
722-
if [ -f "$target_path/$kernel_params" ] && ! $secureboot; then
723-
info "Loading extra kernel parameters from $kernel_params"
724-
cat "$target_path/$kernel_params" | cmdline_append
730+
if [ -f "$target_path/$kernel_params" ]; then
731+
if $secureboot && $debug; then
732+
warn "Unsafe: Loading extra kernel parameters from $kernel_params"
733+
cat "$target_path/$kernel_params" | cmdline_append
734+
elif ! $secureboot; then
735+
info "Loading extra kernel parameters from $kernel_params"
736+
cat "$target_path/$kernel_params" | cmdline_append
737+
fi
725738
fi
726739

727740
# FIXME: sonic sometimes adds extra kernel parameters from user space
@@ -807,12 +820,12 @@ regular_install() {
807820

808821
mkdir -p $image_path
809822

810-
info "Generating boot-config, machine.conf and cmdline"
811-
write_regular_configs "$image_path"
812-
813823
info "Installing image under $image_path"
814824
extract_image
815825

826+
info "Generating boot-config, machine.conf and cmdline"
827+
write_regular_configs "$image_path"
828+
816829
run_hooks post-install
817830
}
818831

0 commit comments

Comments
 (0)