Skip to content

Commit

Permalink
feat: install LTS kernel for Ubuntu when available (#5835)
Browse files Browse the repository at this point in the history
Co-authored-by: anujmaheshwari1 <[email protected]>
  • Loading branch information
anujmaheshwari1 and anujmaheshwari1 authored Feb 22, 2025
1 parent 79b026b commit c970d87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
26 changes: 19 additions & 7 deletions vhdbuilder/packer/pre-install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,29 @@ if [[ ${OS} == ${MARINER_OS_NAME} ]] && [[ "${ENABLE_CGROUPV2,,}" == "true" ]];
enableCgroupV2forAzureLinux
fi

if [[ "${UBUNTU_RELEASE}" == "22.04" && "${ENABLE_FIPS,,}" != "true" ]]; then
if [[ ${UBUNTU_RELEASE//./} -ge 2204 && "${ENABLE_FIPS,,}" != "true" ]]; then
LTS_KERNEL="linux-image-azure-lts-${UBUNTU_RELEASE}"
LTS_TOOLS="linux-tools-azure-lts-${UBUNTU_RELEASE}"
LTS_CLOUD_TOOLS="linux-cloud-tools-azure-lts-${UBUNTU_RELEASE}"
LTS_HEADERS="linux-headers-azure-lts-${UBUNTU_RELEASE}"
LTS_MODULES="linux-modules-extra-azure-lts-${UBUNTU_RELEASE}"

echo "Logging the currently running kernel: $(uname -r)"
echo "Before purging kernel, here is a list of kernels/headers installed:"; dpkg -l 'linux-*azure*'

# Purge all current kernels and dependencies
DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y $(dpkg-query -W 'linux-*azure*' | awk '$2 != "" { print $1 }' | paste -s)
echo "After purging kernel, dpkg list should be empty"; dpkg -l 'linux-*azure*'
if apt-cache show "$LTS_KERNEL" &>/dev/null; then
echo "LTS kernel is available for ${UBUNTU_RELEASE}, proceeding with purging current kernel and installing LTS kernel..."

# Purge all current kernels and dependencies
DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y $(dpkg-query -W 'linux-*azure*' | awk '$2 != "" { print $1 }' | paste -s)
echo "After purging kernel, dpkg list should be empty"; dpkg -l 'linux-*azure*'

# Install lts-22.04 kernel
DEBIAN_FRONTEND=noninteractive apt-get install -y linux-image-azure-lts-22.04 linux-cloud-tools-azure-lts-22.04 linux-headers-azure-lts-22.04 linux-modules-extra-azure-lts-22.04 linux-tools-azure-lts-22.04
echo "After installing new kernel, here is a list of kernels/headers installed"; dpkg -l 'linux-*azure*'
# Install LTS kernel
DEBIAN_FRONTEND=noninteractive apt-get install -y "$LTS_KERNEL" "$LTS_TOOLS" "$LTS_CLOUD_TOOLS" "$LTS_HEADERS" "$LTS_MODULES"
echo "After installing new kernel, here is a list of kernels/headers installed:"; dpkg -l 'linux-*azure*'
else
echo "LTS kernel for Ubuntu ${UBUNTU_RELEASE} is not available. Skipping purging and subsequent installation."
fi

update-grub
fi
Expand Down
34 changes: 33 additions & 1 deletion vhdbuilder/packer/test/linux-vhd-content-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,37 @@ testFips() {
echo "$test:Finish"
}

testLtsKernel() {
test="testLtsKernel"
echo "$test:Start"
os_version=$1
os_sku=$2
enable_fips=$3

if [[ "$os_sku" == "Ubuntu" && ${enable_fips,,} != "true" ]]; then
echo "OS is Ubuntu and FIPS is not enabled, check LTS kernel version"
# Check the Ubuntu version and set the expected kernel version
if [[ "$os_version" == "2204" ]]; then
expected_kernel="5.15"
elif [[ "$os_version" == "2404" ]]; then
expected_kernel="6.8"
else
echo "LTS kernel not installed for: $os_version"
fi

kernel=$(uname -r)
echo "Current kernel version: $kernel"
if [[ "$kernel" == *"$expected_kernel"* ]]; then
echo "Kernel version is as expected ($expected_kernel)."
else
echo "Kernel version is not as expected. Expected $expected_kernel, found $kernel."
fi
else
echo "OS is not Ubuntu OR OS is Ubuntu and FIPS is true, skip LTS kernel test"
fi

}

testCloudInit() {
test="testCloudInit"
echo "$test:Start"
Expand Down Expand Up @@ -1160,4 +1191,5 @@ testPam $OS_SKU $OS_VERSION
testUmaskSettings
testContainerImagePrefetchScript
testAKSNodeControllerBinary
testAKSNodeControllerService
testAKSNodeControllerService
testLtsKernel $OS_VERSION $OS_SKU $ENABLE_FIPS

0 comments on commit c970d87

Please sign in to comment.