From 09edbef287cd5168351ff7220e45ae04a5d9194f Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:09:09 +0000 Subject: [PATCH 1/6] kdump fix, initializing network interface on boot over 2023-11 release --- build_debian.sh | 10 ++++++++++ files/scripts/network-interface-state-init.sh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 files/scripts/network-interface-state-init.sh diff --git a/build_debian.sh b/build_debian.sh index 508c5dffa8f6..4d0e4550a59f 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -439,6 +439,11 @@ sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo 'MODULES=most' >> /etc/in # Copy vmcore-sysctl.conf to add more vmcore dump flags to kernel sudo cp files/image_config/kdump/vmcore-sysctl.conf $FILESYSTEM_ROOT/etc/sysctl.d/ +# Edit the kdump-tools package script which shall enable ethernet interfaces upon the crash kernel +sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config +sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config + + #Adds a locale to a debian system in non-interactive mode sudo sed -i '/^#.* en_US.* /s/^#//' $FILESYSTEM_ROOT/etc/locale.gen && \ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT locale-gen "en_US.UTF-8" @@ -844,6 +849,11 @@ sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head +# Required for kdump_remote_ssh_dump: Initialize network interfaces and enable DHCP. +# Currently used on crash kernel boot only +sudo cp files/scripts/network-interface-state-init.sh $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh +sudo chmod +x $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh + ## Optimize filesystem size if [ "$BUILD_REDUCE_IMAGE_SIZE" = "y" ]; then sudo scripts/build-optimize-fs-size.py "$FILESYSTEM_ROOT" \ diff --git a/files/scripts/network-interface-state-init.sh b/files/scripts/network-interface-state-init.sh new file mode 100644 index 000000000000..70c540afc600 --- /dev/null +++ b/files/scripts/network-interface-state-init.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Get list of Ethernet interfaces excluding Docker interfaces +interfaces=$(ip -o link show | awk -F': ' '$2 ~ /^e/ && $2 !~ /^docker/ {print $2}') + +# Loop through each Ethernet interface +for interface in $interfaces; do + # Check if the interface is already up + if ! ip link show dev $interface | grep -q 'state UP'; then + # Bring up the interface if it's not already up + ip link set dev $interface up || { echo "Failed to bring up interface $interface"; continue; } + fi + + # Configure the interface to use DHCP + dhclient $interface || echo "Failed to configure DHCP for interface $interface" +done From 6f8be7d8b4bd077630619b51f94a1a75f4c2cbc4 Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:11:23 +0000 Subject: [PATCH 2/6] kdump fix, initializing network interface on crash kernel boot over master release --- build_debian.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build_debian.sh b/build_debian.sh index 4d0e4550a59f..aa2aa94bb35e 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -849,6 +849,7 @@ sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head + # Required for kdump_remote_ssh_dump: Initialize network interfaces and enable DHCP. # Currently used on crash kernel boot only sudo cp files/scripts/network-interface-state-init.sh $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh From 203a8dff647d22c8471514a22fdde3a68205d836 Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Thu, 2 May 2024 08:31:30 +0000 Subject: [PATCH 3/6] added sudo keyword to the sed command for tthe intended files to be changed in kdump-tools package installation --- build_debian.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index aa2aa94bb35e..85a34becc42f 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -440,8 +440,8 @@ sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo 'MODULES=most' >> /etc/in sudo cp files/image_config/kdump/vmcore-sysctl.conf $FILESYSTEM_ROOT/etc/sysctl.d/ # Edit the kdump-tools package script which shall enable ethernet interfaces upon the crash kernel -sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config -sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config +sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config +sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config #Adds a locale to a debian system in non-interactive mode From 159f0d538c419e769c0d9f9cb3b237183f1a579a Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Thu, 2 May 2024 10:49:31 +0000 Subject: [PATCH 4/6] stream edit command "sed" location changed. --- build_debian.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 85a34becc42f..c28f898b9767 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -439,11 +439,6 @@ sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "echo 'MODULES=most' >> /etc/in # Copy vmcore-sysctl.conf to add more vmcore dump flags to kernel sudo cp files/image_config/kdump/vmcore-sysctl.conf $FILESYSTEM_ROOT/etc/sysctl.d/ -# Edit the kdump-tools package script which shall enable ethernet interfaces upon the crash kernel -sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config -sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config - - #Adds a locale to a debian system in non-interactive mode sudo sed -i '/^#.* en_US.* /s/^#//' $FILESYSTEM_ROOT/etc/locale.gen && \ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT locale-gen "en_US.UTF-8" @@ -855,6 +850,12 @@ sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/r sudo cp files/scripts/network-interface-state-init.sh $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh sudo chmod +x $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh + +# Edit the kdump-tools package script which shall enable ethernet interfaces upon the crash kernel +sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config +sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config + + ## Optimize filesystem size if [ "$BUILD_REDUCE_IMAGE_SIZE" = "y" ]; then sudo scripts/build-optimize-fs-size.py "$FILESYSTEM_ROOT" \ From 8a09be01c370729ef3e870768a63b650c7571fa0 Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Fri, 3 May 2024 01:20:50 +0000 Subject: [PATCH 5/6] Moved the kdump-tools config script changes to the "sonic_debian_extension.j2" file. --- build_debian.sh | 5 ----- files/build_templates/sonic_debian_extension.j2 | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index c28f898b9767..e9baf3e0b448 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -851,11 +851,6 @@ sudo cp files/scripts/network-interface-state-init.sh $FILESYSTEM_ROOT/usr/sbin/ sudo chmod +x $FILESYSTEM_ROOT/usr/sbin/network-interface-state-init.sh -# Edit the kdump-tools package script which shall enable ethernet interfaces upon the crash kernel -sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config -sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config - - ## Optimize filesystem size if [ "$BUILD_REDUCE_IMAGE_SIZE" = "y" ]; then sudo scripts/build-optimize-fs-size.py "$FILESYSTEM_ROOT" \ diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index cd22584c942d..e905a8a8dc04 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -329,6 +329,13 @@ for kernel_release in $(ls $FILESYSTEM_ROOT/lib/modules/); do done fi + +# Edit the kdump-tools package script to call a custom one, which shall enable ethernet interfaces in the crash kernel environment +sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config +sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config + + + # Install python-swss-common package and all its dependent packages {% if python_swss_debs.strip() -%} {% for deb in python_swss_debs.strip().split(' ') -%} From 6253492e6a2f1faf467c9ab3cb165459b41f436f Mon Sep 17 00:00:00 2001 From: Bilal Ismail <110652537+bilal-ismail@users.noreply.github.com> Date: Fri, 3 May 2024 04:14:11 +0000 Subject: [PATCH 6/6] in the file_path for sed command we have now added the variable in the start of the target file. --- files/build_templates/sonic_debian_extension.j2 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index e905a8a8dc04..389807416b20 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -330,12 +330,6 @@ done fi -# Edit the kdump-tools package script to call a custom one, which shall enable ethernet interfaces in the crash kernel environment -sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" /usr/sbin/kdump-config -sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" /usr/sbin/kdump-config - - - # Install python-swss-common package and all its dependent packages {% if python_swss_debs.strip() -%} {% for deb in python_swss_debs.strip().split(' ') -%} @@ -1064,3 +1058,10 @@ sudo rm -rf $FILESYSTEM_ROOT/tmp/mask_disabled_services.py sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install python3-dbus + + +# Edit the kdump-tools package script to call a custom one, which shall enable ethernet interfaces in the crash kernel environment +sudo sed -i "/PATH=\/bin:\/usr\/bin:\/sbin:\/usr\/sbin/a NET_INTERFACE_INIT=/usr/sbin/network-interface-state-init.sh" $FILESYSTEM_ROOT/usr/sbin/kdump-config +sudo sed -i "/Network not reachable/a . $NET_INTERFACE_INIT" $FILESYSTEM_ROOT/usr/sbin/kdump-config + +