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

feat: install LTS kernel for Ubuntu when available #5835

Merged
merged 10 commits into from
Feb 22, 2025
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
Loading